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 make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
229 SCM loc_on_music (Input loc, SCM arg);
230 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
231 SCM make_chord_step (SCM step, Rational alter);
232 SCM make_simple_markup (SCM a);
233 bool is_duration (int t);
234 bool is_regular_identifier (SCM id);
235 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
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 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);
449 // Evaluate and ignore #xxx, as opposed to \xxx
450 parser->lexer_->eval_scm_token ($1);
452 | embedded_scm_active
454 SCM out = SCM_UNDEFINED;
455 if (Text_interface::is_markup ($1))
456 out = scm_list_1 ($1);
457 else if (Text_interface::is_markup_list ($1))
459 if (scm_is_pair (out))
461 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
462 scm_call_2 (proc, parser->self_scm (), out);
463 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
464 parser->parser_error (@1, _("bad expression type"));
468 Output_def * od = unsmob_output_def ($1);
470 if (od->c_variable ("is-paper") == SCM_BOOL_T)
471 id = ly_symbol2scm ("$defaultpaper");
472 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
473 id = ly_symbol2scm ("$defaultmidi");
474 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
475 id = ly_symbol2scm ("$defaultlayout");
477 parser->lexer_->set_identifier (id, $1);
484 $$ = parser->lexer_->eval_scm_token ($1);
494 embedded_scm_bare_arg:
499 | context_modification
501 | context_def_spec_block
507 /* The generic version may end in music, or not */
515 embedded_scm_bare_arg
521 SCM_FUNCTION function_arglist {
522 $$ = MAKE_SYNTAX ("music-function", @$,
530 $$ = MAKE_SYNTAX ("void-music", @$);
533 | music_embedded music_embedded music_list {
534 $3 = scm_reverse_x ($3, SCM_EOL);
535 if (unsmob_music ($2))
536 $3 = scm_cons ($2, $3);
537 if (unsmob_music ($1))
538 $3 = scm_cons ($1, $3);
539 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
542 parser->error_level_ = 1;
543 $$ = SCM_UNSPECIFIED;
545 | INVALID embedded_lilypond {
546 parser->error_level_ = 1;
552 lilypond_header_body:
553 /* empty */ { $$ = SCM_UNSPECIFIED; }
554 | lilypond_header_body assignment {
557 | lilypond_header_body embedded_scm {
563 HEADER '{' lilypond_header_body '}' {
564 $$ = parser->lexer_->remove_scope ();
573 | LYRICS_STRING { $$ = $1; }
577 assignment_id '=' identifier_init {
578 parser->lexer_->set_identifier ($1, $3);
579 $$ = SCM_UNSPECIFIED;
581 | assignment_id property_path '=' identifier_init {
582 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
583 parser->lexer_->set_identifier (path, $4);
584 $$ = SCM_UNSPECIFIED;
594 | context_def_spec_block
596 | post_event_nofinger
602 | context_modification
605 context_def_spec_block:
606 CONTEXT '{' context_def_spec_body '}'
617 context_mod_embedded:
620 if (unsmob_music ($1)) {
621 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
622 $1 = scm_call_2 (proc, parser->self_scm (), $1);
624 if (unsmob_context_mod ($1))
627 parser->parser_error (@1, _ ("not a context mod"));
633 context_def_spec_body:
635 $$ = Context_def::make_scm ();
636 unsmob_context_def ($$)->origin ()->set_spot (@$);
638 | CONTEXT_DEF_IDENTIFIER {
640 unsmob_context_def ($$)->origin ()->set_spot (@$);
642 | context_def_spec_body context_mod {
643 unsmob_context_def ($$)->add_context_mod ($2);
645 | context_def_spec_body context_modification {
646 Context_def *td = unsmob_context_def ($$);
647 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
648 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
649 td->add_context_mod (scm_car (m));
652 | context_def_spec_body context_mod_embedded {
653 Context_def *td = unsmob_context_def ($$);
654 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
655 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
656 td->add_context_mod (scm_car (m));
664 BOOK '{' book_body '}' {
667 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
672 * Use 'handlers' like for toplevel-* stuff?
673 * grok \layout and \midi? */
676 Book *book = new Book;
677 init_papers (parser);
678 book->origin ()->set_spot (@$);
679 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
680 book->paper_->unprotect ();
681 push_paper (parser, book->paper_);
682 book->header_ = get_header (parser);
683 $$ = book->unprotect ();
684 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
687 unsmob_book ($1)->origin ()->set_spot (@$);
688 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
690 | book_body paper_block {
691 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
692 set_paper (parser, unsmob_output_def ($2));
694 | book_body bookpart_block {
695 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
696 scm_call_2 (proc, $1, $2);
698 | book_body score_block {
699 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
700 scm_call_2 (proc, $1, $2);
702 | book_body composite_music {
703 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
704 scm_call_3 (proc, parser->self_scm (), $1, $2);
706 | book_body full_markup {
707 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
708 scm_call_2 (proc, $1, scm_list_1 ($2));
710 | book_body full_markup_list {
711 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
712 scm_call_2 (proc, $1, $2);
714 | book_body SCM_TOKEN {
715 // Evaluate and ignore #xxx, as opposed to \xxx
716 parser->lexer_->eval_scm_token ($2);
718 | book_body embedded_scm_active
720 SCM out = SCM_UNDEFINED;
721 if (Text_interface::is_markup ($2))
722 out = scm_list_1 ($2);
723 else if (Text_interface::is_markup_list ($2))
725 if (scm_is_pair (out))
727 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
728 scm_call_2 (proc, $1, out);
729 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
730 parser->parser_error (@2, _("bad expression type"));
734 parser->lexer_->add_scope (unsmob_book ($1)->header_);
737 Book *book = unsmob_book ($1);
739 book->scores_ = SCM_EOL;
740 book->bookparts_ = SCM_EOL;
745 BOOKPART '{' bookpart_body '}' {
747 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
753 Book *book = new Book;
754 book->origin ()->set_spot (@$);
755 $$ = book->unprotect ();
756 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
759 unsmob_book ($1)->origin ()->set_spot (@$);
760 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
762 | bookpart_body paper_block {
763 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
765 | bookpart_body score_block {
766 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
767 scm_call_2 (proc, $1, $2);
769 | bookpart_body composite_music {
770 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
771 scm_call_3 (proc, parser->self_scm (), $1, $2);
773 | bookpart_body full_markup {
774 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
775 scm_call_2 (proc, $1, scm_list_1 ($2));
777 | bookpart_body full_markup_list {
778 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
779 scm_call_2 (proc, $1, $2);
781 | bookpart_body SCM_TOKEN {
782 // Evaluate and ignore #xxx, as opposed to \xxx
783 parser->lexer_->eval_scm_token ($2);
785 | bookpart_body embedded_scm_active
787 SCM out = SCM_UNDEFINED;
788 if (Text_interface::is_markup ($2))
789 out = scm_list_1 ($2);
790 else if (Text_interface::is_markup_list ($2))
792 if (scm_is_pair (out))
794 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
795 scm_call_2 (proc, $1, out);
796 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
797 parser->parser_error (@2, _("bad expression type"));
801 Book *book = unsmob_book ($1);
802 if (!ly_is_module (book->header_))
803 book->header_ = ly_make_module (false);
804 parser->lexer_->add_scope (book->header_);
806 | bookpart_body error {
807 Book *book = unsmob_book ($1);
809 book->scores_ = SCM_EOL;
814 SCORE '{' score_body '}' {
821 SCM scorify = ly_lily_module_constant ("scorify-music");
822 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
824 unsmob_score ($$)->origin ()->set_spot (@$);
827 unsmob_score ($$)->origin ()->set_spot (@$);
831 Score *score = unsmob_score ($1);
832 if (!ly_is_module (score->get_header ()))
833 score->set_header (ly_make_module (false));
834 parser->lexer_->add_scope (score->get_header ());
836 | score_body output_def {
837 Output_def *od = unsmob_output_def ($2);
838 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
840 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
845 unsmob_score ($1)->add_output_def (od);
849 unsmob_score ($$)->error_found_ = true;
860 Output_def *od = unsmob_output_def ($1);
862 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
864 parser->parser_error (@1, _ ("need \\paper for paper block"));
865 $$ = get_paper (parser)->unprotect ();
872 output_def_body '}' {
875 parser->lexer_->remove_scope ();
876 parser->lexer_->pop_state ();
882 Output_def *p = get_paper (parser);
883 p->input_origin_ = @$;
884 parser->lexer_->add_scope (p->scope_);
885 $$ = p->unprotect ();
888 Output_def *p = get_midi (parser);
889 $$ = p->unprotect ();
890 parser->lexer_->add_scope (p->scope_);
893 Output_def *p = get_layout (parser);
895 parser->lexer_->add_scope (p->scope_);
896 $$ = p->unprotect ();
900 output_def_head_with_mode_switch:
902 parser->lexer_->push_initial_state ();
907 // We need this weird nonterminal because both music as well as a
908 // context definition can start with \context and the difference is
909 // only apparent after looking at the next token. If it is '{', there
910 // is still time to escape from notes mode.
912 music_or_context_def:
915 parser->lexer_->pop_state ();
919 parser->lexer_->pop_state ();
920 } '{' context_def_spec_body '}'
927 output_def_head_with_mode_switch '{' {
929 unsmob_output_def ($$)->input_origin_.set_spot (@$);
931 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
932 Output_def *o = unsmob_output_def ($3);
933 o->input_origin_.set_spot (@$);
935 parser->lexer_->remove_scope ();
936 parser->lexer_->add_scope (o->scope_);
938 | output_def_body assignment {
941 | output_def_body embedded_scm {
946 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
947 parser->lexer_->push_note_state (nn);
948 } music_or_context_def
950 if (unsmob_context_def ($3))
951 assign_context_def (unsmob_output_def ($1), $3);
954 SCM proc = parser->lexer_->lookup_identifier
955 ("output-def-music-handler");
956 scm_call_3 (proc, parser->self_scm (),
960 | output_def_body error {
966 TEMPO steno_duration '=' tempo_range {
967 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
969 | TEMPO scalar_closed steno_duration '=' tempo_range {
970 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
973 $$ = MAKE_SYNTAX ("tempo", @$, $2);
978 The representation of a list is reversed to have efficient append. */
984 | music_list music_embedded {
985 if (unsmob_music ($2))
986 $$ = scm_cons ($2, $1);
989 Music *m = MY_MAKE_MUSIC("Music", @$);
991 m->set_property ("error-found", SCM_BOOL_T);
992 $$ = scm_cons (m->self_scm (), $1);
993 m->unprotect (); /* UGH */
1000 $$ = scm_reverse_x ($2, SCM_EOL);
1005 | lyric_element_music
1012 if (unsmob_music ($1)
1013 || scm_is_eq ($1, SCM_UNSPECIFIED))
1017 @$.warning (_ ("Ignoring non-music expression"));
1018 $$ = SCM_UNSPECIFIED;
1026 $$ = make_music_from_simple (parser, @1, $1);
1027 if (!unsmob_music ($$))
1028 parser->parser_error (@1, _ ("music expected"));
1030 | composite_music %prec COMPOSITE
1035 | composite_music %prec COMPOSITE
1036 | lyric_element_music
1040 REPEAT simple_string unsigned_number music
1042 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1044 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1046 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1051 SEQUENTIAL braced_music_list {
1052 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1054 | braced_music_list {
1055 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1060 SIMULTANEOUS braced_music_list {
1061 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1063 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1064 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1070 | music_property_def
1074 context_modification:
1075 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1077 parser->lexer_->pop_state ();
1080 | WITH CONTEXT_MOD_IDENTIFIER
1084 | CONTEXT_MOD_IDENTIFIER
1088 | WITH embedded_scm_closed
1090 if (unsmob_context_mod ($2))
1093 parser->parser_error (@2, _ ("not a context mod"));
1094 $$ = Context_mod ().smobbed_copy ();
1099 optional_context_mod:
1103 | context_modification
1111 $$ = Context_mod ().smobbed_copy ();
1113 | context_mod_list context_mod {
1114 unsmob_context_mod ($1)->add_context_mod ($2);
1116 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1117 Context_mod *md = unsmob_context_mod ($2);
1119 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1121 | context_mod_list context_mod_embedded {
1122 unsmob_context_mod ($1)->add_context_mods
1123 (unsmob_context_mod ($2)->get_mods ());
1132 /* Music that can be parsed without lookahead */
1135 | complex_music_prefix closed_music
1137 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1139 | music_function_call_closed
1145 | grouped_music_list
1149 simultaneous_music { $$ = $1; }
1150 | sequential_music { $$ = $1; }
1153 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1154 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1155 and this rule returns the reversed list of arguments. */
1157 function_arglist_skip:
1158 function_arglist_common
1159 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1161 $$ = scm_cons ($1, $3);
1162 } %prec FUNCTION_ARGLIST
1163 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1165 $$ = scm_cons ($1, $3);
1166 } %prec FUNCTION_ARGLIST
1167 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1169 $$ = scm_cons ($1, $3);
1170 } %prec FUNCTION_ARGLIST
1174 function_arglist_nonbackup_common:
1175 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1176 $$ = scm_cons ($4, $3);
1178 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1179 $$ = scm_cons ($4, $3);
1181 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1183 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1185 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1187 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1189 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1191 SCM n = scm_difference ($5, SCM_UNDEFINED);
1192 if (scm_is_true (scm_call_1 ($2, n)))
1193 $$ = scm_cons (n, $3);
1195 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1196 t->set_property ("digit", $5);
1197 $$ = t->unprotect ();
1198 if (scm_is_true (scm_call_1 ($2, $$)))
1199 $$ = scm_cons ($$, $3);
1201 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1205 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1207 $$ = check_scheme_arg (parser, @4,
1208 scm_difference ($5, SCM_UNDEFINED),
1211 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1213 $$ = check_scheme_arg (parser, @4,
1214 scm_difference ($5, SCM_UNDEFINED),
1219 function_arglist_closed_nonbackup:
1220 function_arglist_nonbackup_common
1221 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1223 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1225 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1227 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1231 function_arglist_nonbackup:
1232 function_arglist_nonbackup_common
1233 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1235 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1237 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1239 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1243 function_arglist_keep:
1244 function_arglist_common
1245 | function_arglist_backup
1248 function_arglist_closed_keep:
1249 function_arglist_closed_common
1250 | function_arglist_backup
1253 function_arglist_backup:
1254 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1256 if (scm_is_true (scm_call_1 ($2, $4)))
1258 $$ = scm_cons ($4, $3);
1260 $$ = scm_cons (loc_on_music (@3, $1), $3);
1261 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1264 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1266 if (scm_is_true (scm_call_1 ($2, $4)))
1268 $$ = scm_cons ($4, $3);
1270 $$ = scm_cons (loc_on_music (@3, $1), $3);
1271 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1274 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1276 // There is no point interpreting a lyrics string as
1277 // an event, since we don't allow music possibly
1278 // followed by durations or postevent into closed
1279 // music, and we only accept closed music in optional
1280 // arguments at the moment. If this changes, more
1281 // complex schemes might become interesting here as
1282 // well: see how we do this at the mandatory argument
1284 if (scm_is_true (scm_call_1 ($2, $4)))
1285 $$ = scm_cons ($4, $3);
1287 $$ = scm_cons (loc_on_music (@3, $1), $3);
1288 MYBACKUP (LYRICS_STRING, $4, @4);
1291 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1293 if (scm_is_true (scm_call_1 ($2, $4)))
1296 MYREPARSE (@4, $2, UNSIGNED, $4);
1298 $$ = scm_cons (loc_on_music (@3, $1), $3);
1299 MYBACKUP (UNSIGNED, $4, @4);
1302 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1304 if (scm_is_true (scm_call_1 ($2, $4)))
1307 MYREPARSE (@4, $2, REAL, $4);
1309 $$ = scm_cons (loc_on_music (@3, $1), $3);
1310 MYBACKUP (REAL, $4, @4);
1313 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1315 if (scm_is_true (scm_call_1 ($2, $4)))
1317 $$ = scm_cons ($4, $3);
1319 $$ = scm_cons (loc_on_music (@3, $1), $3);
1320 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1323 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1325 if (scm_is_true (scm_call_1 ($2, $4)))
1327 $$ = scm_cons ($4, $3);
1329 $$ = scm_cons (loc_on_music (@3, $1), $3);
1330 MYBACKUP (FRACTION, $4, @4);
1333 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1335 SCM n = scm_difference ($5, SCM_UNDEFINED);
1336 if (scm_is_true (scm_call_1 ($2, n))) {
1338 MYREPARSE (@5, $2, REAL, n);
1340 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1341 t->set_property ("digit", $5);
1342 $$ = t->unprotect ();
1343 if (scm_is_true (scm_call_1 ($2, $$)))
1344 $$ = scm_cons ($$, $3);
1346 $$ = scm_cons (loc_on_music (@3, $1), $3);
1347 MYBACKUP (UNSIGNED, $5, @5);
1348 parser->lexer_->push_extra_token ('-');
1353 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1355 SCM n = scm_difference ($5, SCM_UNDEFINED);
1356 if (scm_is_true (scm_call_1 ($2, n))) {
1357 MYREPARSE (@5, $2, REAL, n);
1360 MYBACKUP (REAL, n, @5);
1363 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1365 SCM n = scm_difference ($5, SCM_UNDEFINED);
1366 if (scm_is_true (scm_call_1 ($2, n))) {
1367 $$ = scm_cons (n, $3);
1369 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1372 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1374 $$ = scm_cons ($4, $3);
1376 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1378 $$ = scm_cons ($4, $3);
1380 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1382 $$ = scm_cons ($1, $3);
1383 MYBACKUP(0, SCM_UNDEFINED, @3);
1385 | function_arglist_backup REPARSE embedded_scm_arg_closed
1387 $$ = check_scheme_arg (parser, @3,
1390 | function_arglist_backup REPARSE bare_number
1392 $$ = check_scheme_arg (parser, @3,
1398 function_arglist_common
1399 | function_arglist_nonbackup
1402 function_arglist_common:
1403 function_arglist_bare
1404 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1406 $$ = check_scheme_arg (parser, @3,
1409 | EXPECT_SCM function_arglist_closed_optional bare_number
1411 $$ = check_scheme_arg (parser, @3,
1414 | EXPECT_SCM function_arglist_closed_optional FRACTION
1416 $$ = check_scheme_arg (parser, @3,
1419 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1421 $$ = check_scheme_arg (parser, @3,
1424 | function_arglist_common_minus
1425 | function_arglist_common_lyric
1428 function_arglist_common_lyric:
1429 EXPECT_SCM function_arglist_optional lyric_element
1431 // We check how the predicate thinks about a lyrics
1432 // event or about a markup. If it accepts neither, we
1433 // backup the original token. Otherwise we commit to
1434 // taking the token. Depending on what the predicate
1435 // is willing to accept, we interpret as a string, as
1436 // a lyric event, or ambiguously (meaning that if
1437 // something looking like a duration or post event
1438 // follows, we take the event, otherwise the string).
1439 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1440 parser->default_duration_.smobbed_copy ());
1441 if (scm_is_true (scm_call_1 ($1, $3)))
1442 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1445 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1447 $$ = scm_cons ($3, $2);
1449 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1452 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1454 // This is going to flag a syntax error, we
1455 // know the predicate to be false.
1456 check_scheme_arg (parser, @3,
1460 | function_arglist_common_lyric REPARSE lyric_element_arg
1462 // This should never be false
1463 $$ = check_scheme_arg (parser, @3,
1468 function_arglist_common_minus:
1469 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1471 SCM n = scm_difference ($4, SCM_UNDEFINED);
1472 if (scm_is_true (scm_call_1 ($1, n))) {
1474 MYREPARSE (@4, $1, REAL, n);
1476 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1477 t->set_property ("digit", $4);
1478 $$ = t->unprotect ();
1479 if (scm_is_true (scm_call_1 ($1, $$)))
1480 $$ = scm_cons ($$, $2);
1482 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1486 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1489 SCM n = scm_difference ($4, SCM_UNDEFINED);
1490 MYREPARSE (@4, $1, REAL, n);
1492 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1494 SCM n = scm_difference ($4, SCM_UNDEFINED);
1495 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1497 | function_arglist_common_minus REPARSE bare_number
1499 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1503 function_arglist_closed:
1504 function_arglist_closed_common
1505 | function_arglist_closed_nonbackup
1508 function_arglist_closed_common:
1509 function_arglist_bare
1510 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1512 $$ = check_scheme_arg (parser, @3,
1515 | EXPECT_SCM function_arglist_closed_optional bare_number
1517 $$ = check_scheme_arg (parser, @3,
1520 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1522 SCM n = scm_difference ($4, SCM_UNDEFINED);
1523 if (scm_is_true (scm_call_1 ($1, n))) {
1524 $$ = scm_cons (n, $2);
1526 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1527 t->set_property ("digit", $4);
1528 $$ = t->unprotect ();
1529 if (scm_is_true (scm_call_1 ($1, $$)))
1530 $$ = scm_cons ($$, $2);
1532 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1536 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1538 $$ = check_scheme_arg (parser, @3,
1539 scm_difference ($4, SCM_UNDEFINED),
1542 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1544 $$ = check_scheme_arg (parser, @3,
1545 scm_difference ($4, SCM_UNDEFINED),
1548 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1550 $$ = check_scheme_arg (parser, @3,
1553 | EXPECT_SCM function_arglist_closed_optional FRACTION
1555 $$ = check_scheme_arg (parser, @3,
1558 | EXPECT_SCM function_arglist_optional lyric_element
1560 $$ = check_scheme_arg (parser, @3,
1565 function_arglist_optional:
1566 function_arglist_keep %prec FUNCTION_ARGLIST
1567 | function_arglist_backup BACKUP
1568 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1570 $$ = scm_cons ($1, $3);
1572 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1574 $$ = scm_cons ($1, $3);
1578 function_arglist_closed_optional:
1579 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1580 | function_arglist_backup BACKUP
1581 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1583 $$ = scm_cons ($1, $3);
1585 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1587 $$ = scm_cons ($1, $3);
1591 embedded_scm_closed:
1593 | scm_function_call_closed
1596 embedded_scm_arg_closed:
1597 embedded_scm_bare_arg
1598 | scm_function_call_closed
1602 scm_function_call_closed:
1603 SCM_FUNCTION function_arglist_closed {
1604 $$ = MAKE_SYNTAX ("music-function", @$,
1606 } %prec FUNCTION_ARGLIST
1609 function_arglist_bare:
1610 EXPECT_NO_MORE_ARGS {
1613 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1614 $$ = scm_cons ($3, $2);
1616 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1617 $$ = scm_cons ($3, $2);
1619 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1620 $$ = scm_cons ($1, $3);
1622 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1623 $$ = scm_cons ($1, $3);
1625 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1626 $$ = scm_cons ($1, $3);
1630 music_function_call:
1631 MUSIC_FUNCTION function_arglist {
1632 $$ = MAKE_SYNTAX ("music-function", @$,
1639 /**/ { $$ = SCM_EOL; }
1640 | '=' simple_string {
1647 | repeated_music { $$ = $1; }
1648 | re_rhythmed_music { $$ = $1; }
1649 | complex_music_prefix music
1651 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1655 complex_music_prefix:
1656 CONTEXT simple_string optional_id optional_context_mod {
1657 Context_mod *ctxmod = unsmob_context_mod ($4);
1660 mods = ctxmod->get_mods ();
1661 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1663 | NEWCONTEXT simple_string optional_id optional_context_mod {
1664 Context_mod *ctxmod = unsmob_context_mod ($4);
1667 mods = ctxmod->get_mods ();
1668 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1673 mode_changing_head grouped_music_list {
1674 if ($1 == ly_symbol2scm ("chords"))
1676 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1682 parser->lexer_->pop_state ();
1684 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1685 Context_mod *ctxmod = unsmob_context_mod ($2);
1688 mods = ctxmod->get_mods ();
1689 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1690 if ($1 == ly_symbol2scm ("ChordNames"))
1692 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1694 parser->lexer_->pop_state ();
1700 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1701 parser->lexer_->push_note_state (nn);
1703 $$ = ly_symbol2scm ("notes");
1707 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1708 parser->lexer_->push_note_state (nn);
1710 $$ = ly_symbol2scm ("drums");
1713 parser->lexer_->push_figuredbass_state ();
1715 $$ = ly_symbol2scm ("figures");
1718 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1719 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1720 nn = parser->lexer_->lookup_identifier ("pitchnames");
1721 parser->lexer_->push_chord_state (nn);
1722 $$ = ly_symbol2scm ("chords");
1726 { parser->lexer_->push_lyric_state ();
1727 $$ = ly_symbol2scm ("lyrics");
1731 mode_changing_head_with_context:
1733 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1734 parser->lexer_->push_note_state (nn);
1736 $$ = ly_symbol2scm ("DrumStaff");
1739 parser->lexer_->push_figuredbass_state ();
1741 $$ = ly_symbol2scm ("FiguredBass");
1744 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1745 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1746 nn = parser->lexer_->lookup_identifier ("pitchnames");
1747 parser->lexer_->push_chord_state (nn);
1748 $$ = ly_symbol2scm ("ChordNames");
1751 { parser->lexer_->push_lyric_state ();
1752 $$ = ly_symbol2scm ("Lyrics");
1757 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1760 /* Can also use music at the expensive of two S/Rs similar to
1761 \repeat \alternative */
1762 parser->lexer_->pop_state ();
1764 $$ = scm_cons ($3, SCM_EOL);
1766 | new_lyrics ADDLYRICS {
1767 parser->lexer_->push_lyric_state ();
1769 parser->lexer_->pop_state ();
1770 $$ = scm_cons ($4, $1);
1775 composite_music new_lyrics {
1776 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1778 | LYRICSTO simple_string {
1779 parser->lexer_->push_lyric_state ();
1781 parser->lexer_->pop_state ();
1782 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1787 CHANGE STRING '=' STRING {
1788 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1793 property_path_revved:
1794 embedded_scm_closed {
1795 $$ = scm_cons ($1, SCM_EOL);
1797 | property_path_revved embedded_scm_closed {
1798 $$ = scm_cons ($2, $1);
1803 property_path_revved {
1804 $$ = scm_reverse_x ($1, SCM_EOL);
1810 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1811 scm_string_to_symbol ($1), $3);
1813 | UNSET simple_string {
1814 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1815 scm_string_to_symbol ($2));
1817 | OVERRIDE simple_string property_path '=' scalar {
1818 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1819 scm_string_to_symbol ($2), $5),
1822 | REVERT simple_string embedded_scm {
1823 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1824 scm_string_to_symbol ($2), $3);
1829 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1830 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1832 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1833 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1834 | DENIES { $$ = ly_symbol2scm ("denies"); }
1836 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1837 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1838 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1839 | NAME { $$ = ly_symbol2scm ("context-name"); }
1843 property_operation { $$ = $1; }
1844 | context_def_mod STRING {
1845 $$ = scm_list_2 ($1, $2);
1847 | context_def_mod embedded_scm
1849 if (!scm_is_string ($2)
1850 && ly_symbol2scm ("consists") != $1
1851 && ly_symbol2scm ("remove") != $1)
1854 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
1858 $$ = scm_list_2 ($1, $2);
1865 if (!is_regular_identifier ($1))
1867 @$.error (_("Grob name should be alphanumeric"));
1870 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1871 scm_string_to_symbol ($1));
1873 | simple_string '.' simple_string {
1874 $$ = scm_list_2 (scm_string_to_symbol ($1),
1875 scm_string_to_symbol ($3));
1879 simple_music_property_def:
1880 OVERRIDE context_prop_spec property_path '=' scalar {
1881 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1882 ly_symbol2scm ("OverrideProperty"),
1887 | REVERT context_prop_spec embedded_scm {
1888 $$ = scm_list_4 (scm_car ($2),
1889 ly_symbol2scm ("RevertProperty"),
1893 | SET context_prop_spec '=' scalar {
1894 $$ = scm_list_4 (scm_car ($2),
1895 ly_symbol2scm ("PropertySet"),
1899 | UNSET context_prop_spec {
1900 $$ = scm_list_3 (scm_car ($2),
1901 ly_symbol2scm ("PropertyUnset"),
1907 simple_music_property_def {
1908 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
1917 | string '+' string {
1918 if (!scm_is_string ($1)) {
1919 parser->parser_error (@1, (_ ("simple string expected")));
1920 $1 = scm_string (SCM_EOL);
1922 if (!scm_is_string ($3)) {
1923 parser->parser_error (@3, (_ ("simple string expected")));
1924 $3 = scm_string (SCM_EOL);
1926 $$ = scm_string_append (scm_list_2 ($1, $3));
1930 simple_string: STRING {
1938 if (scm_is_string ($1)) {
1941 parser->parser_error (@1, (_ ("simple string expected")));
1942 $$ = scm_string (SCM_EOL);
1955 embedded_scm_arg_closed
1963 simple_element post_events {
1964 // Let the rhythmic music iterator sort this mess out.
1965 if (scm_is_pair ($2)) {
1966 $$ = make_music_from_simple (parser, @1, $1);
1967 if (unsmob_music ($$))
1968 unsmob_music ($$)->set_property ("articulations",
1969 scm_reverse_x ($2, SCM_EOL));
1971 parser->parser_error (@1, _("music expected"));
1974 | simple_chord_elements post_events {
1975 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1978 /* why is this giving wrong start location? -ns
1980 i.set_location (@1, @2);
1981 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1983 | CHORD_REPETITION optional_notemode_duration post_events {
1985 i.set_location (@1, @3);
1986 $$ = MAKE_SYNTAX ("repetition-chord", i,
1987 $2, scm_reverse_x ($3, SCM_EOL));
1989 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1991 i.set_location (@1, @3);
1992 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1993 scm_reverse_x ($3, SCM_EOL));
1996 | note_chord_element
2001 chord_body optional_notemode_duration post_events
2003 Music *m = unsmob_music ($1);
2004 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2005 SCM es = m->get_property ("elements");
2006 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2008 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2009 unsmob_music (scm_car (s))->set_property ("duration", dur);
2010 es = ly_append2 (es, postevs);
2012 m-> set_property ("elements", es);
2014 $$ = m->self_scm ();
2019 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2021 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2025 chord_body_elements:
2026 /* empty */ { $$ = SCM_EOL; }
2027 | chord_body_elements chord_body_element {
2028 if (!SCM_UNBNDP ($2))
2029 $$ = scm_cons ($2, $1);
2034 pitch exclamations questions octave_check post_events
2036 bool q = to_boolean ($3);
2037 bool ex = to_boolean ($2);
2041 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2042 n->set_property ("pitch", $1);
2044 n->set_property ("cautionary", SCM_BOOL_T);
2046 n->set_property ("force-accidental", SCM_BOOL_T);
2048 if (scm_is_pair (post)) {
2049 SCM arts = scm_reverse_x (post, SCM_EOL);
2050 n->set_property ("articulations", arts);
2052 if (scm_is_number (check))
2054 int q = scm_to_int (check);
2055 n->set_property ("absolute-octave", scm_from_int (q-1));
2058 $$ = n->unprotect ();
2060 | DRUM_PITCH post_events {
2061 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2062 n->set_property ("drum-type", $1);
2064 if (scm_is_pair ($2)) {
2065 SCM arts = scm_reverse_x ($2, SCM_EOL);
2066 n->set_property ("articulations", arts);
2068 $$ = n->unprotect ();
2070 | music_function_chord_body
2072 Music *m = unsmob_music ($1);
2074 while (m && m->is_mus_type ("music-wrapper-music")) {
2075 $$ = m->get_property ("element");
2076 m = unsmob_music ($$);
2079 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2080 parser->parser_error (@$, _ ("not a rhythmic event"));
2086 music_function_chord_body:
2091 // Event functions may only take closed arglists, otherwise it would
2092 // not be clear whether a following postevent should be associated
2093 // with the last argument of the event function or with the expression
2094 // for which the function call acts itself as event.
2096 music_function_call_closed:
2097 MUSIC_FUNCTION function_arglist_closed {
2098 $$ = MAKE_SYNTAX ("music-function", @$,
2103 event_function_event:
2104 EVENT_FUNCTION function_arglist_closed {
2105 $$ = MAKE_SYNTAX ("music-function", @$,
2115 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2116 m->set_property ("span-direction", scm_from_int (START));
2117 $$ = m->unprotect();
2120 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2121 m->set_property ("span-direction", scm_from_int (STOP));
2122 $$ = m->unprotect ();
2125 $$ = MAKE_SYNTAX ("voice-separator", @$);
2128 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2130 Music *m = unsmob_music (pipe);
2135 $$ = m->unprotect ();
2138 $$ = MAKE_SYNTAX ("bar-check", @$);
2145 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2157 | post_events post_event {
2158 unsmob_music ($2)->set_spot (@2);
2159 $$ = scm_cons ($2, $$);
2163 post_event_nofinger:
2164 direction_less_event {
2167 | script_dir music_function_call_closed {
2169 if (!SCM_UNBNDP ($1))
2171 unsmob_music ($$)->set_property ("direction", $1);
2175 if (!parser->lexer_->is_lyric_state ())
2176 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2177 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2180 if (!parser->lexer_->is_lyric_state ())
2181 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2182 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2184 | script_dir direction_reqd_event {
2185 if (!SCM_UNBNDP ($1))
2187 Music *m = unsmob_music ($2);
2188 m->set_property ("direction", $1);
2192 | script_dir direction_less_event {
2193 if (!SCM_UNBNDP ($1))
2195 Music *m = unsmob_music ($2);
2196 m->set_property ("direction", $1);
2203 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2208 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2219 string_number_event:
2221 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2222 s->set_property ("string-number", $1);
2223 $$ = s->unprotect ();
2227 direction_less_char:
2229 $$ = ly_symbol2scm ("bracketOpenSymbol");
2232 $$ = ly_symbol2scm ("bracketCloseSymbol");
2235 $$ = ly_symbol2scm ("tildeSymbol");
2238 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2241 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2244 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2247 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2250 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2253 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2256 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2260 direction_less_event:
2261 direction_less_char {
2262 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2264 if (unsmob_music (predefd))
2266 m = unsmob_music (predefd)->clone ();
2271 m = MY_MAKE_MUSIC ("Music", @$);
2273 $$ = m->unprotect ();
2275 | string_number_event
2276 | EVENT_IDENTIFIER {
2280 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2281 a->set_property ("tremolo-type", $1);
2282 $$ = a->unprotect ();
2284 | event_function_event
2287 direction_reqd_event:
2291 | script_abbreviation {
2292 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2293 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2294 if (scm_is_string (s))
2295 a->set_property ("articulation-type", s);
2296 else parser->parser_error (@1, _ ("expecting string as script definition"));
2297 $$ = a->unprotect ();
2302 /**/ { $$ = SCM_EOL; }
2303 | '=' quotes { $$ = $2; }
2317 $$ = scm_from_int (1);
2320 $$ = scm_oneplus ($1);
2326 $$ = scm_from_int (-1);
2329 $$ = scm_oneminus ($1);
2334 NOTENAME_PITCH quotes {
2335 if (!scm_is_eq (SCM_INUM0, $2))
2337 Pitch p = *unsmob_pitch ($1);
2338 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2339 $$ = p.smobbed_copy ();
2349 TONICNAME_PITCH quotes {
2350 if (!scm_is_eq (SCM_INUM0, $2))
2352 Pitch p = *unsmob_pitch ($1);
2353 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2354 $$ = p.smobbed_copy ();
2364 pitch_also_in_chords:
2371 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2372 t->set_property ("text", $1);
2373 $$ = t->unprotect ();
2376 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2377 t->set_property ("text",
2378 make_simple_markup ($1));
2379 $$ = t->unprotect ();
2382 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2383 t->set_property ("text",
2384 make_simple_markup ($1));
2385 $$ = t->unprotect ();
2389 Music *m = unsmob_music ($1);
2390 if (m && m->is_mus_type ("post-event"))
2392 else if (Text_interface::is_markup ($1)) {
2393 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2394 t->set_property ("text", $1);
2395 $$ = t->unprotect ();
2397 parser->parser_error (@1, _ ("not an articulation"));
2403 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2404 t->set_property ("digit", $1);
2405 $$ = t->unprotect ();
2409 script_abbreviation:
2411 $$ = scm_from_locale_string ("Hat");
2414 $$ = scm_from_locale_string ("Plus");
2417 $$ = scm_from_locale_string ("Dash");
2420 $$ = scm_from_locale_string ("Bar");
2423 $$ = scm_from_locale_string ("Larger");
2426 $$ = scm_from_locale_string ("Dot");
2429 $$ = scm_from_locale_string ("Underscore");
2434 '_' { $$ = scm_from_int (DOWN); }
2435 | '^' { $$ = scm_from_int (UP); }
2436 | '-' { $$ = SCM_UNDEFINED; }
2440 multiplied_duration {
2445 maybe_notemode_duration:
2449 | multiplied_duration {
2451 parser->default_duration_ = *unsmob_duration ($$);
2456 optional_notemode_duration:
2457 maybe_notemode_duration
2459 if (SCM_UNBNDP ($$))
2460 $$ = parser->default_duration_.smobbed_copy ();
2467 int n = scm_to_int ($1);
2468 if (!is_duration (n))
2469 parser->parser_error (@1, _f ("not a duration: %d", n));
2473 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2475 | DURATION_IDENTIFIER dots {
2476 Duration *d = unsmob_duration ($1);
2477 Duration k (d->duration_log (),
2478 d->dot_count () + scm_to_int ($2));
2479 k = k.compressed (d->factor ());
2480 scm_remember_upto_here_1 ($1);
2481 $$ = k.smobbed_copy ();
2485 multiplied_duration:
2489 | multiplied_duration '*' UNSIGNED {
2490 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2492 | multiplied_duration '*' FRACTION {
2493 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2495 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2504 $$ = scm_oneplus ($1);
2513 int n = scm_to_int ($2);
2514 if (!is_duration (n))
2515 parser->parser_error (@2, _f ("not a duration: %d", n));
2521 UNSIGNED { $$ = $1; }
2522 | STRING { $$ = $1; }
2523 | full_markup { $$ = $1; }
2526 // as an integer, it needs to be non-negative, and otherwise
2527 // it needs to be suitable as a markup.
2528 if (scm_is_integer ($1)
2529 ? scm_is_true (scm_negative_p ($1))
2530 : !Text_interface::is_markup ($1))
2532 parser->parser_error (@1, _ ("bass number expected"));
2538 figured_bass_alteration:
2539 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2540 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2541 | '!' { $$ = scm_from_int (0); }
2546 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2547 $$ = bfr->unprotect ();
2550 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2551 $$ = bfr->self_scm ();
2553 if (scm_is_number ($1))
2554 bfr->set_property ("figure", $1);
2555 else if (Text_interface::is_markup ($1))
2556 bfr->set_property ("text", $1);
2562 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2564 | bass_figure figured_bass_alteration {
2565 Music *m = unsmob_music ($1);
2566 if (scm_to_double ($2)) {
2567 SCM salter = m->get_property ("alteration");
2568 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2569 m->set_property ("alteration",
2570 scm_sum (alter, $2));
2572 m->set_property ("alteration", scm_from_int (0));
2575 | bass_figure figured_bass_modification {
2576 Music *m = unsmob_music ($1);
2577 if ($2 == ly_symbol2scm ("plus"))
2579 m->set_property ("augmented", SCM_BOOL_T);
2581 else if ($2 == ly_symbol2scm ("slash"))
2583 m->set_property ("diminished", SCM_BOOL_T);
2585 else if ($2 == ly_symbol2scm ("exclamation"))
2587 m->set_property ("no-continuation", SCM_BOOL_T);
2589 else if ($2 == ly_symbol2scm ("backslash"))
2591 m->set_property ("augmented-slash", SCM_BOOL_T);
2597 figured_bass_modification:
2599 $$ = ly_symbol2scm ("plus");
2602 $$ = ly_symbol2scm ("exclamation");
2605 $$ = ly_symbol2scm ("slash");
2608 $$ = ly_symbol2scm ("backslash");
2618 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2626 | figure_list br_bass_figure {
2627 $$ = scm_cons ($2, $1);
2632 FIGURE_OPEN figure_list FIGURE_CLOSE {
2633 $$ = scm_reverse_x ($2, SCM_EOL);
2639 /**/ { $$ = SCM_BOOL_F; }
2640 | REST { $$ = SCM_BOOL_T; }
2644 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2645 if (!parser->lexer_->is_note_state ())
2646 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2647 if (!SCM_UNBNDP ($2)
2649 || scm_is_number ($4)
2651 || scm_is_true ($6))
2654 if (scm_is_true ($6))
2655 n = MY_MAKE_MUSIC ("RestEvent", @$);
2657 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2659 n->set_property ("pitch", $1);
2660 if (SCM_UNBNDP ($5))
2661 n->set_property ("duration",
2662 parser->default_duration_.smobbed_copy ());
2664 n->set_property ("duration", $5);
2666 if (scm_is_number ($4))
2668 int q = scm_to_int ($4);
2669 n->set_property ("absolute-octave", scm_from_int (q-1));
2672 if (to_boolean ($3))
2673 n->set_property ("cautionary", SCM_BOOL_T);
2674 if (to_boolean ($2) || to_boolean ($3))
2675 n->set_property ("force-accidental", SCM_BOOL_T);
2677 $$ = n->unprotect ();
2680 | DRUM_PITCH optional_notemode_duration {
2681 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2682 n->set_property ("duration", $2);
2683 n->set_property ("drum-type", $1);
2685 $$ = n->unprotect ();
2687 | RESTNAME optional_notemode_duration {
2689 if (ly_scm2string ($1) == "s") {
2691 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2694 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2697 ev->set_property ("duration", $2);
2698 $$ = ev->unprotect ();
2702 simple_chord_elements:
2704 if (!parser->lexer_->is_chord_state ())
2705 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2708 | figure_spec optional_notemode_duration {
2709 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2711 unsmob_music (scm_car (s))->set_property ("duration", $2);
2728 | lyric_element multiplied_duration post_events {
2729 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2730 if (scm_is_pair ($3))
2731 unsmob_music ($$)->set_property
2732 ("articulations", scm_reverse_x ($3, SCM_EOL));
2734 | lyric_element post_event post_events {
2735 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2736 parser->default_duration_.smobbed_copy ());
2737 unsmob_music ($$)->set_property
2738 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2740 | LYRIC_ELEMENT optional_notemode_duration post_events {
2741 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2742 if (scm_is_pair ($3))
2743 unsmob_music ($$)->set_property
2744 ("articulations", scm_reverse_x ($3, SCM_EOL));
2749 lyric_element_music:
2750 lyric_element optional_notemode_duration post_events {
2751 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2752 if (scm_is_pair ($3))
2753 unsmob_music ($$)->set_property
2754 ("articulations", scm_reverse_x ($3, SCM_EOL));
2759 steno_tonic_pitch optional_notemode_duration {
2760 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2762 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2763 SCM its = scm_reverse_x ($4, SCM_EOL);
2764 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2772 | chord_items chord_item {
2773 $$ = scm_cons ($2, $$);
2779 $$ = ly_symbol2scm ("chord-colon");
2782 $$ = ly_symbol2scm ("chord-caret");
2784 | CHORD_SLASH steno_tonic_pitch {
2785 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2787 | CHORD_BASS steno_tonic_pitch {
2788 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2797 $$ = scm_reverse_x ($1, SCM_EOL);
2805 step_number { $$ = scm_cons ($1, SCM_EOL); }
2806 | step_numbers '.' step_number {
2807 $$ = scm_cons ($3, $$);
2813 $$ = make_chord_step ($1, 0);
2816 $$ = make_chord_step ($1, SHARP_ALTERATION);
2818 | UNSIGNED CHORD_MINUS {
2819 $$ = make_chord_step ($1, FLAT_ALTERATION);
2827 | UNSIGNED '~' UNSIGNED {
2828 $$ = scm_cons ($1, $3);
2835 TODO: should deprecate in favor of Scheme?
2839 number_expression '+' number_term {
2840 $$ = scm_sum ($1, $3);
2842 | number_expression '-' number_term {
2843 $$ = scm_difference ($1, $3);
2852 | number_factor '*' number_factor {
2853 $$ = scm_product ($1, $3);
2855 | number_factor '/' number_factor {
2856 $$ = scm_divide ($1, $3);
2861 '-' number_factor { /* %prec UNARY_MINUS */
2862 $$ = scm_difference ($2, SCM_UNDEFINED);
2870 | UNSIGNED NUMBER_IDENTIFIER {
2871 $$ = scm_product ($1, $2);
2873 | REAL NUMBER_IDENTIFIER {
2874 $$ = scm_product ($1, $2);
2890 { $$ = SCM_UNDEFINED; }
2893 if (SCM_UNBNDP ($1))
2901 { $$ = SCM_UNDEFINED; }
2904 if (SCM_UNBNDP ($1))
2912 This should be done more dynamically if possible.
2917 { parser->lexer_->push_markup_state (); }
2920 parser->lexer_->pop_state ();
2926 { parser->lexer_->push_markup_state (); }
2929 parser->lexer_->pop_state ();
2935 { parser->lexer_->push_markup_state (); }
2938 parser->lexer_->pop_state ();
2944 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2946 | markup_head_1_list simple_markup {
2947 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2957 if (Text_interface::is_markup ($1))
2958 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
2959 else if (Text_interface::is_markup_list ($1))
2960 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
2962 parser->parser_error (@1, _ ("not a markup"));
2963 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
2970 markup_composed_list {
2973 | markup_braced_list {
2976 | markup_command_list {
2977 $$ = scm_list_1 ($1);
2979 | markup_scm MARKUPLIST_IDENTIFIER
2985 markup_composed_list:
2986 markup_head_1_list markup_braced_list {
2987 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2993 '{' markup_braced_list_body '}' {
2994 $$ = scm_reverse_x ($2, SCM_EOL);
2998 markup_braced_list_body:
2999 /* empty */ { $$ = SCM_EOL; }
3000 | markup_braced_list_body markup {
3001 $$ = scm_cons ($2, $1);
3003 | markup_braced_list_body markup_list {
3004 $$ = scm_reverse_x ($2, $1);
3008 markup_command_list:
3009 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3010 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3014 markup_command_basic_arguments:
3015 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3016 $$ = scm_cons ($3, $2);
3018 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3019 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3021 | EXPECT_NO_MORE_ARGS {
3026 markup_command_list_arguments:
3027 markup_command_basic_arguments { $$ = $1; }
3028 | EXPECT_MARKUP markup_command_list_arguments markup {
3029 $$ = scm_cons ($3, $2);
3034 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3035 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3040 markup_head_1_item {
3041 $$ = scm_list_1 ($1);
3043 | markup_head_1_list markup_head_1_item {
3044 $$ = scm_cons ($2, $1);
3050 $$ = make_simple_markup ($1);
3053 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3054 parser->lexer_->push_note_state (nn);
3055 } '{' score_body '}' {
3056 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3057 parser->lexer_->pop_state ();
3059 | MARKUP_FUNCTION markup_command_basic_arguments {
3060 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3062 | markup_scm MARKUP_IDENTIFIER
3069 markup_head_1_list simple_markup {
3070 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3071 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3081 Lily_parser::set_yydebug (bool x)
3087 Lily_parser::do_yyparse ()
3089 SCM retval = SCM_UNDEFINED;
3090 yyparse (this, &retval);
3100 It is a little strange to have this function in this file, but
3101 otherwise, we have to import music classes into the lexer.
3105 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3107 if (unsmob_book (sid)) {
3108 Book *book = unsmob_book (sid)->clone ();
3109 *destination = book->self_scm ();
3112 return BOOK_IDENTIFIER;
3113 } else if (scm_is_number (sid)) {
3115 return NUMBER_IDENTIFIER;
3116 } else if (unsmob_context_def (sid)) {
3117 Context_def *def= unsmob_context_def (sid)->clone ();
3119 *destination = def->self_scm ();
3122 return CONTEXT_DEF_IDENTIFIER;
3123 } else if (unsmob_context_mod (sid)) {
3124 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3126 return CONTEXT_MOD_IDENTIFIER;
3127 } else if (unsmob_score (sid)) {
3128 Score *score = new Score (*unsmob_score (sid));
3129 *destination = score->self_scm ();
3131 score->unprotect ();
3132 return SCORE_IDENTIFIER;
3133 } else if (Music *mus = unsmob_music (sid)) {
3134 mus = mus->clone ();
3135 *destination = mus->self_scm ();
3136 unsmob_music (*destination)->
3137 set_property ("origin", make_input (last_input_));
3139 bool is_event = mus->is_mus_type ("post-event");
3141 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3142 } else if (unsmob_pitch (sid)) {
3143 *destination = unsmob_pitch (sid)->smobbed_copy ();
3144 return PITCH_IDENTIFIER;
3145 } else if (unsmob_duration (sid)) {
3146 *destination = unsmob_duration (sid)->smobbed_copy ();
3147 return DURATION_IDENTIFIER;
3148 } else if (unsmob_output_def (sid)) {
3149 Output_def *p = unsmob_output_def (sid);
3152 *destination = p->self_scm ();
3154 return OUTPUT_DEF_IDENTIFIER;
3161 get_next_unique_context_id ()
3163 return scm_from_locale_string ("$uniqueContextId");
3168 get_next_unique_lyrics_context_id ()
3170 static int new_context_count;
3172 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3173 return scm_from_locale_string (s);
3176 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3177 SCM arg, SCM args, SCM pred)
3179 args = scm_cons (arg, args);
3180 if (scm_is_true (scm_call_1 (pred, arg)))
3182 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3183 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3184 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3188 SCM loc_on_music (Input loc, SCM arg)
3190 if (Music *m = unsmob_music (arg))
3194 return m->unprotect ();
3200 is_regular_identifier (SCM id)
3202 string str = ly_scm2string (id);
3203 char const *s = str.c_str ();
3212 v = v && isalnum (*s);
3219 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3221 if (unsmob_music (simple))
3223 if (parser->lexer_->is_note_state ()) {
3224 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3225 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3226 if (scm_is_symbol (simple))
3227 n->set_property ("drum-type", simple);
3228 else if (unsmob_pitch (simple))
3229 n->set_property ("pitch", simple);
3234 return n->unprotect ();
3235 } else if (parser->lexer_->is_lyric_state ()) {
3236 if (Text_interface::is_markup (simple))
3237 return MAKE_SYNTAX ("lyric-event", loc, simple,
3238 parser->default_duration_.smobbed_copy ());
3239 } else if (parser->lexer_->is_chord_state ()) {
3240 if (unsmob_pitch (simple))
3241 return make_chord_elements (loc, simple,
3242 parser->default_duration_.smobbed_copy (),
3249 make_music_with_input (SCM name, Input where)
3251 Music *m = make_music_by_name (name);
3252 m->set_spot (where);
3257 make_simple_markup (SCM a)
3265 return t && t == 1 << intlog2 (t);
3269 make_chord_step (SCM step_scm, Rational alter)
3271 int step = scm_to_int (step_scm);
3274 alter += FLAT_ALTERATION;
3278 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3279 return m.smobbed_copy ();
3284 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3286 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3287 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3288 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3290 unsmob_music (scm_car (s))->set_spot (loc);
3296 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3298 Lily_lexer *lex = parser->lexer_;
3302 lex->prepare_for_next_token ();
3303 return lex->yylex ();