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 '}' {
883 SCM scorify = ly_lily_module_constant ("scorify-music");
884 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
886 unsmob_score ($$)->origin ()->set_spot (@$);
888 | embedded_scm_active {
890 if (unsmob_score ($1))
891 score = new Score (*unsmob_score ($1));
894 parser->parser_error (@1, _("score expected"));
896 unsmob_score ($$)->origin ()->set_spot (@$);
897 $$ = score->unprotect ();
901 Score *score = unsmob_score ($1);
902 if (!ly_is_module (score->get_header ()))
903 score->set_header (ly_make_module (false));
904 parser->lexer_->add_scope (score->get_header ());
906 | score_body output_def {
907 Output_def *od = unsmob_output_def ($2);
908 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
910 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
915 unsmob_score ($1)->add_output_def (od);
919 unsmob_score ($$)->error_found_ = true;
930 Output_def *od = unsmob_output_def ($1);
932 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
934 parser->parser_error (@1, _ ("need \\paper for paper block"));
935 $$ = get_paper (parser)->unprotect ();
942 output_def_body '}' {
945 parser->lexer_->remove_scope ();
946 parser->lexer_->pop_state ();
952 Output_def *p = get_paper (parser);
953 p->input_origin_ = @$;
954 parser->lexer_->add_scope (p->scope_);
955 $$ = p->unprotect ();
958 Output_def *p = get_midi (parser);
959 $$ = p->unprotect ();
960 parser->lexer_->add_scope (p->scope_);
963 Output_def *p = get_layout (parser);
965 parser->lexer_->add_scope (p->scope_);
966 $$ = p->unprotect ();
970 output_def_head_with_mode_switch:
972 parser->lexer_->push_initial_state ();
977 // We need this weird nonterminal because both music as well as a
978 // context definition can start with \context and the difference is
979 // only apparent after looking at the next token. If it is '{', there
980 // is still time to escape from notes mode.
982 music_or_context_def:
984 | context_def_spec_block
988 output_def_head_with_mode_switch '{' {
990 unsmob_output_def ($$)->input_origin_.set_spot (@$);
992 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
993 Output_def *o = unsmob_output_def ($3);
994 o->input_origin_.set_spot (@$);
996 parser->lexer_->remove_scope ();
997 parser->lexer_->add_scope (o->scope_);
999 | output_def_body assignment {
1002 | output_def_body embedded_scm {
1007 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1008 parser->lexer_->push_note_state (nn);
1009 } music_or_context_def
1011 parser->lexer_->pop_state ();
1012 if (unsmob_context_def ($3))
1013 assign_context_def (unsmob_output_def ($1), $3);
1016 SCM proc = parser->lexer_->lookup_identifier
1017 ("output-def-music-handler");
1018 scm_call_3 (proc, parser->self_scm (),
1022 | output_def_body error {
1028 TEMPO steno_duration '=' tempo_range {
1029 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1031 | TEMPO scalar steno_duration '=' tempo_range {
1032 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1035 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1040 The representation of a list is reversed to have efficient append. */
1046 | music_list music_embedded {
1047 if (unsmob_music ($2))
1048 $$ = scm_cons ($2, $1);
1050 | music_list error {
1051 Music *m = MY_MAKE_MUSIC("Music", @$);
1053 m->set_property ("error-found", SCM_BOOL_T);
1054 $$ = scm_cons (m->self_scm (), $1);
1055 m->unprotect (); /* UGH */
1062 $$ = scm_reverse_x ($2, SCM_EOL);
1067 | lyric_element_music
1073 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1074 parser->parser_error (@1, _ ("unexpected post-event"));
1075 $$ = SCM_UNSPECIFIED;
1078 | music_embedded_backup
1082 | music_embedded_backup BACKUP lyric_element_music
1086 | multiplied_duration post_events
1088 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1090 parser->default_duration_ = *unsmob_duration ($1);
1091 n->set_property ("duration", $1);
1093 if (scm_is_pair ($2))
1094 n->set_property ("articulations",
1095 scm_reverse_x ($2, SCM_EOL));
1096 $$ = n->unprotect ();
1100 music_embedded_backup:
1103 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1105 else if (Music *m = unsmob_music ($1)) {
1106 if (m->is_mus_type ("post-event")) {
1107 parser->parser_error
1108 (@1, _ ("unexpected post-event"));
1109 $$ = SCM_UNSPECIFIED;
1112 } else if (parser->lexer_->is_lyric_state ()
1113 && Text_interface::is_markup ($1))
1114 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1116 @$.warning (_ ("Ignoring non-music expression"));
1125 $$ = make_music_from_simple (parser, @1, $1);
1126 if (!unsmob_music ($$))
1128 parser->parser_error (@1, _ ("music expected"));
1129 $$ = MAKE_SYNTAX ("void-music", @$);
1132 | composite_music %prec COMPOSITE
1137 | composite_music %prec COMPOSITE
1141 REPEAT simple_string unsigned_number music
1143 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1145 | REPEAT_IDENTIFIER music
1147 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1150 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1152 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1154 | REPEAT_IDENTIFIER music ALTERNATIVE braced_music_list
1156 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1162 SEQUENTIAL braced_music_list {
1163 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1165 | braced_music_list {
1166 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1171 SIMULTANEOUS braced_music_list {
1172 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1174 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1175 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1181 | music_property_def
1185 context_modification:
1188 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1189 parser->lexer_->push_note_state (nn);
1190 } '{' context_mod_list '}'
1192 parser->lexer_->pop_state ();
1195 | WITH CONTEXT_MOD_IDENTIFIER
1199 | CONTEXT_MOD_IDENTIFIER
1203 | WITH context_modification_arg
1205 if (unsmob_music ($2)) {
1206 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1207 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1209 if (unsmob_context_mod ($2))
1212 parser->parser_error (@2, _ ("not a context mod"));
1213 $$ = Context_mod ().smobbed_copy ();
1218 context_modification_arg:
1223 optional_context_mod:
1227 | context_modification
1235 $$ = Context_mod ().smobbed_copy ();
1237 | context_mod_list context_mod {
1238 if (!SCM_UNBNDP ($2))
1239 unsmob_context_mod ($1)->add_context_mod ($2);
1241 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1242 Context_mod *md = unsmob_context_mod ($2);
1244 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1246 | context_mod_list context_mod_embedded {
1247 unsmob_context_mod ($1)->add_context_mods
1248 (unsmob_context_mod ($2)->get_mods ());
1257 /* Music that can be parsed without lookahead */
1260 | complex_music_prefix closed_music
1262 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1264 | music_function_call_closed
1270 | grouped_music_list
1274 simultaneous_music { $$ = $1; }
1275 | sequential_music { $$ = $1; }
1278 /* Function argument lists are arguably the most complex part in the
1279 * parser. They are pretty tricky to understand because of the way
1280 * they are processed, and because of optional arguments that can be
1281 * omitted. When there are several optional arguments in a row,
1282 * omitting one automatically omits all following arguments. Optional
1283 * arguments can only be omitted when either
1285 * a) the omission is explicitly started with \default
1286 * b) the omission is implicitly started by an argument not matching
1287 * its predicate, and there is a mandatory argument later that can
1288 * "catch" the argument that does not fit.
1290 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1291 * (corresponding to mandatory arguments and having a predicate
1292 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1293 * the semantic value of the EXPECT_OPTIONAL token is the default to
1294 * use when the optional argument is omitted, and EXPECT_SCM again has
1295 * the argument predicate as semantic value) in reverse order to the
1296 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1297 * processed inside-out while actual tokens are consumed.
1299 * This means that the argument list tokens determine the actions
1300 * taken as they arrive. The structure of the argument list is known
1301 * to the parser and stored in its parse stack when the first argument
1302 * is being parsed. What the parser does not know is which predicates
1303 * will match and whether or not \default will be appearing in the
1304 * argument list, and where.
1306 * Many of the basic nonterminals used for argument list scanning come
1307 * in a "normal" and a "closed" flavor. A closed expression is one
1308 * that can be parsed without a lookahead token. That makes it
1309 * feasible for an optional argument that may need to be skipped:
1310 * skipping can only be accomplished by pushing back the token into
1311 * the lexer, and that only works when there is no lookahead token.
1313 * Sequences of 0 or more optional arguments are scanned using either
1314 * function_arglist_backup or function_arglist_nonbackup. The first
1315 * is used when optional arguments are followed by at least one
1316 * mandatory argument: in that case optional arguments may be skipped
1317 * by either a false predicate (in which case the expression will be
1318 * pushed back as one or more tokens, preceded by a BACKUP token) or
1319 * by using \default.
1321 * If optional arguments are at the end of the argument list, they are
1322 * instead scanned using function_arglist_nonbackup: here the only
1323 * manner to enter into skipping of optional arguments is the use of
1326 * The argument list of a normal function call is parsed using
1327 * function_arglist. The part of an argument list before a mandatory
1328 * argument is parsed using function_arglist_optional.
1330 * The difference is that leading optional arguments are scanned using
1331 * function_arglist_nonbackup and function_arglist_backup,
1334 * Most other details are obvious in the rules themselves.
1338 function_arglist_nonbackup_common:
1339 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1341 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1343 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1345 SCM n = scm_difference ($5, SCM_UNDEFINED);
1346 if (scm_is_true (scm_call_1 ($2, n)))
1347 $$ = scm_cons (n, $3);
1349 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1350 t->set_property ("digit", $5);
1351 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1356 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1358 $$ = check_scheme_arg (parser, @4,
1359 scm_difference ($5, SCM_UNDEFINED),
1362 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1364 $$ = check_scheme_arg (parser, @4,
1365 scm_difference ($5, SCM_UNDEFINED),
1370 function_arglist_closed_nonbackup:
1371 function_arglist_nonbackup_common
1372 | function_arglist_closed_common
1373 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg_closed
1375 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1377 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_closed
1379 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1381 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1383 $$ = check_scheme_arg (parser, @4,
1384 try_string_variants ($2, $4),
1387 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1389 $$ = check_scheme_arg (parser, @4,
1390 try_string_variants ($2, $4),
1393 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1395 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1401 | SYMBOL_LIST '.' symbol_list_rev
1403 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1409 | symbol_list_rev '.' symbol_list_part
1411 $$ = scm_append_x (scm_list_2 ($3, $1));
1415 // symbol_list_part delivers elements in reverse copy.
1420 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1421 $$ = try_string_variants (sym_l_p, $1);
1422 if (SCM_UNBNDP ($$)) {
1423 parser->parser_error (@1, _("not a symbol"));
1426 $$ = scm_reverse ($$);
1431 symbol_list_element:
1437 function_arglist_nonbackup:
1438 function_arglist_nonbackup_common
1439 | function_arglist_common
1440 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1442 if (scm_is_true (scm_call_1 ($2, $4)))
1443 $$ = scm_cons ($4, $3);
1445 $$ = check_scheme_arg (parser, @4,
1446 make_music_from_simple
1450 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1452 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1454 | function_arglist_nonbackup_reparse REPARSE duration_length
1456 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1458 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1460 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1462 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1464 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1466 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1468 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1470 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1472 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1476 function_arglist_nonbackup_reparse:
1477 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1480 SCM res = try_string_variants ($2, $4);
1481 if (!SCM_UNBNDP (res))
1482 if (scm_is_pair (res))
1483 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1485 MYREPARSE (@4, $2, SCM_ARG, res);
1486 else if (scm_is_true
1488 ($2, make_music_from_simple
1490 MYREPARSE (@4, $2, STRING, $4);
1492 MYREPARSE (@4, $2, SCM_ARG, $4);
1494 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1497 SCM res = try_string_variants ($2, $4);
1498 if (!SCM_UNBNDP (res))
1499 if (scm_is_pair (res))
1500 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1502 MYREPARSE (@4, $2, SCM_ARG, res);
1503 else if (scm_is_true
1505 ($2, make_music_from_simple
1507 MYREPARSE (@4, $2, STRING, $4);
1509 MYREPARSE (@4, $2, SCM_ARG, $4);
1511 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1514 if (scm_is_true (scm_call_1 ($2, $4)))
1515 MYREPARSE (@4, $2, SCM_ARG, $4);
1516 else if (scm_is_true
1518 ($2, make_music_from_simple
1520 MYREPARSE (@4, $2, STRING, $4);
1522 MYREPARSE (@4, $2, SCM_ARG, $4);
1524 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1527 if (scm_is_true (scm_call_1 ($2, $4)))
1528 MYREPARSE (@4, $2, REAL, $4);
1530 SCM d = make_duration ($4);
1531 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1532 MYREPARSE (@4, $2, REAL, $4); // trigger error
1534 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1537 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1539 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1544 // function_arglist_backup can't occur at the end of an argument
1545 // list. It needs to be careful about avoiding lookahead only until
1546 // it has made a decision whether or not to accept the parsed entity.
1547 // At that point of time, music requiring lookahead to parse becomes
1549 function_arglist_backup:
1550 function_arglist_common
1551 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg_closed
1553 if (scm_is_true (scm_call_1 ($2, $4)))
1555 $$ = scm_cons ($4, $3);
1557 $$ = scm_cons (loc_on_music (@3, $1), $3);
1558 MYBACKUP (SCM_ARG, $4, @4);
1561 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REPEAT simple_string unsigned_number
1563 $4 = MAKE_SYNTAX ("repeat", @4, $5, $6,
1564 MY_MAKE_MUSIC ("Music", @4)->unprotect (),
1566 if (scm_is_true (scm_call_1 ($2, $4)))
1569 MYREPARSE (@4, $2, REPEAT_IDENTIFIER, scm_cons ($5, $6));
1571 $$ = scm_cons (loc_on_music (@3, $1), $3);
1572 MYBACKUP (REPEAT_IDENTIFIER, scm_cons ($5, $6), @4);
1575 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup chord_body
1577 if (scm_is_true (scm_call_1 ($2, $4)))
1580 MYREPARSE (@4, $2, CHORD_BODY_IDENTIFIER, $4);
1582 $$ = scm_cons (loc_on_music (@3, $1), $3);
1583 MYBACKUP (CHORD_BODY_IDENTIFIER, $4, @4);
1586 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1588 if (scm_is_true (scm_call_1 ($2, $4)))
1590 $$ = scm_cons ($4, $3);
1592 $$ = scm_cons (loc_on_music (@3, $1), $3);
1593 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1596 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1598 if (scm_is_true (scm_call_1 ($2, $4)))
1599 $$ = scm_cons ($4, $3);
1601 $$ = scm_cons (loc_on_music (@3, $1), $3);
1602 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1605 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1607 if (scm_is_true (scm_call_1 ($2, $4)))
1609 MYREPARSE (@4, $2, REAL, $4);
1612 SCM d = make_duration ($4);
1613 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1615 $$ = scm_cons (loc_on_music (@3, $1), $3);
1616 MYBACKUP (UNSIGNED, $4, @4);
1618 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1623 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1625 if (scm_is_true (scm_call_1 ($2, $4)))
1628 MYREPARSE (@4, $2, REAL, $4);
1630 $$ = scm_cons (loc_on_music (@3, $1), $3);
1631 MYBACKUP (REAL, $4, @4);
1634 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1636 if (scm_is_true (scm_call_1 ($2, $4)))
1638 $$ = scm_cons ($4, $3);
1640 $$ = scm_cons (loc_on_music (@3, $1), $3);
1641 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1644 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1646 SCM n = scm_difference ($5, SCM_UNDEFINED);
1647 if (scm_is_true (scm_call_1 ($2, n))) {
1649 MYREPARSE (@5, $2, REAL, n);
1651 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1652 t->set_property ("digit", $5);
1653 $$ = t->unprotect ();
1654 if (scm_is_true (scm_call_1 ($2, $$)))
1655 $$ = scm_cons ($$, $3);
1657 $$ = scm_cons (loc_on_music (@3, $1), $3);
1658 MYBACKUP (UNSIGNED, $5, @5);
1659 parser->lexer_->push_extra_token ('-');
1664 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1666 SCM n = scm_difference ($5, SCM_UNDEFINED);
1667 if (scm_is_true (scm_call_1 ($2, n))) {
1668 MYREPARSE (@5, $2, REAL, n);
1671 $$ = scm_cons (loc_on_music (@3, $1), $3);
1672 MYBACKUP (REAL, n, @5);
1675 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1677 SCM n = scm_difference ($5, SCM_UNDEFINED);
1678 if (scm_is_true (scm_call_1 ($2, n))) {
1679 $$ = scm_cons (n, $3);
1681 $$ = scm_cons (loc_on_music (@3, $1), $3);
1682 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1685 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup PITCH_IDENTIFIER
1687 SCM m = make_music_from_simple (parser, @4, $4);
1688 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1690 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1692 } else if (scm_is_true (scm_call_1 ($2, $4)))
1694 MYREPARSE (@4, $2, PITCH_ARG, $4);
1697 $$ = scm_cons (loc_on_music (@3, $1), $3);
1698 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1701 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NOTENAME_PITCH
1703 SCM m = make_music_from_simple (parser, @4, $4);
1704 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1706 MYREPARSE (@4, $2, NOTENAME_PITCH, $4);
1708 } else if (scm_is_true (scm_call_1 ($2, $4)))
1710 MYREPARSE (@4, $2, PITCH_ARG, $4);
1713 $$ = scm_cons (loc_on_music (@3, $1), $3);
1714 MYBACKUP (NOTENAME_PITCH, $4, @4);
1717 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup TONICNAME_PITCH
1719 SCM m = make_music_from_simple (parser, @4, $4);
1720 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1722 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1724 } else if (scm_is_true (scm_call_1 ($2, $4)))
1726 MYREPARSE (@4, $2, PITCH_ARG, $4);
1729 $$ = scm_cons (loc_on_music (@3, $1), $3);
1730 MYBACKUP (TONICNAME_PITCH, $4, @4);
1733 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1735 if (scm_is_true (scm_call_1 ($2, $4)))
1737 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1740 $$ = scm_cons (loc_on_music (@3, $1), $3);
1741 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1744 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1746 SCM res = try_string_variants ($2, $4);
1747 if (!SCM_UNBNDP (res))
1748 if (scm_is_pair (res)) {
1750 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1753 $$ = scm_cons (res, $3);
1755 $$ = scm_cons (loc_on_music (@3, $1), $3);
1756 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1759 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1761 SCM res = try_string_variants ($2, $4);
1762 if (!SCM_UNBNDP (res))
1763 if (scm_is_pair (res)) {
1765 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1768 $$ = scm_cons (res, $3);
1770 $$ = scm_cons (loc_on_music (@3, $1), $3);
1771 MYBACKUP (STRING, $4, @4);
1774 | function_arglist_backup REPARSE music_assign
1776 if (scm_is_true (scm_call_1 ($2, $3)))
1777 $$ = scm_cons ($3, $1);
1779 $$ = check_scheme_arg (parser, @3,
1780 make_music_from_simple
1784 | function_arglist_backup REPARSE pitch_arg
1786 $$ = check_scheme_arg (parser, @3,
1789 | function_arglist_backup REPARSE bare_number_common
1791 $$ = check_scheme_arg (parser, @3,
1794 | function_arglist_backup REPARSE duration_length
1796 $$ = check_scheme_arg (parser, @3,
1799 | function_arglist_backup REPARSE symbol_list_arg
1801 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1806 function_arglist_nonbackup
1807 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1809 $$ = scm_cons (loc_on_music (@4, $1), $3);
1813 function_arglist_skip_nonbackup:
1814 function_arglist_nonbackup
1815 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1817 $$ = scm_cons (loc_on_music (@3, $1), $3);
1821 function_arglist_common:
1822 EXPECT_NO_MORE_ARGS {
1825 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1827 if (scm_is_true (scm_call_1 ($1, $3)))
1828 $$ = scm_cons ($3, $2);
1830 $$ = check_scheme_arg (parser, @3,
1831 make_music_from_simple
1835 | EXPECT_SCM function_arglist_optional bare_number_common
1837 $$ = check_scheme_arg (parser, @3,
1840 | EXPECT_SCM function_arglist_optional post_event_nofinger
1842 $$ = check_scheme_arg (parser, @3,
1845 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1847 SCM n = scm_difference ($4, SCM_UNDEFINED);
1848 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1850 | function_arglist_common_reparse REPARSE SCM_ARG
1852 $$ = check_scheme_arg (parser, @3,
1855 | function_arglist_common_reparse REPARSE lyric_element_music
1857 $$ = check_scheme_arg (parser, @3,
1860 | function_arglist_common_reparse REPARSE bare_number_common
1862 $$ = check_scheme_arg (parser, @3,
1865 | function_arglist_common_reparse REPARSE duration_length
1867 $$ = check_scheme_arg (parser, @3,
1870 | function_arglist_common_reparse REPARSE symbol_list_arg
1872 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1876 function_arglist_common_reparse:
1877 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1880 SCM res = try_string_variants ($1, $3);
1881 if (!SCM_UNBNDP (res))
1882 if (scm_is_pair (res))
1883 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1885 MYREPARSE (@3, $1, SCM_ARG, res);
1886 else if (scm_is_true
1888 ($1, make_music_from_simple (parser, @3, $3))))
1889 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1891 // This is going to flag a syntax error, we
1892 // know the predicate to be false.
1893 MYREPARSE (@3, $1, SCM_ARG, $3);
1895 | EXPECT_SCM function_arglist_optional STRING
1898 SCM res = try_string_variants ($1, $3);
1899 if (!SCM_UNBNDP (res))
1900 if (scm_is_pair (res))
1901 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1903 MYREPARSE (@3, $1, SCM_ARG, res);
1904 else if (scm_is_true
1906 ($1, make_music_from_simple (parser, @3, $3))))
1907 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1909 // This is going to flag a syntax error, we
1910 // know the predicate to be false.
1911 MYREPARSE (@3, $1, SCM_ARG, $3);
1913 | EXPECT_SCM function_arglist_optional full_markup
1916 if (scm_is_true (scm_call_1 ($1, $3)))
1917 MYREPARSE (@3, $1, SCM_ARG, $3);
1918 else if (scm_is_true
1920 ($1, make_music_from_simple (parser, @3, $3))))
1921 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1923 // This is going to flag a syntax error, we
1924 // know the predicate to be false.
1925 MYREPARSE (@3, $1, SCM_ARG, $3);
1927 | EXPECT_SCM function_arglist_optional UNSIGNED
1930 if (scm_is_true (scm_call_1 ($1, $3)))
1931 MYREPARSE (@3, $1, REAL, $3);
1933 SCM d = make_duration ($3);
1934 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
1935 MYREPARSE (@3, $1, REAL, $3);
1937 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
1940 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
1943 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
1945 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
1948 SCM n = scm_difference ($4, SCM_UNDEFINED);
1949 if (scm_is_true (scm_call_1 ($1, n)))
1950 MYREPARSE (@4, $1, REAL, n);
1952 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1953 t->set_property ("digit", $4);
1954 SCM m = t->unprotect ();
1955 if (scm_is_true (scm_call_1 ($1, m)))
1956 MYREPARSE (@4, $1, SCM_ARG, m);
1958 MYREPARSE (@4, $1, SCM_ARG, $4);
1962 | EXPECT_SCM function_arglist_optional '-' REAL
1965 SCM n = scm_difference ($4, SCM_UNDEFINED);
1966 MYREPARSE (@4, $1, REAL, n);
1970 function_arglist_closed:
1971 function_arglist_closed_nonbackup
1972 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1974 $$ = scm_cons (loc_on_music (@4, $1), $3);
1978 function_arglist_closed_common:
1979 EXPECT_NO_MORE_ARGS {
1982 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1984 $$ = check_scheme_arg (parser, @3,
1987 | EXPECT_SCM function_arglist_optional bare_number_common_closed
1989 $$ = check_scheme_arg (parser, @3,
1992 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1994 $$ = check_scheme_arg (parser, @3,
1995 scm_difference ($4, SCM_UNDEFINED),
1998 | EXPECT_SCM function_arglist_optional post_event_nofinger
2000 $$ = check_scheme_arg (parser, @3,
2003 | function_arglist_common_reparse REPARSE SCM_ARG
2005 $$ = check_scheme_arg (parser, @3,
2008 | function_arglist_common_reparse REPARSE bare_number_common_closed
2010 $$ = check_scheme_arg (parser, @3,
2013 | function_arglist_common_reparse REPARSE symbol_list_arg
2015 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2019 function_arglist_optional:
2020 function_arglist_backup
2021 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2023 $$ = scm_cons (loc_on_music (@4, $1), $3);
2025 | function_arglist_skip_backup BACKUP
2028 function_arglist_skip_backup:
2029 function_arglist_backup
2030 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2032 $$ = scm_cons (loc_on_music (@3, $1), $3);
2036 embedded_scm_closed:
2038 | scm_function_call_closed
2041 embedded_scm_arg_closed:
2042 embedded_scm_bare_arg
2043 | scm_function_call_closed
2047 scm_function_call_closed:
2048 SCM_FUNCTION function_arglist_closed {
2049 $$ = MAKE_SYNTAX ("music-function", @$,
2054 music_function_call:
2055 MUSIC_FUNCTION function_arglist {
2056 $$ = MAKE_SYNTAX ("music-function", @$,
2063 /**/ { $$ = SCM_EOL; }
2064 | '=' simple_string {
2071 | repeated_music { $$ = $1; }
2072 | re_rhythmed_music { $$ = $1; }
2073 | complex_music_prefix music
2075 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2079 complex_music_prefix:
2080 CONTEXT symbol optional_id optional_context_mod {
2081 Context_mod *ctxmod = unsmob_context_mod ($4);
2084 mods = ctxmod->get_mods ();
2085 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2087 | NEWCONTEXT symbol optional_id optional_context_mod {
2088 Context_mod *ctxmod = unsmob_context_mod ($4);
2091 mods = ctxmod->get_mods ();
2092 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2097 mode_changing_head grouped_music_list {
2098 if ($1 == ly_symbol2scm ("chords"))
2100 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2106 parser->lexer_->pop_state ();
2108 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2109 Context_mod *ctxmod = unsmob_context_mod ($2);
2112 mods = ctxmod->get_mods ();
2113 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2114 if ($1 == ly_symbol2scm ("ChordNames"))
2116 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2118 parser->lexer_->pop_state ();
2124 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2125 parser->lexer_->push_note_state (nn);
2127 $$ = ly_symbol2scm ("notes");
2131 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2132 parser->lexer_->push_note_state (nn);
2134 $$ = ly_symbol2scm ("drums");
2137 parser->lexer_->push_figuredbass_state ();
2139 $$ = ly_symbol2scm ("figures");
2142 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2143 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2144 nn = parser->lexer_->lookup_identifier ("pitchnames");
2145 parser->lexer_->push_chord_state (nn);
2146 $$ = ly_symbol2scm ("chords");
2150 { parser->lexer_->push_lyric_state ();
2151 $$ = ly_symbol2scm ("lyrics");
2155 mode_changing_head_with_context:
2157 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2158 parser->lexer_->push_note_state (nn);
2160 $$ = ly_symbol2scm ("DrumStaff");
2163 parser->lexer_->push_figuredbass_state ();
2165 $$ = ly_symbol2scm ("FiguredBass");
2168 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2169 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2170 nn = parser->lexer_->lookup_identifier ("pitchnames");
2171 parser->lexer_->push_chord_state (nn);
2172 $$ = ly_symbol2scm ("ChordNames");
2175 { parser->lexer_->push_lyric_state ();
2176 $$ = ly_symbol2scm ("Lyrics");
2181 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2184 /* Can also use music at the expensive of two S/Rs similar to
2185 \repeat \alternative */
2186 parser->lexer_->pop_state ();
2188 $$ = scm_cons ($3, SCM_EOL);
2190 | new_lyrics ADDLYRICS {
2191 parser->lexer_->push_lyric_state ();
2193 parser->lexer_->pop_state ();
2194 $$ = scm_cons ($4, $1);
2199 composite_music new_lyrics {
2200 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2202 | LYRICSTO simple_string {
2203 parser->lexer_->push_lyric_state ();
2205 parser->lexer_->pop_state ();
2206 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2211 CHANGE STRING '=' STRING {
2212 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
2219 $$ = scm_reverse_x ($1, SCM_EOL);
2221 | symbol_list_rev property_path {
2222 $$ = scm_reverse_x ($1, $2);
2228 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2231 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2233 | OVERRIDE property_path '=' scalar {
2234 if (scm_ilength ($2) < 2) {
2235 parser->parser_error (@2, _("bad grob property path"));
2238 $$ = scm_cons (ly_symbol2scm ("push"),
2239 scm_cons2 (scm_car ($2),
2244 | REVERT revert_arg {
2245 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2249 // This is all quite awkward for the sake of substantial backward
2250 // compatibility while at the same time allowing a more "natural" form
2251 // of specification not separating grob specification from grob
2252 // property path. The purpose of this definition of revert_arg is to
2253 // allow the symbol list which specifies grob and property to revert
2254 // to be optionally be split into two parts after the grob (which in
2255 // this case is just the first element of the list). symbol_list_part
2256 // is only one path component, but it can be parsed without lookahead,
2257 // so we can follow it with a synthetic BACKUP token when needed. If
2258 // the first symbol_list_part already contains multiple elements (only
2259 // possible if a Scheme expression provides them), we just parse for
2260 // additional elements introduced by '.', which is what the
2261 // SYMBOL_LIST backup in connection with the immediately following
2262 // rule using symbol_list_arg does.
2264 // As long as we don't have our coffers filled with both grob and at
2265 // least one grob property specification, the rest of the required
2266 // symbol list chain may be provided either with or without a leading
2267 // dot. This is for both allowing the traditional
2268 // \revert Accidental #'color
2269 // as well as well as the "naive" form
2270 // \revert Accidental.color
2273 revert_arg_backup BACKUP symbol_list_arg
2282 if (scm_is_null ($1)
2283 || scm_is_null (scm_cdr ($1)))
2284 MYBACKUP (SCM_ARG, $1, @1);
2286 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2290 // revert_arg_part delivers results in reverse
2293 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2295 $$ = scm_append_x (scm_list_2 ($5, $3));
2297 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2299 $$ = scm_append_x (scm_list_2 ($4, $3));
2304 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2305 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2307 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2308 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2309 | DENIES { $$ = ly_symbol2scm ("denies"); }
2311 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2312 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2313 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2314 | NAME { $$ = ly_symbol2scm ("context-name"); }
2318 property_operation { $$ = $1; }
2319 | context_def_mod STRING {
2320 $$ = scm_list_2 ($1, $2);
2322 | context_def_mod embedded_scm
2324 if (!scm_is_string ($2)
2325 && ly_symbol2scm ("consists") != $1
2326 && ly_symbol2scm ("remove") != $1)
2329 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2333 $$ = scm_list_2 ($1, $2);
2338 // If defined, at least two members.
2342 SCM l = scm_reverse_x ($1, SCM_EOL);
2345 (scm_object_property (scm_car (l),
2346 ly_symbol2scm ("is-grob?"))))
2347 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2348 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2349 parser->parser_error (@1, _ ("bad grob property path"));
2356 // If defined, at least three members
2360 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2362 parser->parser_error (@1, _ ("bad grob property path"));
2366 | grob_prop_spec property_path
2368 if (!SCM_UNBNDP ($1)) {
2369 $$ = scm_append_x (scm_list_2 ($1, $2));
2370 if (scm_is_null (scm_cddr ($$))) {
2371 parser->parser_error (@$, _ ("bad grob property path"));
2379 // Exactly two elements or undefined
2383 SCM l = scm_reverse_x ($1, SCM_EOL);
2384 switch (scm_ilength (l)) {
2386 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2390 parser->parser_error (@1, _ ("bad context property path"));
2397 simple_music_property_def:
2398 OVERRIDE grob_prop_path '=' scalar {
2399 if (SCM_UNBNDP ($2))
2402 $$ = scm_list_5 (scm_car ($2),
2403 ly_symbol2scm ("OverrideProperty"),
2409 | REVERT simple_revert_context revert_arg {
2410 $$ = scm_list_4 ($2,
2411 ly_symbol2scm ("RevertProperty"),
2415 | SET context_prop_spec '=' scalar {
2416 if (SCM_UNBNDP ($2))
2419 $$ = scm_list_4 (scm_car ($2),
2420 ly_symbol2scm ("PropertySet"),
2424 | UNSET context_prop_spec {
2425 if (SCM_UNBNDP ($2))
2428 $$ = scm_list_3 (scm_car ($2),
2429 ly_symbol2scm ("PropertyUnset"),
2435 // This is all quite awkward for the sake of substantial backward
2436 // compatibility while at the same time allowing a more "natural" form
2437 // of specification not separating grob specification from grob
2438 // property path. The purpose of this definition of
2439 // simple_revert_context is to allow the symbol list which specifies
2440 // grob and property to revert to be optionally be split into two
2441 // parts after the grob (which may be preceded by a context
2442 // specification, a case which we distinguish by checking whether the
2443 // first symbol is a valid grob symbol instead).
2445 // See revert_arg above for the main work horse of this arrangement.
2446 // simple_revert_context just caters for the context and delegates the
2447 // rest of the job to revert_arg.
2449 simple_revert_context:
2452 $1 = scm_reverse_x ($1, SCM_EOL);
2453 if (scm_is_null ($1)
2455 (scm_object_property (scm_car ($1),
2456 ly_symbol2scm ("is-grob?")))) {
2457 $$ = ly_symbol2scm ("Bottom");
2458 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2461 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2468 simple_music_property_def {
2469 if (SCM_UNBNDP ($1))
2470 $$ = MAKE_SYNTAX ("void-music", @1);
2472 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2483 simple_string: STRING {
2488 if (scm_is_string ($1)) {
2491 parser->parser_error (@1, (_ ("simple string expected")));
2492 $$ = scm_string (SCM_EOL);
2499 $$ = scm_string_to_symbol ($1);
2503 // This is a bit of overkill but makes the same
2504 // routine responsible for all symbol interpretations.
2505 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2507 if (SCM_UNBNDP ($$))
2509 parser->parser_error (@1, (_ ("symbol expected")));
2510 // Generate a unique symbol in case it is used
2511 // for an assignment or similar
2512 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2521 // The following is a rather defensive variant of admitting
2522 // negative numbers: the grammar would permit number_factor or
2523 // even number_expression. However, function arguments allow
2524 // only this simple kind of negative number, so to have things
2525 // like \tweak and \override behave reasonably similar, it
2526 // makes sense to rule out things like -- which are rather an
2527 // accent in function argument contexts.
2530 $$ = scm_difference ($2, SCM_UNDEFINED);
2537 simple_element post_events {
2538 // Let the rhythmic music iterator sort this mess out.
2539 if (scm_is_pair ($2)) {
2540 $$ = make_music_from_simple (parser, @1, $1);
2541 if (unsmob_music ($$))
2542 unsmob_music ($$)->set_property ("articulations",
2543 scm_reverse_x ($2, SCM_EOL));
2546 parser->parser_error (@1, _("music expected"));
2547 $$ = MAKE_SYNTAX ("void-music", @1);
2551 | simple_chord_elements post_events {
2552 if (scm_is_pair ($2)) {
2553 if (unsmob_pitch ($1))
2554 $1 = make_chord_elements (@1,
2556 parser->default_duration_.smobbed_copy (),
2559 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2561 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
2562 } else if (!unsmob_pitch ($1))
2563 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
2564 // A mere pitch drops through.
2566 | CHORD_REPETITION optional_notemode_duration post_events {
2568 i.set_location (@1, @3);
2569 $$ = MAKE_SYNTAX ("repetition-chord", i,
2570 $2, scm_reverse_x ($3, SCM_EOL));
2572 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2574 i.set_location (@1, @3);
2575 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2576 scm_reverse_x ($3, SCM_EOL));
2579 | note_chord_element
2584 chord_body optional_notemode_duration post_events
2586 Music *m = unsmob_music ($1);
2587 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2588 SCM es = m->get_property ("elements");
2589 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2591 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2592 unsmob_music (scm_car (s))->set_property ("duration", dur);
2593 es = ly_append2 (es, postevs);
2595 m-> set_property ("elements", es);
2597 $$ = m->self_scm ();
2602 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2604 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2606 | CHORD_BODY_IDENTIFIER
2609 chord_body_elements:
2610 /* empty */ { $$ = SCM_EOL; }
2611 | chord_body_elements chord_body_element {
2612 if (!SCM_UNBNDP ($2))
2613 $$ = scm_cons ($2, $1);
2618 pitch exclamations questions octave_check post_events
2620 bool q = to_boolean ($3);
2621 bool ex = to_boolean ($2);
2625 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2626 n->set_property ("pitch", $1);
2628 n->set_property ("cautionary", SCM_BOOL_T);
2630 n->set_property ("force-accidental", SCM_BOOL_T);
2632 if (scm_is_pair (post)) {
2633 SCM arts = scm_reverse_x (post, SCM_EOL);
2634 n->set_property ("articulations", arts);
2636 if (scm_is_number (check))
2638 int q = scm_to_int (check);
2639 n->set_property ("absolute-octave", scm_from_int (q-1));
2642 $$ = n->unprotect ();
2644 | DRUM_PITCH post_events {
2645 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2646 n->set_property ("drum-type", $1);
2648 if (scm_is_pair ($2)) {
2649 SCM arts = scm_reverse_x ($2, SCM_EOL);
2650 n->set_property ("articulations", arts);
2652 $$ = n->unprotect ();
2654 | music_function_chord_body
2656 Music *m = unsmob_music ($1);
2658 while (m && m->is_mus_type ("music-wrapper-music")) {
2659 $$ = m->get_property ("element");
2660 m = unsmob_music ($$);
2663 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2664 parser->parser_error (@$, _ ("not a rhythmic event"));
2670 music_function_chord_body:
2675 // Event functions may only take closed arglists, otherwise it would
2676 // not be clear whether a following postevent should be associated
2677 // with the last argument of the event function or with the expression
2678 // for which the function call acts itself as event.
2680 music_function_call_closed:
2681 MUSIC_FUNCTION function_arglist_closed {
2682 $$ = MAKE_SYNTAX ("music-function", @$,
2687 event_function_event:
2688 EVENT_FUNCTION function_arglist_closed {
2689 $$ = MAKE_SYNTAX ("music-function", @$,
2711 | post_events post_event {
2713 if (Music *m = unsmob_music ($2))
2715 if (m->is_mus_type ("post-event-wrapper"))
2717 for (SCM p = m->get_property ("elements");
2721 $$ = scm_cons (scm_car (p), $$);
2725 $$ = scm_cons ($2, $$);
2731 post_event_nofinger:
2732 direction_less_event {
2735 | script_dir music_function_call_closed {
2737 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2738 parser->parser_error (@2, _ ("post-event expected"));
2739 $$ = SCM_UNSPECIFIED;
2740 } else if (!SCM_UNBNDP ($1))
2742 unsmob_music ($$)->set_property ("direction", $1);
2746 if (!parser->lexer_->is_lyric_state ())
2747 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2748 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2751 if (!parser->lexer_->is_lyric_state ())
2752 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2753 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2755 | script_dir direction_reqd_event {
2756 if (!SCM_UNBNDP ($1))
2758 Music *m = unsmob_music ($2);
2759 m->set_property ("direction", $1);
2763 | script_dir direction_less_event {
2764 if (!SCM_UNBNDP ($1))
2766 Music *m = unsmob_music ($2);
2767 m->set_property ("direction", $1);
2774 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2779 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2790 string_number_event:
2792 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2793 s->set_property ("string-number", $1);
2794 $$ = s->unprotect ();
2798 direction_less_event:
2800 | EVENT_IDENTIFIER {
2804 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2805 a->set_property ("tremolo-type", $1);
2806 $$ = a->unprotect ();
2808 | event_function_event
2811 direction_reqd_event:
2815 | script_abbreviation {
2816 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2817 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2818 if (scm_is_string (s))
2819 a->set_property ("articulation-type", s);
2820 else parser->parser_error (@1, _ ("expecting string as script definition"));
2821 $$ = a->unprotect ();
2826 /**/ { $$ = SCM_EOL; }
2827 | '=' quotes { $$ = $2; }
2841 $$ = scm_from_int (1);
2844 $$ = scm_oneplus ($1);
2850 $$ = scm_from_int (-1);
2853 $$ = scm_oneminus ($1);
2858 NOTENAME_PITCH quotes {
2859 if (!scm_is_eq (SCM_INUM0, $2))
2861 Pitch p = *unsmob_pitch ($1);
2862 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2863 $$ = p.smobbed_copy ();
2873 TONICNAME_PITCH quotes {
2874 if (!scm_is_eq (SCM_INUM0, $2))
2876 Pitch p = *unsmob_pitch ($1);
2877 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2878 $$ = p.smobbed_copy ();
2885 | PITCH_IDENTIFIER quotes {
2886 if (!scm_is_eq (SCM_INUM0, $2))
2888 Pitch p = *unsmob_pitch ($1);
2889 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2890 $$ = p.smobbed_copy ();
2897 if (!scm_is_eq (SCM_INUM0, $2))
2899 Pitch p = *unsmob_pitch ($1);
2900 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2901 $$ = p.smobbed_copy ();
2908 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2909 t->set_property ("text", $1);
2910 $$ = t->unprotect ();
2913 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2914 t->set_property ("text",
2915 make_simple_markup ($1));
2916 $$ = t->unprotect ();
2918 | embedded_scm_closed
2920 Music *m = unsmob_music ($1);
2921 if (m && m->is_mus_type ("post-event"))
2923 else if (Text_interface::is_markup ($1)) {
2924 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2925 t->set_property ("text", $1);
2926 $$ = t->unprotect ();
2928 parser->parser_error (@1, _ ("not an articulation"));
2934 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2935 t->set_property ("digit", $1);
2936 $$ = t->unprotect ();
2940 script_abbreviation:
2942 $$ = scm_from_locale_string ("Hat");
2945 $$ = scm_from_locale_string ("Plus");
2948 $$ = scm_from_locale_string ("Dash");
2951 $$ = scm_from_locale_string ("Bang");
2954 $$ = scm_from_locale_string ("Larger");
2957 $$ = scm_from_locale_string ("Dot");
2960 $$ = scm_from_locale_string ("Underscore");
2965 '_' { $$ = scm_from_int (DOWN); }
2966 | '^' { $$ = scm_from_int (UP); }
2967 | '-' { $$ = SCM_UNDEFINED; }
2971 multiplied_duration {
2976 maybe_notemode_duration:
2980 | multiplied_duration {
2982 parser->default_duration_ = *unsmob_duration ($$);
2987 optional_notemode_duration:
2988 maybe_notemode_duration
2990 if (SCM_UNBNDP ($$))
2991 $$ = parser->default_duration_.smobbed_copy ();
2997 $$ = make_duration ($1, scm_to_int ($2));
2998 if (SCM_UNBNDP ($$))
3000 parser->parser_error (@1, _ ("not a duration"));
3001 $$ = Duration ().smobbed_copy ();
3004 | DURATION_IDENTIFIER dots {
3005 Duration *d = unsmob_duration ($1);
3006 Duration k (d->duration_log (),
3007 d->dot_count () + scm_to_int ($2));
3008 k = k.compressed (d->factor ());
3009 scm_remember_upto_here_1 ($1);
3010 $$ = k.smobbed_copy ();
3014 multiplied_duration:
3018 | multiplied_duration '*' UNSIGNED {
3019 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
3021 | multiplied_duration '*' FRACTION {
3022 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
3024 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
3033 $$ = scm_oneplus ($1);
3042 if (SCM_UNBNDP (make_duration ($2)))
3043 parser->parser_error (@2, _ ("not a duration"));
3049 UNSIGNED { $$ = $1; }
3050 | STRING { $$ = $1; }
3051 | full_markup { $$ = $1; }
3054 // as an integer, it needs to be non-negative, and otherwise
3055 // it needs to be suitable as a markup.
3056 if (scm_is_integer ($1)
3057 ? scm_is_true (scm_negative_p ($1))
3058 : !Text_interface::is_markup ($1))
3060 parser->parser_error (@1, _ ("bass number expected"));
3066 figured_bass_alteration:
3067 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3068 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3069 | '!' { $$ = scm_from_int (0); }
3074 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3075 $$ = bfr->unprotect ();
3078 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3079 $$ = bfr->self_scm ();
3081 if (scm_is_number ($1))
3082 bfr->set_property ("figure", $1);
3083 else if (Text_interface::is_markup ($1))
3084 bfr->set_property ("text", $1);
3090 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3092 | bass_figure figured_bass_alteration {
3093 Music *m = unsmob_music ($1);
3094 if (scm_to_double ($2)) {
3095 SCM salter = m->get_property ("alteration");
3096 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3097 m->set_property ("alteration",
3098 scm_sum (alter, $2));
3100 m->set_property ("alteration", scm_from_int (0));
3103 | bass_figure figured_bass_modification {
3104 Music *m = unsmob_music ($1);
3105 m->set_property ($2, SCM_BOOL_T);
3110 figured_bass_modification:
3112 $$ = ly_symbol2scm ("augmented");
3115 $$ = ly_symbol2scm ("no-continuation");
3118 $$ = ly_symbol2scm ("diminished");
3121 $$ = ly_symbol2scm ("augmented-slash");
3131 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3139 | figure_list br_bass_figure {
3140 $$ = scm_cons ($2, $1);
3145 FIGURE_OPEN figure_list FIGURE_CLOSE {
3146 $$ = scm_reverse_x ($2, SCM_EOL);
3152 /**/ { $$ = SCM_BOOL_F; }
3153 | REST { $$ = SCM_BOOL_T; }
3157 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3158 if (!parser->lexer_->is_note_state ())
3159 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3160 if (!SCM_UNBNDP ($2)
3162 || scm_is_number ($4)
3164 || scm_is_true ($6))
3167 if (scm_is_true ($6))
3168 n = MY_MAKE_MUSIC ("RestEvent", @$);
3170 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3172 n->set_property ("pitch", $1);
3173 if (SCM_UNBNDP ($5))
3174 n->set_property ("duration",
3175 parser->default_duration_.smobbed_copy ());
3177 n->set_property ("duration", $5);
3179 if (scm_is_number ($4))
3181 int q = scm_to_int ($4);
3182 n->set_property ("absolute-octave", scm_from_int (q-1));
3185 if (to_boolean ($3))
3186 n->set_property ("cautionary", SCM_BOOL_T);
3187 if (to_boolean ($2) || to_boolean ($3))
3188 n->set_property ("force-accidental", SCM_BOOL_T);
3190 $$ = n->unprotect ();
3193 | DRUM_PITCH optional_notemode_duration {
3194 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3195 n->set_property ("duration", $2);
3196 n->set_property ("drum-type", $1);
3198 $$ = n->unprotect ();
3200 | RESTNAME optional_notemode_duration {
3202 if (ly_scm2string ($1) == "s") {
3204 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3207 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3210 ev->set_property ("duration", $2);
3211 $$ = ev->unprotect ();
3215 // Can return a single pitch rather than a list.
3216 simple_chord_elements:
3218 if (!parser->lexer_->is_chord_state ())
3219 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3222 | figure_spec optional_notemode_duration {
3223 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3225 unsmob_music (scm_car (s))->set_property ("duration", $2);
3233 if (!parser->lexer_->is_lyric_state ())
3234 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3238 if (!parser->lexer_->is_lyric_state ())
3239 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3245 lyric_element_music:
3246 lyric_element optional_notemode_duration post_events {
3247 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3248 if (scm_is_pair ($3))
3249 unsmob_music ($$)->set_property
3250 ("articulations", scm_reverse_x ($3, SCM_EOL));
3254 // Can return a single pitch rather than a list.
3256 steno_tonic_pitch maybe_notemode_duration {
3257 if (SCM_UNBNDP ($2))
3260 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3262 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3263 SCM its = scm_reverse_x ($4, SCM_EOL);
3264 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3272 | chord_items chord_item {
3273 $$ = scm_cons ($2, $$);
3279 $$ = ly_symbol2scm ("chord-colon");
3282 $$ = ly_symbol2scm ("chord-caret");
3284 | CHORD_SLASH steno_tonic_pitch {
3285 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3287 | CHORD_BASS steno_tonic_pitch {
3288 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3297 $$ = scm_reverse_x ($1, SCM_EOL);
3305 step_number { $$ = scm_cons ($1, SCM_EOL); }
3306 | step_numbers '.' step_number {
3307 $$ = scm_cons ($3, $$);
3313 $$ = make_chord_step ($1, 0);
3316 $$ = make_chord_step ($1, SHARP_ALTERATION);
3318 | UNSIGNED CHORD_MINUS {
3319 $$ = make_chord_step ($1, FLAT_ALTERATION);
3327 | unsigned_number '-' unsigned_number {
3328 $$ = scm_cons ($1, $3);
3335 TODO: should deprecate in favor of Scheme?
3339 number_expression '+' number_term {
3340 $$ = scm_sum ($1, $3);
3342 | number_expression '-' number_term {
3343 $$ = scm_difference ($1, $3);
3352 | number_factor '*' number_factor {
3353 $$ = scm_product ($1, $3);
3355 | number_factor '/' number_factor {
3356 $$ = scm_divide ($1, $3);
3361 '-' number_factor { /* %prec UNARY_MINUS */
3362 $$ = scm_difference ($2, SCM_UNDEFINED);
3368 bare_number_common_closed
3369 | REAL NUMBER_IDENTIFIER
3371 $$ = scm_product ($1, $2);
3375 bare_number_common_closed:
3383 | UNSIGNED NUMBER_IDENTIFIER {
3384 $$ = scm_product ($1, $2);
3390 | bare_number_common_closed
3397 if (!scm_is_integer ($1)
3398 || scm_is_true (scm_negative_p ($1)))
3400 parser->parser_error (@1, _("not an unsigned integer"));
3406 if (!scm_is_integer ($1)
3407 || scm_is_true (scm_negative_p ($1)))
3409 parser->parser_error (@1, _("not an unsigned integer"));
3416 { $$ = SCM_UNDEFINED; }
3419 if (SCM_UNBNDP ($1))
3427 { $$ = SCM_UNDEFINED; }
3430 if (SCM_UNBNDP ($1))
3439 { parser->lexer_->push_markup_state (); }
3442 parser->lexer_->pop_state ();
3448 { parser->lexer_->push_markup_state (); }
3451 parser->lexer_->pop_state ();
3457 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3459 | markup_head_1_list simple_markup
3461 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3462 @2, $1, scm_list_1 ($2)));
3472 if (Text_interface::is_markup ($1))
3473 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3474 else if (Text_interface::is_markup_list ($1))
3475 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3477 parser->parser_error (@1, _ ("not a markup"));
3478 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3485 markup_composed_list {
3488 | markup_uncomposed_list
3491 markup_uncomposed_list:
3492 markup_braced_list {
3495 | markup_command_list {
3496 $$ = scm_list_1 ($1);
3498 | markup_scm MARKUPLIST_IDENTIFIER
3503 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3504 parser->lexer_->push_note_state (nn);
3505 } '{' score_body '}' {
3506 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3507 parser->lexer_->pop_state ();
3511 markup_composed_list:
3512 markup_head_1_list markup_uncomposed_list {
3513 $$ = MAKE_SYNTAX ("composed-markup-list",
3519 '{' markup_braced_list_body '}' {
3520 $$ = scm_reverse_x ($2, SCM_EOL);
3524 markup_braced_list_body:
3525 /* empty */ { $$ = SCM_EOL; }
3526 | markup_braced_list_body markup {
3527 $$ = scm_cons ($2, $1);
3529 | markup_braced_list_body markup_list {
3530 $$ = scm_reverse_x ($2, $1);
3534 markup_command_list:
3535 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3536 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3540 markup_command_basic_arguments:
3541 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3542 $$ = scm_cons ($3, $2);
3544 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3545 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3547 | EXPECT_NO_MORE_ARGS {
3552 markup_command_list_arguments:
3553 markup_command_basic_arguments { $$ = $1; }
3554 | EXPECT_MARKUP markup_command_list_arguments markup {
3555 $$ = scm_cons ($3, $2);
3560 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3561 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3566 markup_head_1_item {
3567 $$ = scm_list_1 ($1);
3569 | markup_head_1_list markup_head_1_item {
3570 $$ = scm_cons ($2, $1);
3576 $$ = make_simple_markup ($1);
3579 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3580 parser->lexer_->push_note_state (nn);
3581 } '{' score_body '}' {
3582 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3583 parser->lexer_->pop_state ();
3585 | MARKUP_FUNCTION markup_command_basic_arguments {
3586 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3588 | markup_scm MARKUP_IDENTIFIER
3595 markup_head_1_list simple_markup
3597 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3598 @2, $1, scm_list_1 ($2)));
3608 Lily_parser::set_yydebug (bool x)
3614 Lily_parser::do_yyparse ()
3616 SCM retval = SCM_UNDEFINED;
3617 yyparse (this, &retval);
3627 It is a little strange to have this function in this file, but
3628 otherwise, we have to import music classes into the lexer.
3632 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3634 if (unsmob_book (sid)) {
3635 Book *book = unsmob_book (sid)->clone ();
3636 *destination = book->self_scm ();
3639 return BOOK_IDENTIFIER;
3640 } else if (scm_is_number (sid)) {
3642 return NUMBER_IDENTIFIER;
3643 } else if (unsmob_context_def (sid)) {
3644 Context_def *def= unsmob_context_def (sid)->clone ();
3646 *destination = def->self_scm ();
3649 return CONTEXT_DEF_IDENTIFIER;
3650 } else if (unsmob_context_mod (sid)) {
3651 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3653 return CONTEXT_MOD_IDENTIFIER;
3654 } else if (Music *mus = unsmob_music (sid)) {
3655 mus = mus->clone ();
3656 *destination = mus->self_scm ();
3657 bool is_event = mus->is_mus_type ("post-event");
3659 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3660 } else if (unsmob_pitch (sid)) {
3661 *destination = unsmob_pitch (sid)->smobbed_copy ();
3662 return PITCH_IDENTIFIER;
3663 } else if (unsmob_duration (sid)) {
3664 *destination = unsmob_duration (sid)->smobbed_copy ();
3665 return DURATION_IDENTIFIER;
3666 } else if (unsmob_output_def (sid)) {
3667 Output_def *p = unsmob_output_def (sid);
3670 *destination = p->self_scm ();
3672 return OUTPUT_DEF_IDENTIFIER;
3679 get_next_unique_context_id ()
3681 return scm_from_locale_string ("$uniqueContextId");
3686 get_next_unique_lyrics_context_id ()
3688 static int new_context_count;
3690 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3691 return scm_from_locale_string (s);
3694 // check_scheme_arg checks one argument with a given predicate for use
3695 // in an argument list and throws a syntax error if it is unusable.
3696 // The argument is prepended to the argument list in any case. After
3697 // throwing a syntax error, the argument list is terminated with #f as
3698 // its last cdr in order to mark it as uncallable while not losing
3699 // track of its total length.
3701 // There are a few special considerations: if optional argument disp
3702 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3703 // instead of arg in a prospective error message. This is useful if
3704 // arg is not the actual argument but rather a transformation of it.
3706 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3707 // and an error message using disp is produced unconditionally.
3709 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3710 SCM arg, SCM args, SCM pred, SCM disp)
3712 if (SCM_UNBNDP (arg))
3713 args = scm_cons (disp, args);
3715 args = scm_cons (arg, args);
3716 if (scm_is_true (scm_call_1 (pred, arg)))
3719 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3720 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3721 SCM_UNBNDP (disp) ? arg : disp);
3722 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3726 SCM loc_on_music (Input loc, SCM arg)
3728 if (Music *m = unsmob_music (arg))
3732 return m->unprotect ();
3738 try_string_variants (SCM pred, SCM str)
3740 // a matching predicate is always ok
3741 if (scm_is_true (scm_call_1 (pred, str)))
3743 // a symbol may be interpreted as a list of symbols if it helps
3744 if (scm_is_symbol (str)) {
3745 str = scm_list_1 (str);
3746 if (scm_is_true (scm_call_1 (pred, str)))
3748 return SCM_UNDEFINED;
3751 // If this cannot be a string representation of a symbol list,
3754 if (!is_regular_identifier (str, true))
3755 return SCM_UNDEFINED;
3757 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3758 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3759 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3761 // Let's attempt the symbol list interpretation first.
3763 if (scm_is_true (scm_call_1 (pred, str)))
3766 // If there is just one symbol in the list, we might interpret
3767 // it as a single symbol
3769 if (scm_is_null (scm_cdr (str)))
3771 str = scm_car (str);
3772 if (scm_is_true (scm_call_1 (pred, str)))
3776 return SCM_UNDEFINED;
3780 is_regular_identifier (SCM id, bool multiple)
3782 if (!scm_is_string (id))
3785 string str = ly_scm2string (id);
3787 bool middle = false;
3789 for (string::iterator it=str.begin(); it != str.end (); it++)
3792 if ((c >= 'a' && c <= 'z')
3793 || (c >= 'A' && c <= 'Z')
3796 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3805 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3807 if (unsmob_music (simple))
3809 if (parser->lexer_->is_note_state ()) {
3810 if (scm_is_symbol (simple)) {
3811 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3812 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3813 n->set_property ("drum-type", simple);
3814 return n->unprotect ();
3816 if (unsmob_pitch (simple)) {
3817 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3818 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3819 n->set_property ("pitch", simple);
3820 return n->unprotect ();
3823 } else if (parser->lexer_->is_lyric_state ()) {
3824 if (Text_interface::is_markup (simple))
3825 return MAKE_SYNTAX ("lyric-event", loc, simple,
3826 parser->default_duration_.smobbed_copy ());
3827 } else if (parser->lexer_->is_chord_state ()) {
3828 if (unsmob_pitch (simple))
3832 make_chord_elements (loc, simple,
3833 parser->default_duration_.smobbed_copy (),
3840 make_music_with_input (SCM name, Input where)
3842 Music *m = make_music_by_name (name);
3843 m->set_spot (where);
3848 make_simple_markup (SCM a)
3854 make_duration (SCM d, int dots)
3856 int t = scm_to_int (d);
3857 if (t > 0 && (t & (t-1)) == 0)
3858 return Duration (intlog2 (t), dots).smobbed_copy ();
3860 return SCM_UNDEFINED;
3864 make_chord_step (SCM step_scm, Rational alter)
3866 int step = scm_to_int (step_scm);
3869 alter += FLAT_ALTERATION;
3873 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3874 return m.smobbed_copy ();
3879 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3881 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3882 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3883 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3885 unsmob_music (scm_car (s))->set_spot (loc);
3891 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3893 Lily_lexer *lex = parser->lexer_;
3897 lex->prepare_for_next_token ();
3898 return lex->yylex ();