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 SCM try_string_variants (SCM pred, SCM str);
236 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
240 /* The third option is an alias that will be used to display the
241 syntax error. Bison CVS now correctly handles backslash escapes.
243 FIXME: Bison needs to translate some of these, eg, STRING.
247 /* Keyword tokens with plain escaped name. */
248 %token END_OF_FILE 0 "end of input"
249 %token ACCEPTS "\\accepts"
250 %token ADDLYRICS "\\addlyrics"
251 %token ALIAS "\\alias"
252 %token ALTERNATIVE "\\alternative"
254 %token BOOKPART "\\bookpart"
255 %token CHANGE "\\change"
256 %token CHORDMODE "\\chordmode"
257 %token CHORDS "\\chords"
258 %token CONSISTS "\\consists"
259 %token CONTEXT "\\context"
260 %token DEFAULT "\\default"
261 %token DEFAULTCHILD "\\defaultchild"
262 %token DENIES "\\denies"
263 %token DESCRIPTION "\\description"
264 %token DRUMMODE "\\drummode"
265 %token DRUMS "\\drums"
266 %token FIGUREMODE "\\figuremode"
267 %token FIGURES "\\figures"
268 %token HEADER "\\header"
269 %token INVALID "\\version-error"
270 %token LAYOUT "\\layout"
271 %token LYRICMODE "\\lyricmode"
272 %token LYRICS "\\lyrics"
273 %token LYRICSTO "\\lyricsto"
274 %token MARKUP "\\markup"
275 %token MARKUPLIST "\\markuplist"
278 %token NOTEMODE "\\notemode"
279 %token OVERRIDE "\\override"
280 %token PAPER "\\paper"
281 %token REMOVE "\\remove"
282 %token REPEAT "\\repeat"
284 %token REVERT "\\revert"
285 %token SCORE "\\score"
286 %token SEQUENTIAL "\\sequential"
288 %token SIMULTANEOUS "\\simultaneous"
289 %token TEMPO "\\tempo"
291 %token UNSET "\\unset"
294 /* Keyword token exceptions. */
295 %token NEWCONTEXT "\\new"
298 /* Other string tokens. */
300 %token CHORD_BASS "/+"
301 %token CHORD_CARET "^"
302 %token CHORD_COLON ":"
303 %token CHORD_MINUS "-"
304 %token CHORD_SLASH "/"
305 %token ANGLE_OPEN "<"
306 %token ANGLE_CLOSE ">"
307 %token DOUBLE_ANGLE_OPEN "<<"
308 %token DOUBLE_ANGLE_CLOSE ">>"
309 %token E_BACKSLASH "\\"
310 %token E_ANGLE_CLOSE "\\>"
311 %token E_CHAR "\\C[haracter]"
313 %token E_EXCLAMATION "\\!"
314 %token E_BRACKET_OPEN "\\["
316 %token E_BRACKET_CLOSE "\\]"
317 %token E_ANGLE_OPEN "\\<"
323 If we give names, Bison complains.
325 %token FIGURE_CLOSE /* "\\>" */
326 %token FIGURE_OPEN /* "\\<" */
327 %token FIGURE_SPACE "_"
330 %token CHORDMODIFIERS
332 %token MULTI_MEASURE_REST
338 /* Artificial tokens, for more generic function syntax */
339 %token EXPECT_MARKUP "markup?"
340 %token EXPECT_PITCH "ly:pitch?"
341 %token EXPECT_DURATION "ly:duration?"
342 %token EXPECT_SCM "scheme?"
343 %token BACKUP "(backed-up?)"
344 %token REPARSE "(reparsed?)"
345 %token EXPECT_MARKUP_LIST "markup-list?"
346 %token EXPECT_OPTIONAL "optional?"
347 /* After the last argument. */
348 %token EXPECT_NO_MORE_ARGS;
350 /* An artificial token for parsing embedded Lilypond */
351 %token EMBEDDED_LILY "#{"
353 %token BOOK_IDENTIFIER
354 %token CHORDMODIFIER_PITCH
355 %token CHORD_MODIFIER
356 %token CHORD_REPETITION
357 %token CONTEXT_DEF_IDENTIFIER
358 %token CONTEXT_MOD_IDENTIFIER
360 %token PITCH_IDENTIFIER
361 %token DURATION_IDENTIFIER
362 %token EVENT_IDENTIFIER
363 %token EVENT_FUNCTION
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
380 %token SCM_IDENTIFIER
382 %token SCORE_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);
451 // Evaluate and ignore #xxx, as opposed to \xxx
452 parser->lexer_->eval_scm_token ($1);
454 | embedded_scm_active
456 SCM out = SCM_UNDEFINED;
457 if (Text_interface::is_markup ($1))
458 out = scm_list_1 ($1);
459 else if (Text_interface::is_markup_list ($1))
461 if (scm_is_pair (out))
463 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
464 scm_call_2 (proc, parser->self_scm (), out);
465 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
466 parser->parser_error (@1, _("bad expression type"));
470 Output_def * od = unsmob_output_def ($1);
472 if (od->c_variable ("is-paper") == SCM_BOOL_T)
473 id = ly_symbol2scm ("$defaultpaper");
474 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
475 id = ly_symbol2scm ("$defaultmidi");
476 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
477 id = ly_symbol2scm ("$defaultlayout");
479 parser->lexer_->set_identifier (id, $1);
486 $$ = parser->lexer_->eval_scm_token ($1);
496 embedded_scm_bare_arg:
500 $$ = parser->lexer_->eval_scm_token ($1);
504 | context_modification
506 | context_def_spec_block
512 /* The generic version may end in music, or not */
520 embedded_scm_bare_arg
526 SCM_FUNCTION function_arglist {
527 $$ = MAKE_SYNTAX ("music-function", @$,
535 $$ = MAKE_SYNTAX ("void-music", @$);
538 | music_embedded music_embedded music_list {
539 $3 = scm_reverse_x ($3, SCM_EOL);
540 if (unsmob_music ($2))
541 $3 = scm_cons ($2, $3);
542 if (unsmob_music ($1))
543 $3 = scm_cons ($1, $3);
544 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
547 parser->error_level_ = 1;
548 $$ = SCM_UNSPECIFIED;
550 | INVALID embedded_lilypond {
551 parser->error_level_ = 1;
557 lilypond_header_body:
558 /* empty */ { $$ = SCM_UNSPECIFIED; }
559 | lilypond_header_body assignment {
562 | lilypond_header_body embedded_scm {
568 HEADER '{' lilypond_header_body '}' {
569 $$ = parser->lexer_->remove_scope ();
578 | LYRICS_STRING { $$ = $1; }
582 assignment_id '=' identifier_init {
583 parser->lexer_->set_identifier ($1, $3);
584 $$ = SCM_UNSPECIFIED;
586 | assignment_id property_path '=' identifier_init {
587 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
588 parser->lexer_->set_identifier (path, $4);
589 $$ = SCM_UNSPECIFIED;
599 | context_def_spec_block
601 | post_event_nofinger
607 | context_modification
610 context_def_spec_block:
611 CONTEXT '{' context_def_spec_body '}'
622 context_mod_embedded:
625 if (unsmob_music ($1)) {
626 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
627 $1 = scm_call_2 (proc, parser->self_scm (), $1);
629 if (unsmob_context_mod ($1))
632 parser->parser_error (@1, _ ("not a context mod"));
638 context_def_spec_body:
640 $$ = Context_def::make_scm ();
641 unsmob_context_def ($$)->origin ()->set_spot (@$);
643 | CONTEXT_DEF_IDENTIFIER {
645 unsmob_context_def ($$)->origin ()->set_spot (@$);
647 | context_def_spec_body context_mod {
648 unsmob_context_def ($$)->add_context_mod ($2);
650 | context_def_spec_body context_modification {
651 Context_def *td = unsmob_context_def ($$);
652 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
653 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
654 td->add_context_mod (scm_car (m));
657 | context_def_spec_body context_mod_embedded {
658 Context_def *td = unsmob_context_def ($$);
659 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
660 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
661 td->add_context_mod (scm_car (m));
669 BOOK '{' book_body '}' {
672 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
677 * Use 'handlers' like for toplevel-* stuff?
678 * grok \layout and \midi? */
681 Book *book = new Book;
682 init_papers (parser);
683 book->origin ()->set_spot (@$);
684 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
685 book->paper_->unprotect ();
686 push_paper (parser, book->paper_);
687 book->header_ = get_header (parser);
688 $$ = book->unprotect ();
689 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
692 unsmob_book ($1)->origin ()->set_spot (@$);
693 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
695 | book_body paper_block {
696 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
697 set_paper (parser, unsmob_output_def ($2));
699 | book_body bookpart_block {
700 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
701 scm_call_2 (proc, $1, $2);
703 | book_body score_block {
704 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
705 scm_call_2 (proc, $1, $2);
707 | book_body composite_music {
708 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
709 scm_call_3 (proc, parser->self_scm (), $1, $2);
711 | book_body full_markup {
712 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
713 scm_call_2 (proc, $1, scm_list_1 ($2));
715 | book_body full_markup_list {
716 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
717 scm_call_2 (proc, $1, $2);
719 | book_body SCM_TOKEN {
720 // Evaluate and ignore #xxx, as opposed to \xxx
721 parser->lexer_->eval_scm_token ($2);
723 | book_body embedded_scm_active
725 SCM out = SCM_UNDEFINED;
726 if (Text_interface::is_markup ($2))
727 out = scm_list_1 ($2);
728 else if (Text_interface::is_markup_list ($2))
730 if (scm_is_pair (out))
732 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
733 scm_call_2 (proc, $1, out);
734 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
735 parser->parser_error (@2, _("bad expression type"));
739 parser->lexer_->add_scope (unsmob_book ($1)->header_);
742 Book *book = unsmob_book ($1);
744 book->scores_ = SCM_EOL;
745 book->bookparts_ = SCM_EOL;
750 BOOKPART '{' bookpart_body '}' {
752 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
758 Book *book = new Book;
759 book->origin ()->set_spot (@$);
760 $$ = book->unprotect ();
761 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
764 unsmob_book ($1)->origin ()->set_spot (@$);
765 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
767 | bookpart_body paper_block {
768 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
770 | bookpart_body score_block {
771 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
772 scm_call_2 (proc, $1, $2);
774 | bookpart_body composite_music {
775 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
776 scm_call_3 (proc, parser->self_scm (), $1, $2);
778 | bookpart_body full_markup {
779 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
780 scm_call_2 (proc, $1, scm_list_1 ($2));
782 | bookpart_body full_markup_list {
783 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
784 scm_call_2 (proc, $1, $2);
786 | bookpart_body SCM_TOKEN {
787 // Evaluate and ignore #xxx, as opposed to \xxx
788 parser->lexer_->eval_scm_token ($2);
790 | bookpart_body embedded_scm_active
792 SCM out = SCM_UNDEFINED;
793 if (Text_interface::is_markup ($2))
794 out = scm_list_1 ($2);
795 else if (Text_interface::is_markup_list ($2))
797 if (scm_is_pair (out))
799 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
800 scm_call_2 (proc, $1, out);
801 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
802 parser->parser_error (@2, _("bad expression type"));
806 Book *book = unsmob_book ($1);
807 if (!ly_is_module (book->header_))
808 book->header_ = ly_make_module (false);
809 parser->lexer_->add_scope (book->header_);
811 | bookpart_body error {
812 Book *book = unsmob_book ($1);
814 book->scores_ = SCM_EOL;
819 SCORE '{' score_body '}' {
826 SCM scorify = ly_lily_module_constant ("scorify-music");
827 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
829 unsmob_score ($$)->origin ()->set_spot (@$);
832 unsmob_score ($$)->origin ()->set_spot (@$);
836 Score *score = unsmob_score ($1);
837 if (!ly_is_module (score->get_header ()))
838 score->set_header (ly_make_module (false));
839 parser->lexer_->add_scope (score->get_header ());
841 | score_body output_def {
842 Output_def *od = unsmob_output_def ($2);
843 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
845 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
850 unsmob_score ($1)->add_output_def (od);
854 unsmob_score ($$)->error_found_ = true;
865 Output_def *od = unsmob_output_def ($1);
867 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
869 parser->parser_error (@1, _ ("need \\paper for paper block"));
870 $$ = get_paper (parser)->unprotect ();
877 output_def_body '}' {
880 parser->lexer_->remove_scope ();
881 parser->lexer_->pop_state ();
887 Output_def *p = get_paper (parser);
888 p->input_origin_ = @$;
889 parser->lexer_->add_scope (p->scope_);
890 $$ = p->unprotect ();
893 Output_def *p = get_midi (parser);
894 $$ = p->unprotect ();
895 parser->lexer_->add_scope (p->scope_);
898 Output_def *p = get_layout (parser);
900 parser->lexer_->add_scope (p->scope_);
901 $$ = p->unprotect ();
905 output_def_head_with_mode_switch:
907 parser->lexer_->push_initial_state ();
912 // We need this weird nonterminal because both music as well as a
913 // context definition can start with \context and the difference is
914 // only apparent after looking at the next token. If it is '{', there
915 // is still time to escape from notes mode.
917 music_or_context_def:
920 parser->lexer_->pop_state ();
924 parser->lexer_->pop_state ();
925 } '{' context_def_spec_body '}'
932 output_def_head_with_mode_switch '{' {
934 unsmob_output_def ($$)->input_origin_.set_spot (@$);
936 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
937 Output_def *o = unsmob_output_def ($3);
938 o->input_origin_.set_spot (@$);
940 parser->lexer_->remove_scope ();
941 parser->lexer_->add_scope (o->scope_);
943 | output_def_body assignment {
946 | output_def_body embedded_scm {
951 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
952 parser->lexer_->push_note_state (nn);
953 } music_or_context_def
955 if (unsmob_context_def ($3))
956 assign_context_def (unsmob_output_def ($1), $3);
959 SCM proc = parser->lexer_->lookup_identifier
960 ("output-def-music-handler");
961 scm_call_3 (proc, parser->self_scm (),
965 | output_def_body error {
971 TEMPO steno_duration '=' tempo_range {
972 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
974 | TEMPO scalar_closed steno_duration '=' tempo_range {
975 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
978 $$ = MAKE_SYNTAX ("tempo", @$, $2);
983 The representation of a list is reversed to have efficient append. */
989 | music_list music_embedded {
990 if (unsmob_music ($2))
991 $$ = scm_cons ($2, $1);
994 Music *m = MY_MAKE_MUSIC("Music", @$);
996 m->set_property ("error-found", SCM_BOOL_T);
997 $$ = scm_cons (m->self_scm (), $1);
998 m->unprotect (); /* UGH */
1005 $$ = scm_reverse_x ($2, SCM_EOL);
1010 | lyric_element_music
1017 if (unsmob_music ($1)
1018 || scm_is_eq ($1, SCM_UNSPECIFIED))
1022 @$.warning (_ ("Ignoring non-music expression"));
1023 $$ = SCM_UNSPECIFIED;
1031 $$ = make_music_from_simple (parser, @1, $1);
1032 if (!unsmob_music ($$))
1033 parser->parser_error (@1, _ ("music expected"));
1035 | composite_music %prec COMPOSITE
1040 | composite_music %prec COMPOSITE
1044 REPEAT simple_string unsigned_number music
1046 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1048 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1050 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1055 SEQUENTIAL braced_music_list {
1056 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1058 | braced_music_list {
1059 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1064 SIMULTANEOUS braced_music_list {
1065 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1067 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1068 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1074 | music_property_def
1078 context_modification:
1079 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1081 parser->lexer_->pop_state ();
1084 | WITH CONTEXT_MOD_IDENTIFIER
1088 | CONTEXT_MOD_IDENTIFIER
1092 | WITH embedded_scm_closed
1094 if (unsmob_context_mod ($2))
1097 parser->parser_error (@2, _ ("not a context mod"));
1098 $$ = Context_mod ().smobbed_copy ();
1103 optional_context_mod:
1107 | context_modification
1115 $$ = Context_mod ().smobbed_copy ();
1117 | context_mod_list context_mod {
1118 unsmob_context_mod ($1)->add_context_mod ($2);
1120 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1121 Context_mod *md = unsmob_context_mod ($2);
1123 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1125 | context_mod_list context_mod_embedded {
1126 unsmob_context_mod ($1)->add_context_mods
1127 (unsmob_context_mod ($2)->get_mods ());
1136 /* Music that can be parsed without lookahead */
1139 | complex_music_prefix closed_music
1141 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1143 | music_function_call_closed
1149 | grouped_music_list
1153 simultaneous_music { $$ = $1; }
1154 | sequential_music { $$ = $1; }
1157 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1158 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1159 and this rule returns the reversed list of arguments. */
1161 function_arglist_skip:
1162 function_arglist_common
1163 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1165 $$ = scm_cons ($1, $3);
1166 } %prec FUNCTION_ARGLIST
1167 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1169 $$ = scm_cons ($1, $3);
1170 } %prec FUNCTION_ARGLIST
1171 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1173 $$ = scm_cons ($1, $3);
1174 } %prec FUNCTION_ARGLIST
1178 function_arglist_nonbackup_common:
1179 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1180 $$ = scm_cons ($4, $3);
1182 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1183 $$ = scm_cons ($4, $3);
1185 | EXPECT_OPTIONAL EXPECT_SCM function_arglist FRACTION
1187 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1189 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1191 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1193 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1195 SCM n = scm_difference ($5, SCM_UNDEFINED);
1196 if (scm_is_true (scm_call_1 ($2, n)))
1197 $$ = scm_cons (n, $3);
1199 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1200 t->set_property ("digit", $5);
1201 $$ = t->unprotect ();
1202 if (scm_is_true (scm_call_1 ($2, $$)))
1203 $$ = scm_cons ($$, $3);
1205 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1209 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1211 $$ = check_scheme_arg (parser, @4,
1212 scm_difference ($5, SCM_UNDEFINED),
1215 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1217 $$ = check_scheme_arg (parser, @4,
1218 scm_difference ($5, SCM_UNDEFINED),
1223 function_arglist_closed_nonbackup:
1224 function_arglist_nonbackup_common
1225 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1227 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1229 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1231 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1233 | EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1235 SCM res = try_string_variants ($2, $4);
1236 if (SCM_UNBNDP (res))
1237 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1239 $$ = scm_cons (res, $3);
1241 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1243 SCM res = try_string_variants ($2, $4);
1244 if (SCM_UNBNDP (res))
1245 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1247 $$ = scm_cons (res, $3);
1249 | EXPECT_OPTIONAL EXPECT_SCM function_arglist LYRICS_STRING
1251 SCM res = try_string_variants ($2, $4);
1252 if (SCM_UNBNDP (res))
1253 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1255 $$ = scm_cons (res, $3);
1257 | EXPECT_OPTIONAL EXPECT_SCM function_arglist lyric_markup
1259 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1263 function_arglist_nonbackup:
1264 function_arglist_nonbackup_common
1265 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1267 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1269 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1271 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1273 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1275 SCM res = try_string_variants ($2, $4);
1276 if (SCM_UNBNDP (res))
1277 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1279 $$ = scm_cons (res, $3);
1281 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1283 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1285 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1287 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1291 function_arglist_nonbackup_reparse:
1292 EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1295 SCM res = try_string_variants ($2, $4);
1296 if (!SCM_UNBNDP (res))
1297 MYREPARSE (@4, $2, SCM_ARG, res);
1298 else if (scm_is_true
1300 ($2, make_music_from_simple
1302 MYREPARSE (@4, $2, LYRICS_STRING, $4);
1304 MYREPARSE (@4, $2, SCM_ARG, $4);
1306 | EXPECT_OPTIONAL EXPECT_SCM function_arglist LYRICS_STRING
1309 SCM res = try_string_variants ($2, $4);
1310 if (!SCM_UNBNDP (res))
1311 MYREPARSE (@4, $2, SCM_ARG, res);
1312 else if (scm_is_true
1314 ($2, make_music_from_simple
1316 MYREPARSE (@4, $2, LYRICS_STRING, $4);
1318 MYREPARSE (@4, $2, SCM_ARG, $4);
1320 | EXPECT_OPTIONAL EXPECT_SCM function_arglist lyric_markup
1323 if (scm_is_true (scm_call_1 ($2, $4)))
1324 MYREPARSE (@4, $2, SCM_ARG, $4);
1325 else if (scm_is_true
1327 ($2, make_music_from_simple
1329 MYREPARSE (@4, $2, LYRICS_STRING, $4);
1331 MYREPARSE (@4, $2, SCM_ARG, $4);
1335 function_arglist_keep:
1336 function_arglist_common
1337 | function_arglist_backup
1340 function_arglist_closed_keep:
1341 function_arglist_closed_common
1342 | function_arglist_backup
1345 function_arglist_backup:
1346 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1348 if (scm_is_true (scm_call_1 ($2, $4)))
1350 $$ = scm_cons ($4, $3);
1352 $$ = scm_cons (loc_on_music (@3, $1), $3);
1353 MYBACKUP (SCM_ARG, $4, @4);
1356 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1358 if (scm_is_true (scm_call_1 ($2, $4)))
1360 $$ = scm_cons ($4, $3);
1362 $$ = scm_cons (loc_on_music (@3, $1), $3);
1363 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1366 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_markup
1368 if (scm_is_true (scm_call_1 ($2, $4)))
1369 $$ = scm_cons ($4, $3);
1371 $$ = scm_cons (loc_on_music (@3, $1), $3);
1372 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1375 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1377 if (scm_is_true (scm_call_1 ($2, $4)))
1380 MYREPARSE (@4, $2, UNSIGNED, $4);
1382 $$ = scm_cons (loc_on_music (@3, $1), $3);
1383 MYBACKUP (UNSIGNED, $4, @4);
1386 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1388 if (scm_is_true (scm_call_1 ($2, $4)))
1391 MYREPARSE (@4, $2, REAL, $4);
1393 $$ = scm_cons (loc_on_music (@3, $1), $3);
1394 MYBACKUP (REAL, $4, @4);
1397 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1399 if (scm_is_true (scm_call_1 ($2, $4)))
1401 $$ = scm_cons ($4, $3);
1403 $$ = scm_cons (loc_on_music (@3, $1), $3);
1404 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1407 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1409 if (scm_is_true (scm_call_1 ($2, $4)))
1411 $$ = scm_cons ($4, $3);
1413 $$ = scm_cons (loc_on_music (@3, $1), $3);
1414 MYBACKUP (FRACTION, $4, @4);
1417 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1419 SCM n = scm_difference ($5, SCM_UNDEFINED);
1420 if (scm_is_true (scm_call_1 ($2, n))) {
1422 MYREPARSE (@5, $2, REAL, n);
1424 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1425 t->set_property ("digit", $5);
1426 $$ = t->unprotect ();
1427 if (scm_is_true (scm_call_1 ($2, $$)))
1428 $$ = scm_cons ($$, $3);
1430 $$ = scm_cons (loc_on_music (@3, $1), $3);
1431 MYBACKUP (UNSIGNED, $5, @5);
1432 parser->lexer_->push_extra_token ('-');
1437 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1439 SCM n = scm_difference ($5, SCM_UNDEFINED);
1440 if (scm_is_true (scm_call_1 ($2, n))) {
1441 MYREPARSE (@5, $2, REAL, n);
1444 $$ = scm_cons (loc_on_music (@3, $1), $3);
1445 MYBACKUP (REAL, n, @5);
1448 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1450 SCM n = scm_difference ($5, SCM_UNDEFINED);
1451 if (scm_is_true (scm_call_1 ($2, n))) {
1452 $$ = scm_cons (n, $3);
1454 $$ = scm_cons (loc_on_music (@3, $1), $3);
1455 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1458 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1460 $$ = scm_cons ($4, $3);
1462 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1464 $$ = scm_cons ($4, $3);
1466 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep SCM_IDENTIFIER
1468 SCM res = try_string_variants ($2, $4);
1469 if (!SCM_UNBNDP (res))
1470 $$ = scm_cons (res, $3);
1472 $$ = scm_cons (loc_on_music (@3, $1), $3);
1473 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1476 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep STRING
1478 SCM res = try_string_variants ($2, $4);
1479 if (!SCM_UNBNDP (res))
1480 $$ = scm_cons (res, $3);
1482 $$ = scm_cons (loc_on_music (@3, $1), $3);
1483 MYBACKUP (STRING, $4, @4);
1486 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep LYRICS_STRING
1488 SCM res = try_string_variants ($2, $4);
1489 if (!SCM_UNBNDP (res))
1490 $$ = scm_cons (res, $3);
1492 $$ = scm_cons (loc_on_music (@3, $1), $3);
1493 MYBACKUP (LYRICS_STRING, $4, @4);
1496 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1498 $$ = scm_cons ($1, $3);
1499 MYBACKUP(0, SCM_UNDEFINED, @3);
1501 | function_arglist_backup REPARSE bare_number
1503 $$ = check_scheme_arg (parser, @3,
1509 function_arglist_common
1510 | function_arglist_nonbackup
1513 function_arglist_common:
1514 function_arglist_bare
1515 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1517 $$ = check_scheme_arg (parser, @3,
1520 | EXPECT_SCM function_arglist_closed_optional bare_number
1522 $$ = check_scheme_arg (parser, @3,
1525 | EXPECT_SCM function_arglist_optional FRACTION
1527 $$ = check_scheme_arg (parser, @3,
1530 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1532 $$ = check_scheme_arg (parser, @3,
1535 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1537 SCM n = scm_difference ($4, SCM_UNDEFINED);
1538 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1540 | EXPECT_SCM function_arglist_optional STRING
1542 SCM res = try_string_variants ($1, $3);
1543 if (!SCM_UNBNDP (res))
1544 $$ = scm_cons ($3, $2);
1546 // This is going to flag a syntax error, we
1547 // know the predicate to be false.
1548 $$ = check_scheme_arg (parser, @3,
1551 | function_arglist_common_reparse REPARSE SCM_ARG
1553 $$ = check_scheme_arg (parser, @3,
1556 | function_arglist_common_reparse REPARSE lyric_element_music
1558 $$ = check_scheme_arg (parser, @3,
1561 | function_arglist_common_reparse REPARSE bare_number
1563 $$ = check_scheme_arg (parser, @3,
1568 function_arglist_common_reparse:
1569 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1572 SCM res = try_string_variants ($1, $3);
1573 if (!SCM_UNBNDP (res))
1574 MYREPARSE (@3, $1, SCM_ARG, res);
1575 else if (scm_is_true
1577 ($1, make_music_from_simple (parser, @3, $3))))
1578 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1580 // This is going to flag a syntax error, we
1581 // know the predicate to be false.
1582 MYREPARSE (@3, $1, SCM_ARG, $3);
1584 | EXPECT_SCM function_arglist_optional LYRICS_STRING
1587 SCM res = try_string_variants ($1, $3);
1588 if (!SCM_UNBNDP (res))
1589 MYREPARSE (@3, $1, SCM_ARG, res);
1590 else if (scm_is_true
1592 ($1, make_music_from_simple (parser, @3, $3))))
1593 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1595 // This is going to flag a syntax error, we
1596 // know the predicate to be false.
1597 MYREPARSE (@3, $1, SCM_ARG, $3);
1599 | EXPECT_SCM function_arglist_optional lyric_markup
1602 // We check how the predicate thinks about the
1603 // unmodified lyric element. If it would be accepted
1604 // in this form, we don't try interpreting is as lyric
1606 if (scm_is_true (scm_call_1 ($1, $3)))
1607 MYREPARSE (@3, $1, SCM_ARG, $3);
1608 else if (scm_is_true
1610 ($1, make_music_from_simple (parser, @3, $3))))
1611 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1613 // This is going to flag a syntax error, we
1614 // know the predicate to be false.
1615 MYREPARSE (@3, $1, SCM_ARG, $3);
1617 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1620 SCM n = scm_difference ($4, SCM_UNDEFINED);
1621 if (scm_is_true (scm_call_1 ($1, n)))
1622 MYREPARSE (@4, $1, REAL, n);
1624 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1625 t->set_property ("digit", $4);
1626 SCM m = t->unprotect ();
1627 if (scm_is_true (scm_call_1 ($1, m)))
1628 MYREPARSE (@4, $1, SCM_ARG, m);
1630 MYREPARSE (@4, $1, SCM_ARG, $4);
1634 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1637 SCM n = scm_difference ($4, SCM_UNDEFINED);
1638 MYREPARSE (@4, $1, REAL, n);
1642 function_arglist_closed:
1643 function_arglist_closed_common
1644 | function_arglist_closed_nonbackup
1647 function_arglist_closed_common:
1648 function_arglist_bare
1649 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1651 $$ = check_scheme_arg (parser, @3,
1654 | EXPECT_SCM function_arglist_closed_optional bare_number
1656 $$ = check_scheme_arg (parser, @3,
1659 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1661 $$ = check_scheme_arg (parser, @3,
1662 scm_difference ($4, SCM_UNDEFINED),
1665 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1667 $$ = check_scheme_arg (parser, @3,
1670 | EXPECT_SCM function_arglist_optional FRACTION
1672 $$ = check_scheme_arg (parser, @3,
1675 | EXPECT_SCM function_arglist_optional STRING
1677 SCM res = try_string_variants ($1, $3);
1678 if (!SCM_UNBNDP (res))
1679 $$ = scm_cons ($3, $2);
1681 // This is going to flag a syntax error, we
1682 // know the predicate to be false.
1683 $$ = check_scheme_arg (parser, @3,
1686 | function_arglist_common_reparse REPARSE SCM_ARG
1688 $$ = check_scheme_arg (parser, @3,
1691 | function_arglist_common_reparse REPARSE bare_number
1693 $$ = check_scheme_arg (parser, @3,
1698 function_arglist_optional:
1699 function_arglist_keep %prec FUNCTION_ARGLIST
1700 | function_arglist_backup BACKUP
1701 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1703 $$ = scm_cons ($1, $3);
1705 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1707 $$ = scm_cons ($1, $3);
1711 function_arglist_closed_optional:
1712 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1713 | function_arglist_backup BACKUP
1714 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1716 $$ = scm_cons ($1, $3);
1718 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1720 $$ = scm_cons ($1, $3);
1724 embedded_scm_closed:
1726 | scm_function_call_closed
1729 embedded_scm_arg_closed:
1730 embedded_scm_bare_arg
1731 | scm_function_call_closed
1735 scm_function_call_closed:
1736 SCM_FUNCTION function_arglist_closed {
1737 $$ = MAKE_SYNTAX ("music-function", @$,
1739 } %prec FUNCTION_ARGLIST
1742 function_arglist_bare:
1743 EXPECT_NO_MORE_ARGS {
1746 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1747 $$ = scm_cons ($3, $2);
1749 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1750 $$ = scm_cons ($3, $2);
1752 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1753 $$ = scm_cons ($1, $3);
1755 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1756 $$ = scm_cons ($1, $3);
1758 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1759 $$ = scm_cons ($1, $3);
1763 music_function_call:
1764 MUSIC_FUNCTION function_arglist {
1765 $$ = MAKE_SYNTAX ("music-function", @$,
1772 /**/ { $$ = SCM_EOL; }
1773 | '=' simple_string {
1780 | repeated_music { $$ = $1; }
1781 | re_rhythmed_music { $$ = $1; }
1782 | complex_music_prefix music
1784 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1788 complex_music_prefix:
1789 CONTEXT simple_string optional_id optional_context_mod {
1790 Context_mod *ctxmod = unsmob_context_mod ($4);
1793 mods = ctxmod->get_mods ();
1794 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1796 | NEWCONTEXT simple_string optional_id optional_context_mod {
1797 Context_mod *ctxmod = unsmob_context_mod ($4);
1800 mods = ctxmod->get_mods ();
1801 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1806 mode_changing_head grouped_music_list {
1807 if ($1 == ly_symbol2scm ("chords"))
1809 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1815 parser->lexer_->pop_state ();
1817 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1818 Context_mod *ctxmod = unsmob_context_mod ($2);
1821 mods = ctxmod->get_mods ();
1822 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1823 if ($1 == ly_symbol2scm ("ChordNames"))
1825 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1827 parser->lexer_->pop_state ();
1833 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1834 parser->lexer_->push_note_state (nn);
1836 $$ = ly_symbol2scm ("notes");
1840 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1841 parser->lexer_->push_note_state (nn);
1843 $$ = ly_symbol2scm ("drums");
1846 parser->lexer_->push_figuredbass_state ();
1848 $$ = ly_symbol2scm ("figures");
1851 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1852 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1853 nn = parser->lexer_->lookup_identifier ("pitchnames");
1854 parser->lexer_->push_chord_state (nn);
1855 $$ = ly_symbol2scm ("chords");
1859 { parser->lexer_->push_lyric_state ();
1860 $$ = ly_symbol2scm ("lyrics");
1864 mode_changing_head_with_context:
1866 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1867 parser->lexer_->push_note_state (nn);
1869 $$ = ly_symbol2scm ("DrumStaff");
1872 parser->lexer_->push_figuredbass_state ();
1874 $$ = ly_symbol2scm ("FiguredBass");
1877 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1878 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1879 nn = parser->lexer_->lookup_identifier ("pitchnames");
1880 parser->lexer_->push_chord_state (nn);
1881 $$ = ly_symbol2scm ("ChordNames");
1884 { parser->lexer_->push_lyric_state ();
1885 $$ = ly_symbol2scm ("Lyrics");
1890 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1893 /* Can also use music at the expensive of two S/Rs similar to
1894 \repeat \alternative */
1895 parser->lexer_->pop_state ();
1897 $$ = scm_cons ($3, SCM_EOL);
1899 | new_lyrics ADDLYRICS {
1900 parser->lexer_->push_lyric_state ();
1902 parser->lexer_->pop_state ();
1903 $$ = scm_cons ($4, $1);
1908 composite_music new_lyrics {
1909 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1911 | LYRICSTO simple_string {
1912 parser->lexer_->push_lyric_state ();
1914 parser->lexer_->pop_state ();
1915 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1920 CHANGE STRING '=' STRING {
1921 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1926 property_path_revved:
1927 embedded_scm_closed {
1928 $$ = scm_cons ($1, SCM_EOL);
1930 | property_path_revved embedded_scm_closed {
1931 $$ = scm_cons ($2, $1);
1936 property_path_revved {
1937 $$ = scm_reverse_x ($1, SCM_EOL);
1943 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1944 scm_string_to_symbol ($1), $3);
1946 | UNSET simple_string {
1947 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1948 scm_string_to_symbol ($2));
1950 | OVERRIDE simple_string property_path '=' scalar {
1951 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1952 scm_string_to_symbol ($2), $5),
1955 | REVERT simple_string embedded_scm {
1956 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1957 scm_string_to_symbol ($2), $3);
1962 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1963 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1965 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1966 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1967 | DENIES { $$ = ly_symbol2scm ("denies"); }
1969 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1970 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1971 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1972 | NAME { $$ = ly_symbol2scm ("context-name"); }
1976 property_operation { $$ = $1; }
1977 | context_def_mod STRING {
1978 $$ = scm_list_2 ($1, $2);
1980 | context_def_mod embedded_scm
1982 if (!scm_is_string ($2)
1983 && ly_symbol2scm ("consists") != $1
1984 && ly_symbol2scm ("remove") != $1)
1987 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
1991 $$ = scm_list_2 ($1, $2);
1998 if (!is_regular_identifier ($1))
2000 @$.error (_("Grob name should be alphanumeric"));
2003 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
2004 scm_string_to_symbol ($1));
2006 | simple_string '.' simple_string {
2007 $$ = scm_list_2 (scm_string_to_symbol ($1),
2008 scm_string_to_symbol ($3));
2012 simple_music_property_def:
2013 OVERRIDE context_prop_spec property_path '=' scalar {
2014 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
2015 ly_symbol2scm ("OverrideProperty"),
2020 | REVERT context_prop_spec embedded_scm {
2021 $$ = scm_list_4 (scm_car ($2),
2022 ly_symbol2scm ("RevertProperty"),
2026 | SET context_prop_spec '=' scalar {
2027 $$ = scm_list_4 (scm_car ($2),
2028 ly_symbol2scm ("PropertySet"),
2032 | UNSET context_prop_spec {
2033 $$ = scm_list_3 (scm_car ($2),
2034 ly_symbol2scm ("PropertyUnset"),
2040 simple_music_property_def {
2041 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2050 | string '+' string {
2051 if (!scm_is_string ($1)) {
2052 parser->parser_error (@1, (_ ("simple string expected")));
2053 $1 = scm_string (SCM_EOL);
2055 if (!scm_is_string ($3)) {
2056 parser->parser_error (@3, (_ ("simple string expected")));
2057 $3 = scm_string (SCM_EOL);
2059 $$ = scm_string_append (scm_list_2 ($1, $3));
2063 simple_string: STRING {
2071 if (scm_is_string ($1)) {
2074 parser->parser_error (@1, (_ ("simple string expected")));
2075 $$ = scm_string (SCM_EOL);
2090 embedded_scm_arg_closed
2100 simple_element post_events {
2101 // Let the rhythmic music iterator sort this mess out.
2102 if (scm_is_pair ($2)) {
2103 $$ = make_music_from_simple (parser, @1, $1);
2104 if (unsmob_music ($$))
2105 unsmob_music ($$)->set_property ("articulations",
2106 scm_reverse_x ($2, SCM_EOL));
2108 parser->parser_error (@1, _("music expected"));
2111 | simple_chord_elements post_events {
2112 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2115 /* why is this giving wrong start location? -ns
2117 i.set_location (@1, @2);
2118 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2120 | CHORD_REPETITION optional_notemode_duration post_events {
2122 i.set_location (@1, @3);
2123 $$ = MAKE_SYNTAX ("repetition-chord", i,
2124 $2, scm_reverse_x ($3, SCM_EOL));
2126 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2128 i.set_location (@1, @3);
2129 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2130 scm_reverse_x ($3, SCM_EOL));
2133 | note_chord_element
2138 chord_body optional_notemode_duration post_events
2140 Music *m = unsmob_music ($1);
2141 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2142 SCM es = m->get_property ("elements");
2143 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2145 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2146 unsmob_music (scm_car (s))->set_property ("duration", dur);
2147 es = ly_append2 (es, postevs);
2149 m-> set_property ("elements", es);
2151 $$ = m->self_scm ();
2156 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2158 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2162 chord_body_elements:
2163 /* empty */ { $$ = SCM_EOL; }
2164 | chord_body_elements chord_body_element {
2165 if (!SCM_UNBNDP ($2))
2166 $$ = scm_cons ($2, $1);
2171 pitch exclamations questions octave_check post_events
2173 bool q = to_boolean ($3);
2174 bool ex = to_boolean ($2);
2178 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2179 n->set_property ("pitch", $1);
2181 n->set_property ("cautionary", SCM_BOOL_T);
2183 n->set_property ("force-accidental", SCM_BOOL_T);
2185 if (scm_is_pair (post)) {
2186 SCM arts = scm_reverse_x (post, SCM_EOL);
2187 n->set_property ("articulations", arts);
2189 if (scm_is_number (check))
2191 int q = scm_to_int (check);
2192 n->set_property ("absolute-octave", scm_from_int (q-1));
2195 $$ = n->unprotect ();
2197 | DRUM_PITCH post_events {
2198 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2199 n->set_property ("drum-type", $1);
2201 if (scm_is_pair ($2)) {
2202 SCM arts = scm_reverse_x ($2, SCM_EOL);
2203 n->set_property ("articulations", arts);
2205 $$ = n->unprotect ();
2207 | music_function_chord_body
2209 Music *m = unsmob_music ($1);
2211 while (m && m->is_mus_type ("music-wrapper-music")) {
2212 $$ = m->get_property ("element");
2213 m = unsmob_music ($$);
2216 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2217 parser->parser_error (@$, _ ("not a rhythmic event"));
2223 music_function_chord_body:
2228 // Event functions may only take closed arglists, otherwise it would
2229 // not be clear whether a following postevent should be associated
2230 // with the last argument of the event function or with the expression
2231 // for which the function call acts itself as event.
2233 music_function_call_closed:
2234 MUSIC_FUNCTION function_arglist_closed {
2235 $$ = MAKE_SYNTAX ("music-function", @$,
2240 event_function_event:
2241 EVENT_FUNCTION function_arglist_closed {
2242 $$ = MAKE_SYNTAX ("music-function", @$,
2252 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2253 m->set_property ("span-direction", scm_from_int (START));
2254 $$ = m->unprotect();
2257 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2258 m->set_property ("span-direction", scm_from_int (STOP));
2259 $$ = m->unprotect ();
2262 $$ = MAKE_SYNTAX ("voice-separator", @$);
2265 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2267 Music *m = unsmob_music (pipe);
2272 $$ = m->unprotect ();
2275 $$ = MAKE_SYNTAX ("bar-check", @$);
2282 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2294 | post_events post_event {
2295 unsmob_music ($2)->set_spot (@2);
2296 $$ = scm_cons ($2, $$);
2300 post_event_nofinger:
2301 direction_less_event {
2304 | script_dir music_function_call_closed {
2306 if (!SCM_UNBNDP ($1))
2308 unsmob_music ($$)->set_property ("direction", $1);
2312 if (!parser->lexer_->is_lyric_state ())
2313 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2314 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2317 if (!parser->lexer_->is_lyric_state ())
2318 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2319 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2321 | script_dir direction_reqd_event {
2322 if (!SCM_UNBNDP ($1))
2324 Music *m = unsmob_music ($2);
2325 m->set_property ("direction", $1);
2329 | script_dir direction_less_event {
2330 if (!SCM_UNBNDP ($1))
2332 Music *m = unsmob_music ($2);
2333 m->set_property ("direction", $1);
2340 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2345 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2356 string_number_event:
2358 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2359 s->set_property ("string-number", $1);
2360 $$ = s->unprotect ();
2364 direction_less_char:
2366 $$ = ly_symbol2scm ("bracketOpenSymbol");
2369 $$ = ly_symbol2scm ("bracketCloseSymbol");
2372 $$ = ly_symbol2scm ("tildeSymbol");
2375 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2378 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2381 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2384 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2387 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2390 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2393 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2397 direction_less_event:
2398 direction_less_char {
2399 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2401 if (unsmob_music (predefd))
2403 m = unsmob_music (predefd)->clone ();
2408 m = MY_MAKE_MUSIC ("Music", @$);
2410 $$ = m->unprotect ();
2412 | string_number_event
2413 | EVENT_IDENTIFIER {
2417 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2418 a->set_property ("tremolo-type", $1);
2419 $$ = a->unprotect ();
2421 | event_function_event
2424 direction_reqd_event:
2428 | script_abbreviation {
2429 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2430 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2431 if (scm_is_string (s))
2432 a->set_property ("articulation-type", s);
2433 else parser->parser_error (@1, _ ("expecting string as script definition"));
2434 $$ = a->unprotect ();
2439 /**/ { $$ = SCM_EOL; }
2440 | '=' quotes { $$ = $2; }
2454 $$ = scm_from_int (1);
2457 $$ = scm_oneplus ($1);
2463 $$ = scm_from_int (-1);
2466 $$ = scm_oneminus ($1);
2471 NOTENAME_PITCH quotes {
2472 if (!scm_is_eq (SCM_INUM0, $2))
2474 Pitch p = *unsmob_pitch ($1);
2475 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2476 $$ = p.smobbed_copy ();
2486 TONICNAME_PITCH quotes {
2487 if (!scm_is_eq (SCM_INUM0, $2))
2489 Pitch p = *unsmob_pitch ($1);
2490 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2491 $$ = p.smobbed_copy ();
2501 pitch_also_in_chords:
2508 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2509 t->set_property ("text", $1);
2510 $$ = t->unprotect ();
2513 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2514 t->set_property ("text",
2515 make_simple_markup ($1));
2516 $$ = t->unprotect ();
2519 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2520 t->set_property ("text",
2521 make_simple_markup ($1));
2522 $$ = t->unprotect ();
2526 Music *m = unsmob_music ($1);
2527 if (m && m->is_mus_type ("post-event"))
2529 else if (Text_interface::is_markup ($1)) {
2530 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2531 t->set_property ("text", $1);
2532 $$ = t->unprotect ();
2534 parser->parser_error (@1, _ ("not an articulation"));
2540 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2541 t->set_property ("digit", $1);
2542 $$ = t->unprotect ();
2546 script_abbreviation:
2548 $$ = scm_from_locale_string ("Hat");
2551 $$ = scm_from_locale_string ("Plus");
2554 $$ = scm_from_locale_string ("Dash");
2557 $$ = scm_from_locale_string ("Bar");
2560 $$ = scm_from_locale_string ("Larger");
2563 $$ = scm_from_locale_string ("Dot");
2566 $$ = scm_from_locale_string ("Underscore");
2571 '_' { $$ = scm_from_int (DOWN); }
2572 | '^' { $$ = scm_from_int (UP); }
2573 | '-' { $$ = SCM_UNDEFINED; }
2577 multiplied_duration {
2582 maybe_notemode_duration:
2586 | multiplied_duration {
2588 parser->default_duration_ = *unsmob_duration ($$);
2593 optional_notemode_duration:
2594 maybe_notemode_duration
2596 if (SCM_UNBNDP ($$))
2597 $$ = parser->default_duration_.smobbed_copy ();
2604 int n = scm_to_int ($1);
2605 if (!is_duration (n))
2606 parser->parser_error (@1, _f ("not a duration: %d", n));
2610 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2612 | DURATION_IDENTIFIER dots {
2613 Duration *d = unsmob_duration ($1);
2614 Duration k (d->duration_log (),
2615 d->dot_count () + scm_to_int ($2));
2616 k = k.compressed (d->factor ());
2617 scm_remember_upto_here_1 ($1);
2618 $$ = k.smobbed_copy ();
2622 multiplied_duration:
2626 | multiplied_duration '*' UNSIGNED {
2627 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2629 | multiplied_duration '*' FRACTION {
2630 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2632 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2641 $$ = scm_oneplus ($1);
2650 int n = scm_to_int ($2);
2651 if (!is_duration (n))
2652 parser->parser_error (@2, _f ("not a duration: %d", n));
2658 UNSIGNED { $$ = $1; }
2659 | STRING { $$ = $1; }
2660 | full_markup { $$ = $1; }
2663 // as an integer, it needs to be non-negative, and otherwise
2664 // it needs to be suitable as a markup.
2665 if (scm_is_integer ($1)
2666 ? scm_is_true (scm_negative_p ($1))
2667 : !Text_interface::is_markup ($1))
2669 parser->parser_error (@1, _ ("bass number expected"));
2675 figured_bass_alteration:
2676 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2677 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2678 | '!' { $$ = scm_from_int (0); }
2683 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2684 $$ = bfr->unprotect ();
2687 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2688 $$ = bfr->self_scm ();
2690 if (scm_is_number ($1))
2691 bfr->set_property ("figure", $1);
2692 else if (Text_interface::is_markup ($1))
2693 bfr->set_property ("text", $1);
2699 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2701 | bass_figure figured_bass_alteration {
2702 Music *m = unsmob_music ($1);
2703 if (scm_to_double ($2)) {
2704 SCM salter = m->get_property ("alteration");
2705 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2706 m->set_property ("alteration",
2707 scm_sum (alter, $2));
2709 m->set_property ("alteration", scm_from_int (0));
2712 | bass_figure figured_bass_modification {
2713 Music *m = unsmob_music ($1);
2714 if ($2 == ly_symbol2scm ("plus"))
2716 m->set_property ("augmented", SCM_BOOL_T);
2718 else if ($2 == ly_symbol2scm ("slash"))
2720 m->set_property ("diminished", SCM_BOOL_T);
2722 else if ($2 == ly_symbol2scm ("exclamation"))
2724 m->set_property ("no-continuation", SCM_BOOL_T);
2726 else if ($2 == ly_symbol2scm ("backslash"))
2728 m->set_property ("augmented-slash", SCM_BOOL_T);
2734 figured_bass_modification:
2736 $$ = ly_symbol2scm ("plus");
2739 $$ = ly_symbol2scm ("exclamation");
2742 $$ = ly_symbol2scm ("slash");
2745 $$ = ly_symbol2scm ("backslash");
2755 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2763 | figure_list br_bass_figure {
2764 $$ = scm_cons ($2, $1);
2769 FIGURE_OPEN figure_list FIGURE_CLOSE {
2770 $$ = scm_reverse_x ($2, SCM_EOL);
2776 /**/ { $$ = SCM_BOOL_F; }
2777 | REST { $$ = SCM_BOOL_T; }
2781 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2782 if (!parser->lexer_->is_note_state ())
2783 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2784 if (!SCM_UNBNDP ($2)
2786 || scm_is_number ($4)
2788 || scm_is_true ($6))
2791 if (scm_is_true ($6))
2792 n = MY_MAKE_MUSIC ("RestEvent", @$);
2794 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2796 n->set_property ("pitch", $1);
2797 if (SCM_UNBNDP ($5))
2798 n->set_property ("duration",
2799 parser->default_duration_.smobbed_copy ());
2801 n->set_property ("duration", $5);
2803 if (scm_is_number ($4))
2805 int q = scm_to_int ($4);
2806 n->set_property ("absolute-octave", scm_from_int (q-1));
2809 if (to_boolean ($3))
2810 n->set_property ("cautionary", SCM_BOOL_T);
2811 if (to_boolean ($2) || to_boolean ($3))
2812 n->set_property ("force-accidental", SCM_BOOL_T);
2814 $$ = n->unprotect ();
2817 | DRUM_PITCH optional_notemode_duration {
2818 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2819 n->set_property ("duration", $2);
2820 n->set_property ("drum-type", $1);
2822 $$ = n->unprotect ();
2824 | RESTNAME optional_notemode_duration {
2826 if (ly_scm2string ($1) == "s") {
2828 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2831 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2834 ev->set_property ("duration", $2);
2835 $$ = ev->unprotect ();
2839 simple_chord_elements:
2841 if (!parser->lexer_->is_chord_state ())
2842 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2845 | figure_spec optional_notemode_duration {
2846 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2848 unsmob_music (scm_car (s))->set_property ("duration", $2);
2864 lyric_element_music:
2865 lyric_element optional_notemode_duration post_events {
2866 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2867 if (scm_is_pair ($3))
2868 unsmob_music ($$)->set_property
2869 ("articulations", scm_reverse_x ($3, SCM_EOL));
2874 steno_tonic_pitch optional_notemode_duration {
2875 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2877 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2878 SCM its = scm_reverse_x ($4, SCM_EOL);
2879 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2887 | chord_items chord_item {
2888 $$ = scm_cons ($2, $$);
2894 $$ = ly_symbol2scm ("chord-colon");
2897 $$ = ly_symbol2scm ("chord-caret");
2899 | CHORD_SLASH steno_tonic_pitch {
2900 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2902 | CHORD_BASS steno_tonic_pitch {
2903 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2912 $$ = scm_reverse_x ($1, SCM_EOL);
2920 step_number { $$ = scm_cons ($1, SCM_EOL); }
2921 | step_numbers '.' step_number {
2922 $$ = scm_cons ($3, $$);
2928 $$ = make_chord_step ($1, 0);
2931 $$ = make_chord_step ($1, SHARP_ALTERATION);
2933 | UNSIGNED CHORD_MINUS {
2934 $$ = make_chord_step ($1, FLAT_ALTERATION);
2942 | UNSIGNED '~' UNSIGNED {
2943 $$ = scm_cons ($1, $3);
2950 TODO: should deprecate in favor of Scheme?
2954 number_expression '+' number_term {
2955 $$ = scm_sum ($1, $3);
2957 | number_expression '-' number_term {
2958 $$ = scm_difference ($1, $3);
2967 | number_factor '*' number_factor {
2968 $$ = scm_product ($1, $3);
2970 | number_factor '/' number_factor {
2971 $$ = scm_divide ($1, $3);
2976 '-' number_factor { /* %prec UNARY_MINUS */
2977 $$ = scm_difference ($2, SCM_UNDEFINED);
2985 | UNSIGNED NUMBER_IDENTIFIER {
2986 $$ = scm_product ($1, $2);
2988 | REAL NUMBER_IDENTIFIER {
2989 $$ = scm_product ($1, $2);
3005 { $$ = SCM_UNDEFINED; }
3008 if (SCM_UNBNDP ($1))
3016 { $$ = SCM_UNDEFINED; }
3019 if (SCM_UNBNDP ($1))
3027 This should be done more dynamically if possible.
3032 { parser->lexer_->push_markup_state (); }
3035 parser->lexer_->pop_state ();
3041 { parser->lexer_->push_markup_state (); }
3044 parser->lexer_->pop_state ();
3050 { parser->lexer_->push_markup_state (); }
3053 parser->lexer_->pop_state ();
3059 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3061 | markup_head_1_list simple_markup {
3062 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3072 if (Text_interface::is_markup ($1))
3073 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3074 else if (Text_interface::is_markup_list ($1))
3075 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3077 parser->parser_error (@1, _ ("not a markup"));
3078 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3085 markup_composed_list {
3088 | markup_braced_list {
3091 | markup_command_list {
3092 $$ = scm_list_1 ($1);
3094 | markup_scm MARKUPLIST_IDENTIFIER
3100 markup_composed_list:
3101 markup_head_1_list markup_braced_list {
3102 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3108 '{' markup_braced_list_body '}' {
3109 $$ = scm_reverse_x ($2, SCM_EOL);
3113 markup_braced_list_body:
3114 /* empty */ { $$ = SCM_EOL; }
3115 | markup_braced_list_body markup {
3116 $$ = scm_cons ($2, $1);
3118 | markup_braced_list_body markup_list {
3119 $$ = scm_reverse_x ($2, $1);
3123 markup_command_list:
3124 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3125 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3129 markup_command_basic_arguments:
3130 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3131 $$ = scm_cons ($3, $2);
3133 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3134 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3136 | EXPECT_NO_MORE_ARGS {
3141 markup_command_list_arguments:
3142 markup_command_basic_arguments { $$ = $1; }
3143 | EXPECT_MARKUP markup_command_list_arguments markup {
3144 $$ = scm_cons ($3, $2);
3149 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3150 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3155 markup_head_1_item {
3156 $$ = scm_list_1 ($1);
3158 | markup_head_1_list markup_head_1_item {
3159 $$ = scm_cons ($2, $1);
3165 $$ = make_simple_markup ($1);
3168 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3169 parser->lexer_->push_note_state (nn);
3170 } '{' score_body '}' {
3171 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3172 parser->lexer_->pop_state ();
3174 | MARKUP_FUNCTION markup_command_basic_arguments {
3175 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3177 | markup_scm MARKUP_IDENTIFIER
3184 markup_head_1_list simple_markup {
3185 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3186 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3196 Lily_parser::set_yydebug (bool x)
3202 Lily_parser::do_yyparse ()
3204 SCM retval = SCM_UNDEFINED;
3205 yyparse (this, &retval);
3215 It is a little strange to have this function in this file, but
3216 otherwise, we have to import music classes into the lexer.
3220 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3222 if (unsmob_book (sid)) {
3223 Book *book = unsmob_book (sid)->clone ();
3224 *destination = book->self_scm ();
3227 return BOOK_IDENTIFIER;
3228 } else if (scm_is_number (sid)) {
3230 return NUMBER_IDENTIFIER;
3231 } else if (unsmob_context_def (sid)) {
3232 Context_def *def= unsmob_context_def (sid)->clone ();
3234 *destination = def->self_scm ();
3237 return CONTEXT_DEF_IDENTIFIER;
3238 } else if (unsmob_context_mod (sid)) {
3239 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3241 return CONTEXT_MOD_IDENTIFIER;
3242 } else if (unsmob_score (sid)) {
3243 Score *score = new Score (*unsmob_score (sid));
3244 *destination = score->self_scm ();
3246 score->unprotect ();
3247 return SCORE_IDENTIFIER;
3248 } else if (Music *mus = unsmob_music (sid)) {
3249 mus = mus->clone ();
3250 *destination = mus->self_scm ();
3251 unsmob_music (*destination)->
3252 set_property ("origin", make_input (last_input_));
3254 bool is_event = mus->is_mus_type ("post-event");
3256 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3257 } else if (unsmob_pitch (sid)) {
3258 *destination = unsmob_pitch (sid)->smobbed_copy ();
3259 return PITCH_IDENTIFIER;
3260 } else if (unsmob_duration (sid)) {
3261 *destination = unsmob_duration (sid)->smobbed_copy ();
3262 return DURATION_IDENTIFIER;
3263 } else if (unsmob_output_def (sid)) {
3264 Output_def *p = unsmob_output_def (sid);
3267 *destination = p->self_scm ();
3269 return OUTPUT_DEF_IDENTIFIER;
3276 get_next_unique_context_id ()
3278 return scm_from_locale_string ("$uniqueContextId");
3283 get_next_unique_lyrics_context_id ()
3285 static int new_context_count;
3287 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3288 return scm_from_locale_string (s);
3291 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3292 SCM arg, SCM args, SCM pred)
3294 args = scm_cons (arg, args);
3295 if (scm_is_true (scm_call_1 (pred, arg)))
3297 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3298 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3299 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3303 SCM loc_on_music (Input loc, SCM arg)
3305 if (Music *m = unsmob_music (arg))
3309 return m->unprotect ();
3315 try_string_variants (SCM pred, SCM str)
3317 if (scm_is_true (scm_call_1 (pred, str)))
3319 if (!is_regular_identifier (str))
3320 return SCM_UNDEFINED;
3321 str = scm_string_to_symbol (str);
3322 if (scm_is_true (scm_call_1 (pred, str)))
3324 return SCM_UNDEFINED;
3328 is_regular_identifier (SCM id)
3330 if (!scm_is_string (id))
3333 string str = ly_scm2string (id);
3335 bool middle = false;
3337 for (string::iterator it=str.begin(); it != str.end (); it++)
3340 if ((c >= 'a' && c <= 'z')
3341 || (c >= 'A' && c <= 'Z')
3344 else if (middle && (c == '-' || c == '_'))
3353 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3355 if (unsmob_music (simple))
3357 if (parser->lexer_->is_note_state ()) {
3358 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3359 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3360 if (scm_is_symbol (simple))
3361 n->set_property ("drum-type", simple);
3362 else if (unsmob_pitch (simple))
3363 n->set_property ("pitch", simple);
3368 return n->unprotect ();
3369 } else if (parser->lexer_->is_lyric_state ()) {
3370 if (Text_interface::is_markup (simple))
3371 return MAKE_SYNTAX ("lyric-event", loc, simple,
3372 parser->default_duration_.smobbed_copy ());
3373 } else if (parser->lexer_->is_chord_state ()) {
3374 if (unsmob_pitch (simple))
3375 return make_chord_elements (loc, simple,
3376 parser->default_duration_.smobbed_copy (),
3383 make_music_with_input (SCM name, Input where)
3385 Music *m = make_music_by_name (name);
3386 m->set_spot (where);
3391 make_simple_markup (SCM a)
3399 return t && t == 1 << intlog2 (t);
3403 make_chord_step (SCM step_scm, Rational alter)
3405 int step = scm_to_int (step_scm);
3408 alter += FLAT_ALTERATION;
3412 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3413 return m.smobbed_copy ();
3418 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3420 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3421 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3422 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3424 unsmob_music (scm_car (s))->set_spot (loc);
3430 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3432 Lily_lexer *lex = parser->lexer_;
3436 lex->prepare_for_next_token ();
3437 return lex->yylex ();