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. */
65 %nonassoc REPEAT REPEAT_IDENTIFIER
68 /* The above precedences tackle the shift/reduce problem
71 \repeat .. \alternative
73 \repeat { \repeat .. \alternative }
77 \repeat { \repeat } \alternative
83 %right ':' UNSIGNED REAL E_UNSIGNED EVENT_IDENTIFIER EVENT_FUNCTION '^' '_'
84 HYPHEN EXTENDER DURATION_IDENTIFIER
86 /* The above are needed for collecting tremoli and other items (that
87 could otherwise be interpreted as belonging to the next function
88 argument) greedily, and together with the next rule will serve to
89 join numbers and units greedily instead of allowing them into
90 separate function arguments
93 %nonassoc NUMBER_IDENTIFIER
105 %{ // -*-Fundamental-*-
110 * The rules for who is protecting what are very shady. Uniformise
113 * There are too many lexical modes?
124 #include "context-def.hh"
125 #include "context-mod.hh"
126 #include "dimensions.hh"
127 #include "file-path.hh"
129 #include "international.hh"
130 #include "lily-guile.hh"
131 #include "lily-lexer.hh"
132 #include "lily-parser.hh"
136 #include "output-def.hh"
137 #include "paper-book.hh"
138 #include "scm-hash.hh"
140 #include "text-interface.hh"
144 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
146 parser->parser_error (*i, s);
149 #define MYBACKUP(Token, Value, Location) \
151 if (yychar == YYEMPTY) \
154 parser->lexer_->push_extra_token (Token, Value); \
155 parser->lexer_->push_extra_token (BACKUP); \
157 parser->parser_error \
158 (Location, _("Too much lookahead")); \
163 #define MYREPARSE(Location, Pred, Token, Value) \
165 if (yychar == YYEMPTY) \
167 parser->lexer_->push_extra_token (Token, Value); \
168 parser->lexer_->push_extra_token (REPARSE, \
171 parser->parser_error \
172 (Location, _("Too much lookahead")); \
181 #define MY_MAKE_MUSIC(x, spot) \
182 make_music_with_input (ly_symbol2scm (x), \
183 parser->lexer_->override_input (spot))
186 - Don't use lily module, create a new module instead.
187 - delay application of the function
189 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
190 scm_apply_0 (proc, args)
191 /* Syntactic Sugar. */
192 #define MAKE_SYNTAX(name, location, ...) \
193 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (parser->lexer_->override_input (location)), ##__VA_ARGS__, SCM_UNDEFINED))
194 #define START_MAKE_SYNTAX(name, ...) \
195 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
196 #define FINISH_MAKE_SYNTAX(start, location, ...) \
197 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (parser->lexer_->override_input (location)), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
199 SCM get_next_unique_context_id ();
200 SCM get_next_unique_lyrics_context_id ();
207 #define _(x) gettext (x)
211 static Music *make_music_with_input (SCM name, Input where);
212 SCM check_scheme_arg (Lily_parser *parser, Input loc,
213 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
214 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
215 SCM loc_on_music (Input loc, SCM arg);
216 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
217 SCM make_chord_step (SCM step, Rational alter);
218 SCM make_simple_markup (SCM a);
219 SCM make_duration (SCM t, int dots = 0);
220 bool is_regular_identifier (SCM id, bool multiple=false);
221 SCM try_string_variants (SCM pred, SCM str);
222 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
226 /* The third option is an alias that will be used to display the
227 syntax error. Bison CVS now correctly handles backslash escapes.
229 FIXME: Bison needs to translate some of these, eg, STRING.
233 /* Keyword tokens with plain escaped name. */
234 %token END_OF_FILE 0 "end of input"
235 %token ACCEPTS "\\accepts"
236 %token ADDLYRICS "\\addlyrics"
237 %token ALIAS "\\alias"
238 %token ALTERNATIVE "\\alternative"
240 %token BOOKPART "\\bookpart"
241 %token CHANGE "\\change"
242 %token CHORDMODE "\\chordmode"
243 %token CHORDS "\\chords"
244 %token CONSISTS "\\consists"
245 %token CONTEXT "\\context"
246 %token DEFAULT "\\default"
247 %token DEFAULTCHILD "\\defaultchild"
248 %token DENIES "\\denies"
249 %token DESCRIPTION "\\description"
250 %token DRUMMODE "\\drummode"
251 %token DRUMS "\\drums"
252 %token FIGUREMODE "\\figuremode"
253 %token FIGURES "\\figures"
254 %token HEADER "\\header"
255 %token INVALID "\\version-error"
256 %token LAYOUT "\\layout"
257 %token LYRICMODE "\\lyricmode"
258 %token LYRICS "\\lyrics"
259 %token LYRICSTO "\\lyricsto"
260 %token MARKUP "\\markup"
261 %token MARKUPLIST "\\markuplist"
264 %token NOTEMODE "\\notemode"
265 %token OVERRIDE "\\override"
266 %token PAPER "\\paper"
267 %token REMOVE "\\remove"
268 %token REPEAT "\\repeat"
270 %token REVERT "\\revert"
271 %token SCORE "\\score"
272 %token SCORELINES "\\score-lines"
273 %token SEQUENTIAL "\\sequential"
275 %token SIMULTANEOUS "\\simultaneous"
276 %token TEMPO "\\tempo"
278 %token UNSET "\\unset"
281 /* Keyword token exceptions. */
282 %token NEWCONTEXT "\\new"
285 /* Other string tokens. */
287 %token CHORD_BASS "/+"
288 %token CHORD_CARET "^"
289 %token CHORD_COLON ":"
290 %token CHORD_MINUS "-"
291 %token CHORD_SLASH "/"
292 %token ANGLE_OPEN "<"
293 %token ANGLE_CLOSE ">"
294 %token DOUBLE_ANGLE_OPEN "<<"
295 %token DOUBLE_ANGLE_CLOSE ">>"
296 %token E_BACKSLASH "\\"
297 %token E_EXCLAMATION "\\!"
302 If we give names, Bison complains.
304 %token FIGURE_CLOSE /* "\\>" */
305 %token FIGURE_OPEN /* "\\<" */
306 %token FIGURE_SPACE "_"
309 %token MULTI_MEASURE_REST
315 /* Artificial tokens, for more generic function syntax */
316 %token EXPECT_MARKUP "markup?"
317 %token EXPECT_SCM "scheme?"
318 %token BACKUP "(backed-up?)"
319 %token REPARSE "(reparsed?)"
320 %token EXPECT_MARKUP_LIST "markup-list?"
321 %token EXPECT_OPTIONAL "optional?"
322 /* After the last argument. */
323 %token EXPECT_NO_MORE_ARGS;
325 /* An artificial token for parsing embedded Lilypond */
326 %token EMBEDDED_LILY "#{"
328 %token BOOK_IDENTIFIER
329 %token CHORD_BODY_IDENTIFIER
330 %token CHORD_MODIFIER
331 %token CHORD_REPETITION
332 %token CONTEXT_DEF_IDENTIFIER
333 %token CONTEXT_MOD_IDENTIFIER
335 %token PITCH_IDENTIFIER
337 %token DURATION_IDENTIFIER
338 %token EVENT_IDENTIFIER
339 %token EVENT_FUNCTION
342 %token MARKUP_FUNCTION
343 %token MARKUP_LIST_FUNCTION
344 %token MARKUP_IDENTIFIER
345 %token MARKUPLIST_IDENTIFIER
346 %token MUSIC_FUNCTION
347 %token MUSIC_IDENTIFIER
348 %token NOTENAME_PITCH
349 %token NUMBER_IDENTIFIER
350 %token OUTPUT_DEF_IDENTIFIER
352 %token REPEAT_IDENTIFIER
356 %token SCM_IDENTIFIER
360 %token TONICNAME_PITCH
364 /* We don't assign precedence to / and *, because we might need varied
365 prec levels in different prods */
374 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
375 parser->lexer_->push_note_state (nn);
376 } embedded_lilypond {
377 parser->lexer_->pop_state ();
382 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
383 | lilypond toplevel_expression {
385 | lilypond assignment {
388 parser->error_level_ = 1;
391 parser->error_level_ = 1;
398 parser->lexer_->add_scope (get_header (parser));
400 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
403 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
404 scm_call_2 (proc, parser->self_scm (), $1);
407 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
408 scm_call_2 (proc, parser->self_scm (), $1);
411 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
412 scm_call_2 (proc, parser->self_scm (), $1);
415 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
416 scm_call_2 (proc, parser->self_scm (), $1);
419 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
420 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
423 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
424 scm_call_2 (proc, parser->self_scm (), $1);
427 // Evaluate and ignore #xxx, as opposed to \xxx
428 parser->lexer_->eval_scm_token ($1);
430 | embedded_scm_active
432 SCM out = SCM_UNDEFINED;
433 if (Text_interface::is_markup ($1))
434 out = scm_list_1 ($1);
435 else if (Text_interface::is_markup_list ($1))
437 if (scm_is_pair (out))
439 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
440 scm_call_2 (proc, parser->self_scm (), out);
441 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
442 parser->parser_error (@1, _("bad expression type"));
446 Output_def * od = unsmob_output_def ($1);
448 if (od->c_variable ("is-paper") == SCM_BOOL_T)
449 id = ly_symbol2scm ("$defaultpaper");
450 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
451 id = ly_symbol2scm ("$defaultmidi");
452 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
453 id = ly_symbol2scm ("$defaultlayout");
455 parser->lexer_->set_identifier (id, $1);
462 $$ = parser->lexer_->eval_scm_token ($1);
472 embedded_scm_bare_arg:
476 $$ = parser->lexer_->eval_scm_token ($1);
480 | context_modification
482 | context_def_spec_block
488 /* The generic version may end in music, or not */
495 /* embedded_scm_arg is _not_ casting pitches to music by default, this
496 * has to be done by the function itself. Note that this may cause
497 * the results of scm_function_call or embedded_scm_bare_arg to be
498 * turned into music from pitches as well. Note that this creates a
499 * distinctly awkward situation for calculated drum pitches. Those
500 * are at the current point of time rejected as music constituents as
501 * they can't be distinguished from "proper" symbols.
505 embedded_scm_bare_arg
511 SCM_FUNCTION function_arglist {
512 $$ = MAKE_SYNTAX ("music-function", @$,
517 embedded_lilypond_number:
518 '-' embedded_lilypond_number
520 $$ = scm_difference ($2, SCM_UNDEFINED);
523 | UNSIGNED NUMBER_IDENTIFIER
525 $$ = scm_product ($1, $2);
532 // FIXME: @$ does not contain a useful source location
533 // for empty rules, and the only token in the whole
534 // production, EMBEDDED_LILY, is synthetic and also
535 // contains no source location.
536 $$ = MAKE_SYNTAX ("void-music", @$);
538 | identifier_init_nonumber
539 | embedded_lilypond_number
540 | post_event post_events
542 $$ = scm_reverse_x ($2, SCM_EOL);
543 if (Music *m = unsmob_music ($1))
545 if (m->is_mus_type ("post-event-wrapper"))
547 (scm_list_2 (m->get_property ("elements"),
550 $$ = scm_cons ($1, $$);
553 && scm_is_null (scm_cdr ($$)))
557 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
558 m->set_property ("elements", $$);
559 $$ = m->unprotect ();
562 | multiplied_duration
563 | music_embedded music_embedded music_list {
564 $3 = scm_reverse_x ($3, SCM_EOL);
565 if (unsmob_music ($2))
566 $3 = scm_cons ($2, $3);
567 if (unsmob_music ($1))
568 $3 = scm_cons ($1, $3);
569 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
572 parser->error_level_ = 1;
573 $$ = SCM_UNSPECIFIED;
575 | INVALID embedded_lilypond {
576 parser->error_level_ = 1;
582 lilypond_header_body:
583 /* empty */ { $$ = SCM_UNSPECIFIED; }
584 | lilypond_header_body assignment {
587 | lilypond_header_body embedded_scm {
593 HEADER '{' lilypond_header_body '}' {
594 $$ = parser->lexer_->remove_scope ();
606 assignment_id '=' identifier_init {
607 parser->lexer_->set_identifier ($1, $3);
608 $$ = SCM_UNSPECIFIED;
610 | assignment_id property_path '=' identifier_init {
611 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
612 parser->lexer_->set_identifier (path, $4);
613 $$ = SCM_UNSPECIFIED;
619 identifier_init_nonumber
621 | post_event_nofinger post_events
623 $$ = scm_reverse_x ($2, SCM_EOL);
624 if (Music *m = unsmob_music ($1))
626 if (m->is_mus_type ("post-event-wrapper"))
628 (scm_list_2 (m->get_property ("elements"),
631 $$ = scm_cons ($1, $$);
634 && scm_is_null (scm_cdr ($$)))
638 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
639 m->set_property ("elements", $$);
640 $$ = m->unprotect ();
645 identifier_init_nonumber:
650 | context_def_spec_block
656 | context_modification
659 context_def_spec_block:
660 CONTEXT '{' context_def_spec_body '}'
663 unsmob_context_def ($$)->origin ()->set_spot (@$);
671 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
672 parser->lexer_->push_note_state (nn);
676 parser->lexer_->pop_state ();
681 context_mod_embedded:
684 if (unsmob_music ($1)) {
685 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
686 $1 = scm_call_2 (proc, parser->self_scm (), $1);
688 if (unsmob_context_mod ($1))
691 parser->parser_error (@1, _ ("not a context mod"));
692 $$ = Context_mod ().smobbed_copy ();
698 context_def_spec_body:
700 $$ = Context_def::make_scm ();
702 | CONTEXT_DEF_IDENTIFIER {
705 | context_def_spec_body context_mod {
706 if (!SCM_UNBNDP ($2))
707 unsmob_context_def ($$)->add_context_mod ($2);
709 | context_def_spec_body context_modification {
710 Context_def *td = unsmob_context_def ($$);
711 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
712 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
713 td->add_context_mod (scm_car (m));
716 | context_def_spec_body context_mod_embedded {
717 Context_def *td = unsmob_context_def ($$);
718 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
719 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
720 td->add_context_mod (scm_car (m));
728 BOOK '{' book_body '}' {
730 unsmob_book ($$)->origin ()->set_spot (@$);
732 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
737 * Use 'handlers' like for toplevel-* stuff?
738 * grok \layout and \midi? */
741 Book *book = new Book;
742 init_papers (parser);
743 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
744 book->paper_->unprotect ();
745 push_paper (parser, book->paper_);
746 book->header_ = get_header (parser);
747 $$ = book->unprotect ();
748 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
751 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
753 | book_body paper_block {
754 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
755 set_paper (parser, unsmob_output_def ($2));
757 | book_body bookpart_block {
758 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
759 scm_call_2 (proc, $1, $2);
761 | book_body score_block {
762 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
763 scm_call_2 (proc, $1, $2);
765 | book_body composite_music {
766 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
767 scm_call_3 (proc, parser->self_scm (), $1, $2);
769 | book_body full_markup {
770 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
771 scm_call_2 (proc, $1, scm_list_1 ($2));
773 | book_body full_markup_list {
774 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
775 scm_call_2 (proc, $1, $2);
777 | book_body SCM_TOKEN {
778 // Evaluate and ignore #xxx, as opposed to \xxx
779 parser->lexer_->eval_scm_token ($2);
781 | book_body embedded_scm_active
783 SCM out = SCM_UNDEFINED;
784 if (Text_interface::is_markup ($2))
785 out = scm_list_1 ($2);
786 else if (Text_interface::is_markup_list ($2))
788 if (scm_is_pair (out))
790 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
791 scm_call_2 (proc, $1, out);
792 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
793 parser->parser_error (@2, _("bad expression type"));
797 parser->lexer_->add_scope (unsmob_book ($1)->header_);
800 Book *book = unsmob_book ($1);
802 book->scores_ = SCM_EOL;
803 book->bookparts_ = SCM_EOL;
808 BOOKPART '{' bookpart_body '}' {
810 unsmob_book ($$)->origin ()->set_spot (@$);
811 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
817 Book *book = new Book;
818 $$ = book->unprotect ();
819 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
822 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
824 | bookpart_body paper_block {
825 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
827 | bookpart_body score_block {
828 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
829 scm_call_2 (proc, $1, $2);
831 | bookpart_body composite_music {
832 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
833 scm_call_3 (proc, parser->self_scm (), $1, $2);
835 | bookpart_body full_markup {
836 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
837 scm_call_2 (proc, $1, scm_list_1 ($2));
839 | bookpart_body full_markup_list {
840 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
841 scm_call_2 (proc, $1, $2);
843 | bookpart_body SCM_TOKEN {
844 // Evaluate and ignore #xxx, as opposed to \xxx
845 parser->lexer_->eval_scm_token ($2);
847 | bookpart_body embedded_scm_active
849 SCM out = SCM_UNDEFINED;
850 if (Text_interface::is_markup ($2))
851 out = scm_list_1 ($2);
852 else if (Text_interface::is_markup_list ($2))
854 if (scm_is_pair (out))
856 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
857 scm_call_2 (proc, $1, out);
858 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
859 parser->parser_error (@2, _("bad expression type"));
863 Book *book = unsmob_book ($1);
864 if (!ly_is_module (book->header_))
865 book->header_ = ly_make_module (false);
866 parser->lexer_->add_scope (book->header_);
868 | bookpart_body error {
869 Book *book = unsmob_book ($1);
871 book->scores_ = SCM_EOL;
876 SCORE '{' score_body '}' {
877 unsmob_score ($3)->origin ()->set_spot (@$);
889 if (!scm_is_pair ($1)
890 || !ly_is_module (scm_car ($1)))
891 $1 = scm_cons (ly_make_module (false), $1);
892 parser->lexer_->add_scope (scm_car ($1));
897 | score_headers output_def
899 Output_def *od = unsmob_output_def ($2);
900 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
902 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
907 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
908 scm_set_cdr_x ($1, scm_cons ($2, scm_cdr ($1)));
910 $$ = scm_cons ($2, $1);
918 score_headers music {
919 SCM scorify = ly_lily_module_constant ("scorify-music");
920 $$ = scm_call_2 (scorify, $2, parser->self_scm ());
922 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
924 unsmob_score ($$)->set_header (scm_car ($1));
927 for (SCM p = scm_reverse_x ($1, SCM_EOL);
928 scm_is_pair (p); p = scm_cdr (p))
931 add_output_def (unsmob_output_def (scm_car (p)));
934 | embedded_scm_active {
935 if (!unsmob_score ($1))
937 $$ = (new Score)->unprotect ();
938 parser->parser_error (@1, _("score expected"));
943 Score *score = unsmob_score ($1);
944 if (!ly_is_module (score->get_header ()))
945 score->set_header (ly_make_module (false));
946 parser->lexer_->add_scope (score->get_header ());
948 | score_body output_def {
949 Output_def *od = unsmob_output_def ($2);
950 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
952 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
957 unsmob_score ($1)->add_output_def (od);
961 unsmob_score ($$)->error_found_ = true;
972 Output_def *od = unsmob_output_def ($1);
974 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
976 parser->parser_error (@1, _ ("need \\paper for paper block"));
977 $$ = get_paper (parser)->unprotect ();
984 output_def_body '}' {
987 parser->lexer_->remove_scope ();
988 parser->lexer_->pop_state ();
994 Output_def *p = get_paper (parser);
995 p->input_origin_ = @$;
996 parser->lexer_->add_scope (p->scope_);
997 $$ = p->unprotect ();
1000 Output_def *p = get_midi (parser);
1001 $$ = p->unprotect ();
1002 parser->lexer_->add_scope (p->scope_);
1005 Output_def *p = get_layout (parser);
1007 parser->lexer_->add_scope (p->scope_);
1008 $$ = p->unprotect ();
1012 output_def_head_with_mode_switch:
1014 parser->lexer_->push_initial_state ();
1019 // We need this weird nonterminal because both music as well as a
1020 // context definition can start with \context and the difference is
1021 // only apparent after looking at the next token. If it is '{', there
1022 // is still time to escape from notes mode.
1024 music_or_context_def:
1026 | context_def_spec_block
1030 output_def_head_with_mode_switch '{' {
1032 unsmob_output_def ($$)->input_origin_.set_spot (@$);
1034 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1035 Output_def *o = unsmob_output_def ($3);
1036 o->input_origin_.set_spot (@$);
1037 $$ = o->self_scm ();
1038 parser->lexer_->remove_scope ();
1039 parser->lexer_->add_scope (o->scope_);
1041 | output_def_body assignment {
1044 | output_def_body embedded_scm {
1049 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1050 parser->lexer_->push_note_state (nn);
1051 } music_or_context_def
1053 parser->lexer_->pop_state ();
1054 if (unsmob_context_def ($3))
1055 assign_context_def (unsmob_output_def ($1), $3);
1058 SCM proc = parser->lexer_->lookup_identifier
1059 ("output-def-music-handler");
1060 scm_call_3 (proc, parser->self_scm (),
1064 | output_def_body error {
1070 TEMPO steno_duration '=' tempo_range {
1071 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1073 | TEMPO scalar steno_duration '=' tempo_range {
1074 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1077 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1082 The representation of a list is reversed to have efficient append. */
1088 | music_list music_embedded {
1089 if (unsmob_music ($2))
1090 $$ = scm_cons ($2, $1);
1092 | music_list error {
1093 Music *m = MY_MAKE_MUSIC("Music", @$);
1095 m->set_property ("error-found", SCM_BOOL_T);
1096 $$ = scm_cons (m->self_scm (), $1);
1097 m->unprotect (); /* UGH */
1104 $$ = scm_reverse_x ($2, SCM_EOL);
1109 | lyric_element_music
1115 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1116 parser->parser_error (@1, _ ("unexpected post-event"));
1117 $$ = SCM_UNSPECIFIED;
1120 | music_embedded_backup
1124 | music_embedded_backup BACKUP lyric_element_music
1128 | multiplied_duration post_events
1130 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1132 parser->default_duration_ = *unsmob_duration ($1);
1133 n->set_property ("duration", $1);
1135 if (scm_is_pair ($2))
1136 n->set_property ("articulations",
1137 scm_reverse_x ($2, SCM_EOL));
1138 $$ = n->unprotect ();
1142 music_embedded_backup:
1145 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1147 else if (Music *m = unsmob_music ($1)) {
1148 if (m->is_mus_type ("post-event")) {
1149 parser->parser_error
1150 (@1, _ ("unexpected post-event"));
1151 $$ = SCM_UNSPECIFIED;
1154 } else if (parser->lexer_->is_lyric_state ()
1155 && Text_interface::is_markup ($1))
1156 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1158 @$.warning (_ ("Ignoring non-music expression"));
1167 $$ = make_music_from_simple (parser, @1, $1);
1168 if (!unsmob_music ($$))
1170 parser->parser_error (@1, _ ("music expected"));
1171 $$ = MAKE_SYNTAX ("void-music", @$);
1174 | composite_music %prec COMPOSITE
1179 | composite_music %prec COMPOSITE
1183 REPEAT simple_string unsigned_number music
1185 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1187 | REPEAT_IDENTIFIER music
1189 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1192 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1194 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1196 | REPEAT_IDENTIFIER music ALTERNATIVE braced_music_list
1198 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1204 SEQUENTIAL braced_music_list {
1205 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1207 | braced_music_list {
1208 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1213 SIMULTANEOUS braced_music_list {
1214 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1216 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1217 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1223 | music_property_def
1227 context_modification:
1230 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1231 parser->lexer_->push_note_state (nn);
1232 } '{' context_mod_list '}'
1234 parser->lexer_->pop_state ();
1237 | WITH CONTEXT_MOD_IDENTIFIER
1241 | CONTEXT_MOD_IDENTIFIER
1245 | WITH context_modification_arg
1247 if (unsmob_music ($2)) {
1248 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1249 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1251 if (unsmob_context_mod ($2))
1254 parser->parser_error (@2, _ ("not a context mod"));
1255 $$ = Context_mod ().smobbed_copy ();
1260 context_modification_arg:
1265 optional_context_mod:
1269 | context_modification
1277 $$ = Context_mod ().smobbed_copy ();
1279 | context_mod_list context_mod {
1280 if (!SCM_UNBNDP ($2))
1281 unsmob_context_mod ($1)->add_context_mod ($2);
1283 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1284 Context_mod *md = unsmob_context_mod ($2);
1286 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1288 | context_mod_list context_mod_embedded {
1289 unsmob_context_mod ($1)->add_context_mods
1290 (unsmob_context_mod ($2)->get_mods ());
1299 /* Music that can be parsed without lookahead */
1302 | complex_music_prefix closed_music
1304 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1306 | music_function_call_closed
1312 | grouped_music_list
1316 simultaneous_music { $$ = $1; }
1317 | sequential_music { $$ = $1; }
1320 /* Function argument lists are arguably the most complex part in the
1321 * parser. They are pretty tricky to understand because of the way
1322 * they are processed, and because of optional arguments that can be
1323 * omitted. When there are several optional arguments in a row,
1324 * omitting one automatically omits all following arguments. Optional
1325 * arguments can only be omitted when either
1327 * a) the omission is explicitly started with \default
1328 * b) the omission is implicitly started by an argument not matching
1329 * its predicate, and there is a mandatory argument later that can
1330 * "catch" the argument that does not fit.
1332 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1333 * (corresponding to mandatory arguments and having a predicate
1334 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1335 * the semantic value of the EXPECT_OPTIONAL token is the default to
1336 * use when the optional argument is omitted, and EXPECT_SCM again has
1337 * the argument predicate as semantic value) in reverse order to the
1338 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1339 * processed inside-out while actual tokens are consumed.
1341 * This means that the argument list tokens determine the actions
1342 * taken as they arrive. The structure of the argument list is known
1343 * to the parser and stored in its parse stack when the first argument
1344 * is being parsed. What the parser does not know is which predicates
1345 * will match and whether or not \default will be appearing in the
1346 * argument list, and where.
1348 * Many of the basic nonterminals used for argument list scanning come
1349 * in a "normal" and a "closed" flavor. A closed expression is one
1350 * that can be parsed without a lookahead token. That makes it
1351 * feasible for an optional argument that may need to be skipped:
1352 * skipping can only be accomplished by pushing back the token into
1353 * the lexer, and that only works when there is no lookahead token.
1355 * Sequences of 0 or more optional arguments are scanned using either
1356 * function_arglist_backup or function_arglist_nonbackup. The first
1357 * is used when optional arguments are followed by at least one
1358 * mandatory argument: in that case optional arguments may be skipped
1359 * by either a false predicate (in which case the expression will be
1360 * pushed back as one or more tokens, preceded by a BACKUP token) or
1361 * by using \default.
1363 * If optional arguments are at the end of the argument list, they are
1364 * instead scanned using function_arglist_nonbackup: here the only
1365 * manner to enter into skipping of optional arguments is the use of
1368 * The argument list of a normal function call is parsed using
1369 * function_arglist. The part of an argument list before a mandatory
1370 * argument is parsed using function_arglist_optional.
1372 * The difference is that leading optional arguments are scanned using
1373 * function_arglist_nonbackup and function_arglist_backup,
1376 * Most other details are obvious in the rules themselves.
1380 function_arglist_nonbackup_common:
1381 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1383 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1385 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1387 SCM n = scm_difference ($5, SCM_UNDEFINED);
1388 if (scm_is_true (scm_call_1 ($2, n)))
1389 $$ = scm_cons (n, $3);
1391 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1392 t->set_property ("digit", $5);
1393 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1398 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1400 $$ = check_scheme_arg (parser, @4,
1401 scm_difference ($5, SCM_UNDEFINED),
1404 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1406 $$ = check_scheme_arg (parser, @4,
1407 scm_difference ($5, SCM_UNDEFINED),
1412 function_arglist_closed_nonbackup:
1413 function_arglist_nonbackup_common
1414 | function_arglist_closed_common
1415 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg_closed
1417 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1419 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_closed
1421 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1423 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1425 $$ = check_scheme_arg (parser, @4,
1426 try_string_variants ($2, $4),
1429 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1431 $$ = check_scheme_arg (parser, @4,
1432 try_string_variants ($2, $4),
1435 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1437 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1443 | SYMBOL_LIST '.' symbol_list_rev
1445 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1451 | symbol_list_rev '.' symbol_list_part
1453 $$ = scm_append_x (scm_list_2 ($3, $1));
1457 // symbol_list_part delivers elements in reverse copy.
1462 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1463 $$ = try_string_variants (sym_l_p, $1);
1464 if (SCM_UNBNDP ($$)) {
1465 parser->parser_error (@1, _("not a symbol"));
1468 $$ = scm_reverse ($$);
1473 symbol_list_element:
1479 function_arglist_nonbackup:
1480 function_arglist_nonbackup_common
1481 | function_arglist_common
1482 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1484 if (scm_is_true (scm_call_1 ($2, $4)))
1485 $$ = scm_cons ($4, $3);
1487 $$ = check_scheme_arg (parser, @4,
1488 make_music_from_simple
1492 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1494 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1496 | function_arglist_nonbackup_reparse REPARSE duration_length
1498 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1500 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1502 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1504 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1506 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1508 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1510 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1512 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1514 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1518 function_arglist_nonbackup_reparse:
1519 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1522 SCM res = try_string_variants ($2, $4);
1523 if (!SCM_UNBNDP (res))
1524 if (scm_is_pair (res))
1525 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1527 MYREPARSE (@4, $2, SCM_ARG, res);
1528 else if (scm_is_true
1530 ($2, make_music_from_simple
1532 MYREPARSE (@4, $2, STRING, $4);
1534 MYREPARSE (@4, $2, SCM_ARG, $4);
1536 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1539 SCM res = try_string_variants ($2, $4);
1540 if (!SCM_UNBNDP (res))
1541 if (scm_is_pair (res))
1542 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1544 MYREPARSE (@4, $2, SCM_ARG, res);
1545 else if (scm_is_true
1547 ($2, make_music_from_simple
1549 MYREPARSE (@4, $2, STRING, $4);
1551 MYREPARSE (@4, $2, SCM_ARG, $4);
1553 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1556 if (scm_is_true (scm_call_1 ($2, $4)))
1557 MYREPARSE (@4, $2, SCM_ARG, $4);
1558 else if (scm_is_true
1560 ($2, make_music_from_simple
1562 MYREPARSE (@4, $2, STRING, $4);
1564 MYREPARSE (@4, $2, SCM_ARG, $4);
1566 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1569 if (scm_is_true (scm_call_1 ($2, $4)))
1570 MYREPARSE (@4, $2, REAL, $4);
1572 SCM d = make_duration ($4);
1573 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1574 MYREPARSE (@4, $2, REAL, $4); // trigger error
1576 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1579 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1581 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1586 // function_arglist_backup can't occur at the end of an argument
1587 // list. It needs to be careful about avoiding lookahead only until
1588 // it has made a decision whether or not to accept the parsed entity.
1589 // At that point of time, music requiring lookahead to parse becomes
1591 function_arglist_backup:
1592 function_arglist_common
1593 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg_closed
1595 if (scm_is_true (scm_call_1 ($2, $4)))
1597 $$ = scm_cons ($4, $3);
1599 $$ = scm_cons (loc_on_music (@3, $1), $3);
1600 MYBACKUP (SCM_ARG, $4, @4);
1603 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REPEAT simple_string unsigned_number
1605 $4 = MAKE_SYNTAX ("repeat", @4, $5, $6,
1606 MY_MAKE_MUSIC ("Music", @4)->unprotect (),
1608 if (scm_is_true (scm_call_1 ($2, $4)))
1611 MYREPARSE (@4, $2, REPEAT_IDENTIFIER, scm_cons ($5, $6));
1613 $$ = scm_cons (loc_on_music (@3, $1), $3);
1614 MYBACKUP (REPEAT_IDENTIFIER, scm_cons ($5, $6), @4);
1617 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup chord_body
1619 if (scm_is_true (scm_call_1 ($2, $4)))
1622 MYREPARSE (@4, $2, CHORD_BODY_IDENTIFIER, $4);
1624 $$ = scm_cons (loc_on_music (@3, $1), $3);
1625 MYBACKUP (CHORD_BODY_IDENTIFIER, $4, @4);
1628 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1630 if (scm_is_true (scm_call_1 ($2, $4)))
1632 $$ = scm_cons ($4, $3);
1634 $$ = scm_cons (loc_on_music (@3, $1), $3);
1635 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1638 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1640 if (scm_is_true (scm_call_1 ($2, $4)))
1641 $$ = scm_cons ($4, $3);
1643 $$ = scm_cons (loc_on_music (@3, $1), $3);
1644 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1647 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1649 if (scm_is_true (scm_call_1 ($2, $4)))
1651 MYREPARSE (@4, $2, REAL, $4);
1654 SCM d = make_duration ($4);
1655 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1657 $$ = scm_cons (loc_on_music (@3, $1), $3);
1658 MYBACKUP (UNSIGNED, $4, @4);
1660 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1665 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1667 if (scm_is_true (scm_call_1 ($2, $4)))
1670 MYREPARSE (@4, $2, REAL, $4);
1672 $$ = scm_cons (loc_on_music (@3, $1), $3);
1673 MYBACKUP (REAL, $4, @4);
1676 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1678 if (scm_is_true (scm_call_1 ($2, $4)))
1680 $$ = scm_cons ($4, $3);
1682 $$ = scm_cons (loc_on_music (@3, $1), $3);
1683 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1686 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1688 SCM n = scm_difference ($5, SCM_UNDEFINED);
1689 if (scm_is_true (scm_call_1 ($2, n))) {
1691 MYREPARSE (@5, $2, REAL, n);
1693 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1694 t->set_property ("digit", $5);
1695 $$ = t->unprotect ();
1696 if (scm_is_true (scm_call_1 ($2, $$)))
1697 $$ = scm_cons ($$, $3);
1699 $$ = scm_cons (loc_on_music (@3, $1), $3);
1700 MYBACKUP (UNSIGNED, $5, @5);
1701 parser->lexer_->push_extra_token ('-');
1706 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1708 SCM n = scm_difference ($5, SCM_UNDEFINED);
1709 if (scm_is_true (scm_call_1 ($2, n))) {
1710 MYREPARSE (@5, $2, REAL, n);
1713 $$ = scm_cons (loc_on_music (@3, $1), $3);
1714 MYBACKUP (REAL, n, @5);
1717 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1719 SCM n = scm_difference ($5, SCM_UNDEFINED);
1720 if (scm_is_true (scm_call_1 ($2, n))) {
1721 $$ = scm_cons (n, $3);
1723 $$ = scm_cons (loc_on_music (@3, $1), $3);
1724 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1727 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup PITCH_IDENTIFIER
1729 SCM m = make_music_from_simple (parser, @4, $4);
1730 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1732 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1734 } else if (scm_is_true (scm_call_1 ($2, $4)))
1736 MYREPARSE (@4, $2, PITCH_ARG, $4);
1739 $$ = scm_cons (loc_on_music (@3, $1), $3);
1740 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1743 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NOTENAME_PITCH
1745 SCM m = make_music_from_simple (parser, @4, $4);
1746 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1748 MYREPARSE (@4, $2, NOTENAME_PITCH, $4);
1750 } else if (scm_is_true (scm_call_1 ($2, $4)))
1752 MYREPARSE (@4, $2, PITCH_ARG, $4);
1755 $$ = scm_cons (loc_on_music (@3, $1), $3);
1756 MYBACKUP (NOTENAME_PITCH, $4, @4);
1759 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup TONICNAME_PITCH
1761 SCM m = make_music_from_simple (parser, @4, $4);
1762 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1764 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1766 } else if (scm_is_true (scm_call_1 ($2, $4)))
1768 MYREPARSE (@4, $2, PITCH_ARG, $4);
1771 $$ = scm_cons (loc_on_music (@3, $1), $3);
1772 MYBACKUP (TONICNAME_PITCH, $4, @4);
1775 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1777 if (scm_is_true (scm_call_1 ($2, $4)))
1779 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1782 $$ = scm_cons (loc_on_music (@3, $1), $3);
1783 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1786 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1788 SCM res = try_string_variants ($2, $4);
1789 if (!SCM_UNBNDP (res))
1790 if (scm_is_pair (res)) {
1792 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1795 $$ = scm_cons (res, $3);
1797 $$ = scm_cons (loc_on_music (@3, $1), $3);
1798 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1801 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1803 SCM res = try_string_variants ($2, $4);
1804 if (!SCM_UNBNDP (res))
1805 if (scm_is_pair (res)) {
1807 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1810 $$ = scm_cons (res, $3);
1812 $$ = scm_cons (loc_on_music (@3, $1), $3);
1813 MYBACKUP (STRING, $4, @4);
1816 | function_arglist_backup REPARSE music_assign
1818 if (scm_is_true (scm_call_1 ($2, $3)))
1819 $$ = scm_cons ($3, $1);
1821 $$ = check_scheme_arg (parser, @3,
1822 make_music_from_simple
1826 | function_arglist_backup REPARSE pitch_arg
1828 $$ = check_scheme_arg (parser, @3,
1831 | function_arglist_backup REPARSE bare_number_common
1833 $$ = check_scheme_arg (parser, @3,
1836 | function_arglist_backup REPARSE duration_length
1838 $$ = check_scheme_arg (parser, @3,
1841 | function_arglist_backup REPARSE symbol_list_arg
1843 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1848 function_arglist_nonbackup
1849 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1851 $$ = scm_cons (loc_on_music (@4, $1), $3);
1855 function_arglist_skip_nonbackup:
1856 function_arglist_nonbackup
1857 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1859 $$ = scm_cons (loc_on_music (@3, $1), $3);
1863 function_arglist_common:
1864 EXPECT_NO_MORE_ARGS {
1867 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1869 if (scm_is_true (scm_call_1 ($1, $3)))
1870 $$ = scm_cons ($3, $2);
1872 $$ = check_scheme_arg (parser, @3,
1873 make_music_from_simple
1877 | EXPECT_SCM function_arglist_optional bare_number_common
1879 $$ = check_scheme_arg (parser, @3,
1882 | EXPECT_SCM function_arglist_optional post_event_nofinger
1884 $$ = check_scheme_arg (parser, @3,
1887 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1889 SCM n = scm_difference ($4, SCM_UNDEFINED);
1890 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1892 | function_arglist_common_reparse REPARSE SCM_ARG
1894 $$ = check_scheme_arg (parser, @3,
1897 | function_arglist_common_reparse REPARSE lyric_element_music
1899 $$ = check_scheme_arg (parser, @3,
1902 | function_arglist_common_reparse REPARSE bare_number_common
1904 $$ = check_scheme_arg (parser, @3,
1907 | function_arglist_common_reparse REPARSE duration_length
1909 $$ = check_scheme_arg (parser, @3,
1912 | function_arglist_common_reparse REPARSE symbol_list_arg
1914 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1918 function_arglist_common_reparse:
1919 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1922 SCM res = try_string_variants ($1, $3);
1923 if (!SCM_UNBNDP (res))
1924 if (scm_is_pair (res))
1925 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1927 MYREPARSE (@3, $1, SCM_ARG, res);
1928 else if (scm_is_true
1930 ($1, make_music_from_simple (parser, @3, $3))))
1931 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1933 // This is going to flag a syntax error, we
1934 // know the predicate to be false.
1935 MYREPARSE (@3, $1, SCM_ARG, $3);
1937 | EXPECT_SCM function_arglist_optional STRING
1940 SCM res = try_string_variants ($1, $3);
1941 if (!SCM_UNBNDP (res))
1942 if (scm_is_pair (res))
1943 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1945 MYREPARSE (@3, $1, SCM_ARG, res);
1946 else if (scm_is_true
1948 ($1, make_music_from_simple (parser, @3, $3))))
1949 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1951 // This is going to flag a syntax error, we
1952 // know the predicate to be false.
1953 MYREPARSE (@3, $1, SCM_ARG, $3);
1955 | EXPECT_SCM function_arglist_optional full_markup
1958 if (scm_is_true (scm_call_1 ($1, $3)))
1959 MYREPARSE (@3, $1, SCM_ARG, $3);
1960 else if (scm_is_true
1962 ($1, make_music_from_simple (parser, @3, $3))))
1963 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1965 // This is going to flag a syntax error, we
1966 // know the predicate to be false.
1967 MYREPARSE (@3, $1, SCM_ARG, $3);
1969 | EXPECT_SCM function_arglist_optional UNSIGNED
1972 if (scm_is_true (scm_call_1 ($1, $3)))
1973 MYREPARSE (@3, $1, REAL, $3);
1975 SCM d = make_duration ($3);
1976 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
1977 MYREPARSE (@3, $1, REAL, $3);
1979 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
1982 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
1985 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
1987 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
1990 SCM n = scm_difference ($4, SCM_UNDEFINED);
1991 if (scm_is_true (scm_call_1 ($1, n)))
1992 MYREPARSE (@4, $1, REAL, n);
1994 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1995 t->set_property ("digit", $4);
1996 SCM m = t->unprotect ();
1997 if (scm_is_true (scm_call_1 ($1, m)))
1998 MYREPARSE (@4, $1, SCM_ARG, m);
2000 MYREPARSE (@4, $1, SCM_ARG, $4);
2004 | EXPECT_SCM function_arglist_optional '-' REAL
2007 SCM n = scm_difference ($4, SCM_UNDEFINED);
2008 MYREPARSE (@4, $1, REAL, n);
2012 function_arglist_closed:
2013 function_arglist_closed_nonbackup
2014 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2016 $$ = scm_cons (loc_on_music (@4, $1), $3);
2020 function_arglist_closed_common:
2021 EXPECT_NO_MORE_ARGS {
2024 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
2026 $$ = check_scheme_arg (parser, @3,
2029 | EXPECT_SCM function_arglist_optional bare_number_common_closed
2031 $$ = check_scheme_arg (parser, @3,
2034 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2036 $$ = check_scheme_arg (parser, @3,
2037 scm_difference ($4, SCM_UNDEFINED),
2040 | EXPECT_SCM function_arglist_optional post_event_nofinger
2042 $$ = check_scheme_arg (parser, @3,
2045 | function_arglist_common_reparse REPARSE SCM_ARG
2047 $$ = check_scheme_arg (parser, @3,
2050 | function_arglist_common_reparse REPARSE bare_number_common_closed
2052 $$ = check_scheme_arg (parser, @3,
2055 | function_arglist_common_reparse REPARSE symbol_list_arg
2057 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2061 function_arglist_optional:
2062 function_arglist_backup
2063 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2065 $$ = scm_cons (loc_on_music (@4, $1), $3);
2067 | function_arglist_skip_backup BACKUP
2070 function_arglist_skip_backup:
2071 function_arglist_backup
2072 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2074 $$ = scm_cons (loc_on_music (@3, $1), $3);
2078 embedded_scm_closed:
2080 | scm_function_call_closed
2083 embedded_scm_arg_closed:
2084 embedded_scm_bare_arg
2085 | scm_function_call_closed
2089 scm_function_call_closed:
2090 SCM_FUNCTION function_arglist_closed {
2091 $$ = MAKE_SYNTAX ("music-function", @$,
2096 music_function_call:
2097 MUSIC_FUNCTION function_arglist {
2098 $$ = MAKE_SYNTAX ("music-function", @$,
2105 /**/ { $$ = SCM_EOL; }
2106 | '=' simple_string {
2113 | repeated_music { $$ = $1; }
2114 | re_rhythmed_music { $$ = $1; }
2115 | complex_music_prefix music
2117 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2121 complex_music_prefix:
2122 CONTEXT symbol optional_id optional_context_mod {
2123 Context_mod *ctxmod = unsmob_context_mod ($4);
2126 mods = ctxmod->get_mods ();
2127 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2129 | NEWCONTEXT symbol optional_id optional_context_mod {
2130 Context_mod *ctxmod = unsmob_context_mod ($4);
2133 mods = ctxmod->get_mods ();
2134 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2139 mode_changing_head grouped_music_list {
2140 if ($1 == ly_symbol2scm ("chords"))
2142 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2148 parser->lexer_->pop_state ();
2150 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2151 Context_mod *ctxmod = unsmob_context_mod ($2);
2154 mods = ctxmod->get_mods ();
2155 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2156 if ($1 == ly_symbol2scm ("ChordNames"))
2158 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2160 parser->lexer_->pop_state ();
2166 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2167 parser->lexer_->push_note_state (nn);
2169 $$ = ly_symbol2scm ("notes");
2173 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2174 parser->lexer_->push_note_state (nn);
2176 $$ = ly_symbol2scm ("drums");
2179 parser->lexer_->push_figuredbass_state ();
2181 $$ = ly_symbol2scm ("figures");
2184 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2185 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2186 nn = parser->lexer_->lookup_identifier ("pitchnames");
2187 parser->lexer_->push_chord_state (nn);
2188 $$ = ly_symbol2scm ("chords");
2192 { parser->lexer_->push_lyric_state ();
2193 $$ = ly_symbol2scm ("lyrics");
2197 mode_changing_head_with_context:
2199 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2200 parser->lexer_->push_note_state (nn);
2202 $$ = ly_symbol2scm ("DrumStaff");
2205 parser->lexer_->push_figuredbass_state ();
2207 $$ = ly_symbol2scm ("FiguredBass");
2210 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2211 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2212 nn = parser->lexer_->lookup_identifier ("pitchnames");
2213 parser->lexer_->push_chord_state (nn);
2214 $$ = ly_symbol2scm ("ChordNames");
2217 { parser->lexer_->push_lyric_state ();
2218 $$ = ly_symbol2scm ("Lyrics");
2223 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2226 /* Can also use music at the expensive of two S/Rs similar to
2227 \repeat \alternative */
2228 parser->lexer_->pop_state ();
2230 $$ = scm_cons ($3, SCM_EOL);
2232 | new_lyrics ADDLYRICS {
2233 parser->lexer_->push_lyric_state ();
2235 parser->lexer_->pop_state ();
2236 $$ = scm_cons ($4, $1);
2241 composite_music new_lyrics {
2242 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2244 | LYRICSTO simple_string {
2245 parser->lexer_->push_lyric_state ();
2247 parser->lexer_->pop_state ();
2248 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2253 CHANGE symbol '=' simple_string {
2254 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2261 $$ = scm_reverse_x ($1, SCM_EOL);
2263 | symbol_list_rev property_path {
2264 $$ = scm_reverse_x ($1, $2);
2270 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2273 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2275 | OVERRIDE property_path '=' scalar {
2276 if (scm_ilength ($2) < 2) {
2277 parser->parser_error (@2, _("bad grob property path"));
2280 $$ = scm_cons (ly_symbol2scm ("push"),
2281 scm_cons2 (scm_car ($2),
2286 | REVERT revert_arg {
2287 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2291 // This is all quite awkward for the sake of substantial backward
2292 // compatibility while at the same time allowing a more "natural" form
2293 // of specification not separating grob specification from grob
2294 // property path. The purpose of this definition of revert_arg is to
2295 // allow the symbol list which specifies grob and property to revert
2296 // to be optionally be split into two parts after the grob (which in
2297 // this case is just the first element of the list). symbol_list_part
2298 // is only one path component, but it can be parsed without lookahead,
2299 // so we can follow it with a synthetic BACKUP token when needed. If
2300 // the first symbol_list_part already contains multiple elements (only
2301 // possible if a Scheme expression provides them), we just parse for
2302 // additional elements introduced by '.', which is what the
2303 // SYMBOL_LIST backup in connection with the immediately following
2304 // rule using symbol_list_arg does.
2306 // As long as we don't have our coffers filled with both grob and at
2307 // least one grob property specification, the rest of the required
2308 // symbol list chain may be provided either with or without a leading
2309 // dot. This is for both allowing the traditional
2310 // \revert Accidental #'color
2311 // as well as well as the "naive" form
2312 // \revert Accidental.color
2315 revert_arg_backup BACKUP symbol_list_arg
2324 if (scm_is_null ($1)
2325 || scm_is_null (scm_cdr ($1)))
2326 MYBACKUP (SCM_ARG, $1, @1);
2328 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2332 // revert_arg_part delivers results in reverse
2335 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2337 $$ = scm_append_x (scm_list_2 ($5, $3));
2339 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2341 $$ = scm_append_x (scm_list_2 ($4, $3));
2346 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2347 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2349 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2350 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2351 | DENIES { $$ = ly_symbol2scm ("denies"); }
2353 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2354 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2355 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2356 | NAME { $$ = ly_symbol2scm ("context-name"); }
2360 property_operation { $$ = $1; }
2361 | context_def_mod STRING {
2362 $$ = scm_list_2 ($1, $2);
2364 | context_def_mod embedded_scm
2366 if (!scm_is_string ($2)
2367 && ly_symbol2scm ("consists") != $1
2368 && ly_symbol2scm ("remove") != $1)
2371 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2375 $$ = scm_list_2 ($1, $2);
2380 // If defined, at least two members.
2384 SCM l = scm_reverse_x ($1, SCM_EOL);
2387 (scm_object_property (scm_car (l),
2388 ly_symbol2scm ("is-grob?"))))
2389 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2390 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2391 parser->parser_error (@1, _ ("bad grob property path"));
2398 // If defined, at least three members
2402 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2404 parser->parser_error (@1, _ ("bad grob property path"));
2408 | grob_prop_spec property_path
2410 if (!SCM_UNBNDP ($1)) {
2411 $$ = scm_append_x (scm_list_2 ($1, $2));
2412 if (scm_is_null (scm_cddr ($$))) {
2413 parser->parser_error (@$, _ ("bad grob property path"));
2421 // Exactly two elements or undefined
2425 SCM l = scm_reverse_x ($1, SCM_EOL);
2426 switch (scm_ilength (l)) {
2428 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2432 parser->parser_error (@1, _ ("bad context property path"));
2439 simple_music_property_def:
2440 OVERRIDE grob_prop_path '=' scalar {
2441 if (SCM_UNBNDP ($2))
2444 $$ = scm_list_5 (scm_car ($2),
2445 ly_symbol2scm ("OverrideProperty"),
2451 | REVERT simple_revert_context revert_arg {
2452 $$ = scm_list_4 ($2,
2453 ly_symbol2scm ("RevertProperty"),
2457 | SET context_prop_spec '=' scalar {
2458 if (SCM_UNBNDP ($2))
2461 $$ = scm_list_4 (scm_car ($2),
2462 ly_symbol2scm ("PropertySet"),
2466 | UNSET context_prop_spec {
2467 if (SCM_UNBNDP ($2))
2470 $$ = scm_list_3 (scm_car ($2),
2471 ly_symbol2scm ("PropertyUnset"),
2477 // This is all quite awkward for the sake of substantial backward
2478 // compatibility while at the same time allowing a more "natural" form
2479 // of specification not separating grob specification from grob
2480 // property path. The purpose of this definition of
2481 // simple_revert_context is to allow the symbol list which specifies
2482 // grob and property to revert to be optionally be split into two
2483 // parts after the grob (which may be preceded by a context
2484 // specification, a case which we distinguish by checking whether the
2485 // first symbol is a valid grob symbol instead).
2487 // See revert_arg above for the main work horse of this arrangement.
2488 // simple_revert_context just caters for the context and delegates the
2489 // rest of the job to revert_arg.
2491 simple_revert_context:
2494 $1 = scm_reverse_x ($1, SCM_EOL);
2495 if (scm_is_null ($1)
2497 (scm_object_property (scm_car ($1),
2498 ly_symbol2scm ("is-grob?")))) {
2499 $$ = ly_symbol2scm ("Bottom");
2500 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2503 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2510 simple_music_property_def {
2511 if (SCM_UNBNDP ($1))
2512 $$ = MAKE_SYNTAX ("void-music", @1);
2514 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2525 simple_string: STRING {
2530 if (scm_is_string ($1)) {
2533 parser->parser_error (@1, (_ ("simple string expected")));
2534 $$ = scm_string (SCM_EOL);
2541 $$ = scm_string_to_symbol ($1);
2545 // This is a bit of overkill but makes the same
2546 // routine responsible for all symbol interpretations.
2547 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2549 if (SCM_UNBNDP ($$))
2551 parser->parser_error (@1, (_ ("symbol expected")));
2552 // Generate a unique symbol in case it is used
2553 // for an assignment or similar
2554 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2563 // The following is a rather defensive variant of admitting
2564 // negative numbers: the grammar would permit number_factor or
2565 // even number_expression. However, function arguments allow
2566 // only this simple kind of negative number, so to have things
2567 // like \tweak and \override behave reasonably similar, it
2568 // makes sense to rule out things like -- which are rather an
2569 // accent in function argument contexts.
2572 $$ = scm_difference ($2, SCM_UNDEFINED);
2579 simple_element post_events {
2580 // Let the rhythmic music iterator sort this mess out.
2581 if (scm_is_pair ($2)) {
2582 $$ = make_music_from_simple (parser, @1, $1);
2583 if (unsmob_music ($$))
2584 unsmob_music ($$)->set_property ("articulations",
2585 scm_reverse_x ($2, SCM_EOL));
2588 parser->parser_error (@1, _("music expected"));
2589 $$ = MAKE_SYNTAX ("void-music", @1);
2593 | simple_chord_elements post_events {
2594 if (scm_is_pair ($2)) {
2595 if (unsmob_pitch ($1))
2596 $1 = make_chord_elements (@1,
2598 parser->default_duration_.smobbed_copy (),
2601 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2603 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
2604 } else if (!unsmob_pitch ($1))
2605 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
2606 // A mere pitch drops through.
2608 | CHORD_REPETITION optional_notemode_duration post_events {
2610 i.set_location (@1, @3);
2611 $$ = MAKE_SYNTAX ("repetition-chord", i,
2612 $2, scm_reverse_x ($3, SCM_EOL));
2614 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2616 i.set_location (@1, @3);
2617 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2618 scm_reverse_x ($3, SCM_EOL));
2621 | note_chord_element
2626 chord_body optional_notemode_duration post_events
2628 Music *m = unsmob_music ($1);
2629 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2630 SCM es = m->get_property ("elements");
2631 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2633 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2634 unsmob_music (scm_car (s))->set_property ("duration", dur);
2635 es = ly_append2 (es, postevs);
2637 m-> set_property ("elements", es);
2639 $$ = m->self_scm ();
2644 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2646 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2648 | CHORD_BODY_IDENTIFIER
2651 chord_body_elements:
2652 /* empty */ { $$ = SCM_EOL; }
2653 | chord_body_elements chord_body_element {
2654 if (!SCM_UNBNDP ($2))
2655 $$ = scm_cons ($2, $1);
2660 pitch exclamations questions octave_check post_events
2662 bool q = to_boolean ($3);
2663 bool ex = to_boolean ($2);
2667 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2668 n->set_property ("pitch", $1);
2670 n->set_property ("cautionary", SCM_BOOL_T);
2672 n->set_property ("force-accidental", SCM_BOOL_T);
2674 if (scm_is_pair (post)) {
2675 SCM arts = scm_reverse_x (post, SCM_EOL);
2676 n->set_property ("articulations", arts);
2678 if (scm_is_number (check))
2680 int q = scm_to_int (check);
2681 n->set_property ("absolute-octave", scm_from_int (q-1));
2684 $$ = n->unprotect ();
2686 | DRUM_PITCH post_events {
2687 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2688 n->set_property ("drum-type", $1);
2690 if (scm_is_pair ($2)) {
2691 SCM arts = scm_reverse_x ($2, SCM_EOL);
2692 n->set_property ("articulations", arts);
2694 $$ = n->unprotect ();
2696 | music_function_chord_body
2698 Music *m = unsmob_music ($1);
2700 while (m && m->is_mus_type ("music-wrapper-music")) {
2701 $$ = m->get_property ("element");
2702 m = unsmob_music ($$);
2705 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2706 parser->parser_error (@$, _ ("not a rhythmic event"));
2712 music_function_chord_body:
2717 // Event functions may only take closed arglists, otherwise it would
2718 // not be clear whether a following postevent should be associated
2719 // with the last argument of the event function or with the expression
2720 // for which the function call acts itself as event.
2722 music_function_call_closed:
2723 MUSIC_FUNCTION function_arglist_closed {
2724 $$ = MAKE_SYNTAX ("music-function", @$,
2729 event_function_event:
2730 EVENT_FUNCTION function_arglist_closed {
2731 $$ = MAKE_SYNTAX ("music-function", @$,
2753 | post_events post_event {
2755 if (Music *m = unsmob_music ($2))
2757 if (m->is_mus_type ("post-event-wrapper"))
2759 for (SCM p = m->get_property ("elements");
2763 $$ = scm_cons (scm_car (p), $$);
2767 $$ = scm_cons ($2, $$);
2773 post_event_nofinger:
2774 direction_less_event {
2777 | script_dir music_function_call_closed {
2779 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2780 parser->parser_error (@2, _ ("post-event expected"));
2781 $$ = SCM_UNSPECIFIED;
2782 } else if (!SCM_UNBNDP ($1))
2784 unsmob_music ($$)->set_property ("direction", $1);
2788 if (!parser->lexer_->is_lyric_state ())
2789 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2790 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2793 if (!parser->lexer_->is_lyric_state ())
2794 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2795 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2797 | script_dir direction_reqd_event {
2798 if (!SCM_UNBNDP ($1))
2800 Music *m = unsmob_music ($2);
2801 m->set_property ("direction", $1);
2805 | script_dir direction_less_event {
2806 if (!SCM_UNBNDP ($1))
2808 Music *m = unsmob_music ($2);
2809 m->set_property ("direction", $1);
2816 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2821 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2832 string_number_event:
2834 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2835 s->set_property ("string-number", $1);
2836 $$ = s->unprotect ();
2840 direction_less_event:
2842 | EVENT_IDENTIFIER {
2846 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2847 a->set_property ("tremolo-type", $1);
2848 $$ = a->unprotect ();
2850 | event_function_event
2853 direction_reqd_event:
2857 | script_abbreviation {
2858 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2859 if (scm_is_string (s)) {
2860 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2861 a->set_property ("articulation-type", s);
2862 $$ = a->unprotect ();
2864 Music *original = unsmob_music (s);
2865 if (original && original->is_mus_type ("post-event")) {
2866 Music *a = original->clone ();
2867 a->set_spot (parser->lexer_->override_input (@$));
2868 $$ = a->unprotect ();
2870 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2871 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2878 /**/ { $$ = SCM_EOL; }
2879 | '=' quotes { $$ = $2; }
2893 $$ = scm_from_int (1);
2896 $$ = scm_oneplus ($1);
2902 $$ = scm_from_int (-1);
2905 $$ = scm_oneminus ($1);
2910 NOTENAME_PITCH quotes {
2911 if (!scm_is_eq (SCM_INUM0, $2))
2913 Pitch p = *unsmob_pitch ($1);
2914 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2915 $$ = p.smobbed_copy ();
2925 TONICNAME_PITCH quotes {
2926 if (!scm_is_eq (SCM_INUM0, $2))
2928 Pitch p = *unsmob_pitch ($1);
2929 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2930 $$ = p.smobbed_copy ();
2937 | PITCH_IDENTIFIER quotes {
2938 if (!scm_is_eq (SCM_INUM0, $2))
2940 Pitch p = *unsmob_pitch ($1);
2941 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2942 $$ = p.smobbed_copy ();
2949 if (!scm_is_eq (SCM_INUM0, $2))
2951 Pitch p = *unsmob_pitch ($1);
2952 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2953 $$ = p.smobbed_copy ();
2960 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2961 t->set_property ("text", $1);
2962 $$ = t->unprotect ();
2965 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2966 t->set_property ("text",
2967 make_simple_markup ($1));
2968 $$ = t->unprotect ();
2970 | embedded_scm_closed
2972 Music *m = unsmob_music ($1);
2973 if (m && m->is_mus_type ("post-event"))
2975 else if (Text_interface::is_markup ($1)) {
2976 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2977 t->set_property ("text", $1);
2978 $$ = t->unprotect ();
2980 parser->parser_error (@1, _ ("not an articulation"));
2986 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2987 t->set_property ("digit", $1);
2988 $$ = t->unprotect ();
2992 script_abbreviation:
2994 $$ = scm_from_locale_string ("Hat");
2997 $$ = scm_from_locale_string ("Plus");
3000 $$ = scm_from_locale_string ("Dash");
3003 $$ = scm_from_locale_string ("Bang");
3006 $$ = scm_from_locale_string ("Larger");
3009 $$ = scm_from_locale_string ("Dot");
3012 $$ = scm_from_locale_string ("Underscore");
3017 '_' { $$ = scm_from_int (DOWN); }
3018 | '^' { $$ = scm_from_int (UP); }
3019 | '-' { $$ = SCM_UNDEFINED; }
3023 multiplied_duration {
3028 maybe_notemode_duration:
3032 | multiplied_duration {
3034 parser->default_duration_ = *unsmob_duration ($$);
3039 optional_notemode_duration:
3040 maybe_notemode_duration
3042 if (SCM_UNBNDP ($$))
3043 $$ = parser->default_duration_.smobbed_copy ();
3049 $$ = make_duration ($1, scm_to_int ($2));
3050 if (SCM_UNBNDP ($$))
3052 parser->parser_error (@1, _ ("not a duration"));
3053 $$ = Duration ().smobbed_copy ();
3056 | DURATION_IDENTIFIER dots {
3057 Duration *d = unsmob_duration ($1);
3058 Duration k (d->duration_log (),
3059 d->dot_count () + scm_to_int ($2));
3060 k = k.compressed (d->factor ());
3061 scm_remember_upto_here_1 ($1);
3062 $$ = k.smobbed_copy ();
3066 multiplied_duration:
3070 | multiplied_duration '*' UNSIGNED {
3071 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
3073 | multiplied_duration '*' FRACTION {
3074 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
3076 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
3085 $$ = scm_oneplus ($1);
3094 if (SCM_UNBNDP (make_duration ($2)))
3095 parser->parser_error (@2, _ ("not a duration"));
3101 UNSIGNED { $$ = $1; }
3102 | STRING { $$ = $1; }
3103 | full_markup { $$ = $1; }
3106 // as an integer, it needs to be non-negative, and otherwise
3107 // it needs to be suitable as a markup.
3108 if (scm_is_integer ($1)
3109 ? scm_is_true (scm_negative_p ($1))
3110 : !Text_interface::is_markup ($1))
3112 parser->parser_error (@1, _ ("bass number expected"));
3118 figured_bass_alteration:
3119 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3120 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3121 | '!' { $$ = scm_from_int (0); }
3126 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3127 $$ = bfr->unprotect ();
3130 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3131 $$ = bfr->self_scm ();
3133 if (scm_is_number ($1))
3134 bfr->set_property ("figure", $1);
3135 else if (Text_interface::is_markup ($1))
3136 bfr->set_property ("text", $1);
3142 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3144 | bass_figure figured_bass_alteration {
3145 Music *m = unsmob_music ($1);
3146 if (scm_to_double ($2)) {
3147 SCM salter = m->get_property ("alteration");
3148 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3149 m->set_property ("alteration",
3150 scm_sum (alter, $2));
3152 m->set_property ("alteration", scm_from_int (0));
3155 | bass_figure figured_bass_modification {
3156 Music *m = unsmob_music ($1);
3157 m->set_property ($2, SCM_BOOL_T);
3162 figured_bass_modification:
3164 $$ = ly_symbol2scm ("augmented");
3167 $$ = ly_symbol2scm ("no-continuation");
3170 $$ = ly_symbol2scm ("diminished");
3173 $$ = ly_symbol2scm ("augmented-slash");
3183 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3191 | figure_list br_bass_figure {
3192 $$ = scm_cons ($2, $1);
3197 FIGURE_OPEN figure_list FIGURE_CLOSE {
3198 $$ = scm_reverse_x ($2, SCM_EOL);
3204 /**/ { $$ = SCM_BOOL_F; }
3205 | REST { $$ = SCM_BOOL_T; }
3209 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3210 if (!parser->lexer_->is_note_state ())
3211 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3212 if (!SCM_UNBNDP ($2)
3214 || scm_is_number ($4)
3216 || scm_is_true ($6))
3219 if (scm_is_true ($6))
3220 n = MY_MAKE_MUSIC ("RestEvent", @$);
3222 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3224 n->set_property ("pitch", $1);
3225 if (SCM_UNBNDP ($5))
3226 n->set_property ("duration",
3227 parser->default_duration_.smobbed_copy ());
3229 n->set_property ("duration", $5);
3231 if (scm_is_number ($4))
3233 int q = scm_to_int ($4);
3234 n->set_property ("absolute-octave", scm_from_int (q-1));
3237 if (to_boolean ($3))
3238 n->set_property ("cautionary", SCM_BOOL_T);
3239 if (to_boolean ($2) || to_boolean ($3))
3240 n->set_property ("force-accidental", SCM_BOOL_T);
3242 $$ = n->unprotect ();
3245 | DRUM_PITCH optional_notemode_duration {
3246 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3247 n->set_property ("duration", $2);
3248 n->set_property ("drum-type", $1);
3250 $$ = n->unprotect ();
3252 | RESTNAME optional_notemode_duration {
3254 if (ly_scm2string ($1) == "s") {
3256 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3259 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3262 ev->set_property ("duration", $2);
3263 $$ = ev->unprotect ();
3267 // Can return a single pitch rather than a list.
3268 simple_chord_elements:
3270 if (!parser->lexer_->is_chord_state ())
3271 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3274 | figure_spec optional_notemode_duration {
3275 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3277 unsmob_music (scm_car (s))->set_property ("duration", $2);
3285 if (!parser->lexer_->is_lyric_state ())
3286 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3290 if (!parser->lexer_->is_lyric_state ())
3291 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3297 lyric_element_music:
3298 lyric_element optional_notemode_duration post_events {
3299 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3300 if (scm_is_pair ($3))
3301 unsmob_music ($$)->set_property
3302 ("articulations", scm_reverse_x ($3, SCM_EOL));
3306 // Can return a single pitch rather than a list.
3308 steno_tonic_pitch maybe_notemode_duration {
3309 if (SCM_UNBNDP ($2))
3312 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3314 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3315 SCM its = scm_reverse_x ($4, SCM_EOL);
3316 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3324 | chord_items chord_item {
3325 $$ = scm_cons ($2, $$);
3331 $$ = ly_symbol2scm ("chord-colon");
3334 $$ = ly_symbol2scm ("chord-caret");
3336 | CHORD_SLASH steno_tonic_pitch {
3337 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3339 | CHORD_BASS steno_tonic_pitch {
3340 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3349 $$ = scm_reverse_x ($1, SCM_EOL);
3357 step_number { $$ = scm_cons ($1, SCM_EOL); }
3358 | step_numbers '.' step_number {
3359 $$ = scm_cons ($3, $$);
3365 $$ = make_chord_step ($1, 0);
3368 $$ = make_chord_step ($1, SHARP_ALTERATION);
3370 | UNSIGNED CHORD_MINUS {
3371 $$ = make_chord_step ($1, FLAT_ALTERATION);
3379 | unsigned_number '-' unsigned_number {
3380 $$ = scm_cons ($1, $3);
3387 TODO: should deprecate in favor of Scheme?
3391 number_expression '+' number_term {
3392 $$ = scm_sum ($1, $3);
3394 | number_expression '-' number_term {
3395 $$ = scm_difference ($1, $3);
3404 | number_factor '*' number_factor {
3405 $$ = scm_product ($1, $3);
3407 | number_factor '/' number_factor {
3408 $$ = scm_divide ($1, $3);
3413 '-' number_factor { /* %prec UNARY_MINUS */
3414 $$ = scm_difference ($2, SCM_UNDEFINED);
3420 bare_number_common_closed
3421 | REAL NUMBER_IDENTIFIER
3423 $$ = scm_product ($1, $2);
3427 bare_number_common_closed:
3435 | UNSIGNED NUMBER_IDENTIFIER {
3436 $$ = scm_product ($1, $2);
3442 | bare_number_common_closed
3449 if (!scm_is_integer ($1)
3450 || scm_is_true (scm_negative_p ($1)))
3452 parser->parser_error (@1, _("not an unsigned integer"));
3458 if (!scm_is_integer ($1)
3459 || scm_is_true (scm_negative_p ($1)))
3461 parser->parser_error (@1, _("not an unsigned integer"));
3468 { $$ = SCM_UNDEFINED; }
3471 if (SCM_UNBNDP ($1))
3479 { $$ = SCM_UNDEFINED; }
3482 if (SCM_UNBNDP ($1))
3491 { parser->lexer_->push_markup_state (); }
3494 parser->lexer_->pop_state ();
3500 { parser->lexer_->push_markup_state (); }
3503 parser->lexer_->pop_state ();
3509 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3511 | markup_head_1_list simple_markup
3513 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3514 @2, $1, scm_list_1 ($2)));
3524 if (Text_interface::is_markup ($1))
3525 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3526 else if (Text_interface::is_markup_list ($1))
3527 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3529 parser->parser_error (@1, _ ("not a markup"));
3530 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3537 markup_composed_list {
3540 | markup_uncomposed_list
3543 markup_uncomposed_list:
3544 markup_braced_list {
3547 | markup_command_list {
3548 $$ = scm_list_1 ($1);
3550 | markup_scm MARKUPLIST_IDENTIFIER
3555 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3556 parser->lexer_->push_note_state (nn);
3557 } '{' score_body '}' {
3558 unsmob_score ($4)->origin ()->set_spot (@$);
3559 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3560 parser->lexer_->pop_state ();
3564 markup_composed_list:
3565 markup_head_1_list markup_uncomposed_list {
3566 $$ = MAKE_SYNTAX ("composed-markup-list",
3572 '{' markup_braced_list_body '}' {
3573 $$ = scm_reverse_x ($2, SCM_EOL);
3577 markup_braced_list_body:
3578 /* empty */ { $$ = SCM_EOL; }
3579 | markup_braced_list_body markup {
3580 $$ = scm_cons ($2, $1);
3582 | markup_braced_list_body markup_list {
3583 $$ = scm_reverse_x ($2, $1);
3587 markup_command_list:
3588 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3589 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3593 markup_command_basic_arguments:
3594 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3595 $$ = scm_cons ($3, $2);
3597 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3598 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3600 | EXPECT_NO_MORE_ARGS {
3605 markup_command_list_arguments:
3606 markup_command_basic_arguments { $$ = $1; }
3607 | EXPECT_MARKUP markup_command_list_arguments markup {
3608 $$ = scm_cons ($3, $2);
3613 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3614 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3619 markup_head_1_item {
3620 $$ = scm_list_1 ($1);
3622 | markup_head_1_list markup_head_1_item {
3623 $$ = scm_cons ($2, $1);
3629 $$ = make_simple_markup ($1);
3632 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3633 parser->lexer_->push_note_state (nn);
3634 } '{' score_body '}' {
3635 unsmob_score ($4)->origin ()->set_spot (@$);
3636 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3637 parser->lexer_->pop_state ();
3639 | MARKUP_FUNCTION markup_command_basic_arguments {
3640 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3642 | markup_scm MARKUP_IDENTIFIER
3649 markup_head_1_list simple_markup
3651 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3652 @2, $1, scm_list_1 ($2)));
3662 Lily_parser::set_yydebug (bool x)
3668 Lily_parser::do_yyparse ()
3670 SCM retval = SCM_UNDEFINED;
3671 yyparse (this, &retval);
3681 It is a little strange to have this function in this file, but
3682 otherwise, we have to import music classes into the lexer.
3686 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3688 if (unsmob_book (sid)) {
3689 Book *book = unsmob_book (sid)->clone ();
3690 *destination = book->self_scm ();
3693 return BOOK_IDENTIFIER;
3694 } else if (scm_is_number (sid)) {
3696 return NUMBER_IDENTIFIER;
3697 } else if (unsmob_context_def (sid)) {
3698 Context_def *def= unsmob_context_def (sid)->clone ();
3700 *destination = def->self_scm ();
3703 return CONTEXT_DEF_IDENTIFIER;
3704 } else if (unsmob_context_mod (sid)) {
3705 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3707 return CONTEXT_MOD_IDENTIFIER;
3708 } else if (Music *mus = unsmob_music (sid)) {
3709 mus = mus->clone ();
3710 *destination = mus->self_scm ();
3711 bool is_event = mus->is_mus_type ("post-event");
3713 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3714 } else if (unsmob_pitch (sid)) {
3715 *destination = unsmob_pitch (sid)->smobbed_copy ();
3716 return PITCH_IDENTIFIER;
3717 } else if (unsmob_duration (sid)) {
3718 *destination = unsmob_duration (sid)->smobbed_copy ();
3719 return DURATION_IDENTIFIER;
3720 } else if (unsmob_output_def (sid)) {
3721 Output_def *p = unsmob_output_def (sid);
3724 *destination = p->self_scm ();
3726 return OUTPUT_DEF_IDENTIFIER;
3727 } else if (unsmob_score (sid)) {
3728 *destination = unsmob_score (sid)->clone ()->unprotect ();
3729 return SCM_IDENTIFIER;
3736 get_next_unique_context_id ()
3738 return scm_from_locale_string ("$uniqueContextId");
3743 get_next_unique_lyrics_context_id ()
3745 static int new_context_count;
3747 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3748 return scm_from_locale_string (s);
3751 // check_scheme_arg checks one argument with a given predicate for use
3752 // in an argument list and throws a syntax error if it is unusable.
3753 // The argument is prepended to the argument list in any case. After
3754 // throwing a syntax error, the argument list is terminated with #f as
3755 // its last cdr in order to mark it as uncallable while not losing
3756 // track of its total length.
3758 // There are a few special considerations: if optional argument disp
3759 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3760 // instead of arg in a prospective error message. This is useful if
3761 // arg is not the actual argument but rather a transformation of it.
3763 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3764 // and an error message using disp is produced unconditionally.
3766 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3767 SCM arg, SCM args, SCM pred, SCM disp)
3769 if (SCM_UNBNDP (arg))
3770 args = scm_cons (disp, args);
3772 args = scm_cons (arg, args);
3773 if (scm_is_true (scm_call_1 (pred, arg)))
3776 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3777 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3778 SCM_UNBNDP (disp) ? arg : disp);
3779 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3783 SCM loc_on_music (Input loc, SCM arg)
3785 if (Music *m = unsmob_music (arg))
3789 return m->unprotect ();
3795 try_string_variants (SCM pred, SCM str)
3797 // a matching predicate is always ok
3798 if (scm_is_true (scm_call_1 (pred, str)))
3800 // a symbol may be interpreted as a list of symbols if it helps
3801 if (scm_is_symbol (str)) {
3802 str = scm_list_1 (str);
3803 if (scm_is_true (scm_call_1 (pred, str)))
3805 return SCM_UNDEFINED;
3808 // If this cannot be a string representation of a symbol list,
3811 if (!is_regular_identifier (str, true))
3812 return SCM_UNDEFINED;
3814 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3815 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3816 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3818 // Let's attempt the symbol list interpretation first.
3820 if (scm_is_true (scm_call_1 (pred, str)))
3823 // If there is just one symbol in the list, we might interpret
3824 // it as a single symbol
3826 if (scm_is_null (scm_cdr (str)))
3828 str = scm_car (str);
3829 if (scm_is_true (scm_call_1 (pred, str)))
3833 return SCM_UNDEFINED;
3837 is_regular_identifier (SCM id, bool multiple)
3839 if (!scm_is_string (id))
3842 string str = ly_scm2string (id);
3844 bool middle = false;
3846 for (string::iterator it=str.begin(); it != str.end (); it++)
3849 if ((c >= 'a' && c <= 'z')
3850 || (c >= 'A' && c <= 'Z')
3853 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3862 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3864 if (unsmob_music (simple))
3866 if (parser->lexer_->is_note_state ()) {
3867 if (scm_is_symbol (simple)) {
3868 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3869 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3870 n->set_property ("drum-type", simple);
3871 return n->unprotect ();
3873 if (unsmob_pitch (simple)) {
3874 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3875 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3876 n->set_property ("pitch", simple);
3877 return n->unprotect ();
3880 } else if (parser->lexer_->is_lyric_state ()) {
3881 if (Text_interface::is_markup (simple))
3882 return MAKE_SYNTAX ("lyric-event", loc, simple,
3883 parser->default_duration_.smobbed_copy ());
3884 } else if (parser->lexer_->is_chord_state ()) {
3885 if (unsmob_pitch (simple))
3889 make_chord_elements (loc, simple,
3890 parser->default_duration_.smobbed_copy (),
3897 make_music_with_input (SCM name, Input where)
3899 Music *m = make_music_by_name (name);
3900 m->set_spot (where);
3905 make_simple_markup (SCM a)
3911 make_duration (SCM d, int dots)
3913 int t = scm_to_int (d);
3914 if (t > 0 && (t & (t-1)) == 0)
3915 return Duration (intlog2 (t), dots).smobbed_copy ();
3917 return SCM_UNDEFINED;
3921 make_chord_step (SCM step_scm, Rational alter)
3923 int step = scm_to_int (step_scm);
3926 alter += FLAT_ALTERATION;
3930 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3931 return m.smobbed_copy ();
3936 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3938 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3939 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3940 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3942 unsmob_music (scm_car (s))->set_spot (loc);
3948 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3950 Lily_lexer *lex = parser->lexer_;
3954 lex->prepare_for_next_token ();
3955 return lex->yylex ();