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 '}' {
888 if (!scm_is_pair ($1)
889 || !ly_is_module (scm_car ($1)))
890 $1 = scm_cons (ly_make_module (false), $1);
891 parser->lexer_->add_scope (scm_car ($1));
896 | score_headers output_def
898 Output_def *od = unsmob_output_def ($2);
899 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
901 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
906 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
907 scm_set_cdr_x ($1, scm_cons ($2, scm_cdr ($1)));
909 $$ = scm_cons ($2, $1);
917 score_headers music {
918 SCM scorify = ly_lily_module_constant ("scorify-music");
919 $$ = scm_call_2 (scorify, $2, parser->self_scm ());
921 unsmob_score ($$)->origin ()->set_spot (@2);
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 {
936 if (unsmob_score ($1))
937 score = new Score (*unsmob_score ($1));
940 parser->parser_error (@1, _("score expected"));
942 unsmob_score ($$)->origin ()->set_spot (@$);
943 $$ = score->unprotect ();
947 Score *score = unsmob_score ($1);
948 if (!ly_is_module (score->get_header ()))
949 score->set_header (ly_make_module (false));
950 parser->lexer_->add_scope (score->get_header ());
952 | score_body output_def {
953 Output_def *od = unsmob_output_def ($2);
954 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
956 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
961 unsmob_score ($1)->add_output_def (od);
965 unsmob_score ($$)->error_found_ = true;
976 Output_def *od = unsmob_output_def ($1);
978 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
980 parser->parser_error (@1, _ ("need \\paper for paper block"));
981 $$ = get_paper (parser)->unprotect ();
988 output_def_body '}' {
991 parser->lexer_->remove_scope ();
992 parser->lexer_->pop_state ();
998 Output_def *p = get_paper (parser);
999 p->input_origin_ = @$;
1000 parser->lexer_->add_scope (p->scope_);
1001 $$ = p->unprotect ();
1004 Output_def *p = get_midi (parser);
1005 $$ = p->unprotect ();
1006 parser->lexer_->add_scope (p->scope_);
1009 Output_def *p = get_layout (parser);
1011 parser->lexer_->add_scope (p->scope_);
1012 $$ = p->unprotect ();
1016 output_def_head_with_mode_switch:
1018 parser->lexer_->push_initial_state ();
1023 // We need this weird nonterminal because both music as well as a
1024 // context definition can start with \context and the difference is
1025 // only apparent after looking at the next token. If it is '{', there
1026 // is still time to escape from notes mode.
1028 music_or_context_def:
1030 | context_def_spec_block
1034 output_def_head_with_mode_switch '{' {
1036 unsmob_output_def ($$)->input_origin_.set_spot (@$);
1038 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1039 Output_def *o = unsmob_output_def ($3);
1040 o->input_origin_.set_spot (@$);
1041 $$ = o->self_scm ();
1042 parser->lexer_->remove_scope ();
1043 parser->lexer_->add_scope (o->scope_);
1045 | output_def_body assignment {
1048 | output_def_body embedded_scm {
1053 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1054 parser->lexer_->push_note_state (nn);
1055 } music_or_context_def
1057 parser->lexer_->pop_state ();
1058 if (unsmob_context_def ($3))
1059 assign_context_def (unsmob_output_def ($1), $3);
1062 SCM proc = parser->lexer_->lookup_identifier
1063 ("output-def-music-handler");
1064 scm_call_3 (proc, parser->self_scm (),
1068 | output_def_body error {
1074 TEMPO steno_duration '=' tempo_range {
1075 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1077 | TEMPO scalar steno_duration '=' tempo_range {
1078 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1081 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1086 The representation of a list is reversed to have efficient append. */
1092 | music_list music_embedded {
1093 if (unsmob_music ($2))
1094 $$ = scm_cons ($2, $1);
1096 | music_list error {
1097 Music *m = MY_MAKE_MUSIC("Music", @$);
1099 m->set_property ("error-found", SCM_BOOL_T);
1100 $$ = scm_cons (m->self_scm (), $1);
1101 m->unprotect (); /* UGH */
1108 $$ = scm_reverse_x ($2, SCM_EOL);
1113 | lyric_element_music
1119 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1120 parser->parser_error (@1, _ ("unexpected post-event"));
1121 $$ = SCM_UNSPECIFIED;
1124 | music_embedded_backup
1128 | music_embedded_backup BACKUP lyric_element_music
1132 | multiplied_duration post_events
1134 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1136 parser->default_duration_ = *unsmob_duration ($1);
1137 n->set_property ("duration", $1);
1139 if (scm_is_pair ($2))
1140 n->set_property ("articulations",
1141 scm_reverse_x ($2, SCM_EOL));
1142 $$ = n->unprotect ();
1146 music_embedded_backup:
1149 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1151 else if (Music *m = unsmob_music ($1)) {
1152 if (m->is_mus_type ("post-event")) {
1153 parser->parser_error
1154 (@1, _ ("unexpected post-event"));
1155 $$ = SCM_UNSPECIFIED;
1158 } else if (parser->lexer_->is_lyric_state ()
1159 && Text_interface::is_markup ($1))
1160 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1162 @$.warning (_ ("Ignoring non-music expression"));
1171 $$ = make_music_from_simple (parser, @1, $1);
1172 if (!unsmob_music ($$))
1174 parser->parser_error (@1, _ ("music expected"));
1175 $$ = MAKE_SYNTAX ("void-music", @$);
1178 | composite_music %prec COMPOSITE
1183 | composite_music %prec COMPOSITE
1187 REPEAT simple_string unsigned_number music
1189 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1191 | REPEAT_IDENTIFIER music
1193 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1196 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1198 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1200 | REPEAT_IDENTIFIER music ALTERNATIVE braced_music_list
1202 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1208 SEQUENTIAL braced_music_list {
1209 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1211 | braced_music_list {
1212 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1217 SIMULTANEOUS braced_music_list {
1218 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1220 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1221 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1227 | music_property_def
1231 context_modification:
1234 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1235 parser->lexer_->push_note_state (nn);
1236 } '{' context_mod_list '}'
1238 parser->lexer_->pop_state ();
1241 | WITH CONTEXT_MOD_IDENTIFIER
1245 | CONTEXT_MOD_IDENTIFIER
1249 | WITH context_modification_arg
1251 if (unsmob_music ($2)) {
1252 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1253 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1255 if (unsmob_context_mod ($2))
1258 parser->parser_error (@2, _ ("not a context mod"));
1259 $$ = Context_mod ().smobbed_copy ();
1264 context_modification_arg:
1269 optional_context_mod:
1273 | context_modification
1281 $$ = Context_mod ().smobbed_copy ();
1283 | context_mod_list context_mod {
1284 if (!SCM_UNBNDP ($2))
1285 unsmob_context_mod ($1)->add_context_mod ($2);
1287 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1288 Context_mod *md = unsmob_context_mod ($2);
1290 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1292 | context_mod_list context_mod_embedded {
1293 unsmob_context_mod ($1)->add_context_mods
1294 (unsmob_context_mod ($2)->get_mods ());
1303 /* Music that can be parsed without lookahead */
1306 | complex_music_prefix closed_music
1308 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1310 | music_function_call_closed
1316 | grouped_music_list
1320 simultaneous_music { $$ = $1; }
1321 | sequential_music { $$ = $1; }
1324 /* Function argument lists are arguably the most complex part in the
1325 * parser. They are pretty tricky to understand because of the way
1326 * they are processed, and because of optional arguments that can be
1327 * omitted. When there are several optional arguments in a row,
1328 * omitting one automatically omits all following arguments. Optional
1329 * arguments can only be omitted when either
1331 * a) the omission is explicitly started with \default
1332 * b) the omission is implicitly started by an argument not matching
1333 * its predicate, and there is a mandatory argument later that can
1334 * "catch" the argument that does not fit.
1336 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1337 * (corresponding to mandatory arguments and having a predicate
1338 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1339 * the semantic value of the EXPECT_OPTIONAL token is the default to
1340 * use when the optional argument is omitted, and EXPECT_SCM again has
1341 * the argument predicate as semantic value) in reverse order to the
1342 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1343 * processed inside-out while actual tokens are consumed.
1345 * This means that the argument list tokens determine the actions
1346 * taken as they arrive. The structure of the argument list is known
1347 * to the parser and stored in its parse stack when the first argument
1348 * is being parsed. What the parser does not know is which predicates
1349 * will match and whether or not \default will be appearing in the
1350 * argument list, and where.
1352 * Many of the basic nonterminals used for argument list scanning come
1353 * in a "normal" and a "closed" flavor. A closed expression is one
1354 * that can be parsed without a lookahead token. That makes it
1355 * feasible for an optional argument that may need to be skipped:
1356 * skipping can only be accomplished by pushing back the token into
1357 * the lexer, and that only works when there is no lookahead token.
1359 * Sequences of 0 or more optional arguments are scanned using either
1360 * function_arglist_backup or function_arglist_nonbackup. The first
1361 * is used when optional arguments are followed by at least one
1362 * mandatory argument: in that case optional arguments may be skipped
1363 * by either a false predicate (in which case the expression will be
1364 * pushed back as one or more tokens, preceded by a BACKUP token) or
1365 * by using \default.
1367 * If optional arguments are at the end of the argument list, they are
1368 * instead scanned using function_arglist_nonbackup: here the only
1369 * manner to enter into skipping of optional arguments is the use of
1372 * The argument list of a normal function call is parsed using
1373 * function_arglist. The part of an argument list before a mandatory
1374 * argument is parsed using function_arglist_optional.
1376 * The difference is that leading optional arguments are scanned using
1377 * function_arglist_nonbackup and function_arglist_backup,
1380 * Most other details are obvious in the rules themselves.
1384 function_arglist_nonbackup_common:
1385 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1387 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1389 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1391 SCM n = scm_difference ($5, SCM_UNDEFINED);
1392 if (scm_is_true (scm_call_1 ($2, n)))
1393 $$ = scm_cons (n, $3);
1395 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1396 t->set_property ("digit", $5);
1397 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1402 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1404 $$ = check_scheme_arg (parser, @4,
1405 scm_difference ($5, SCM_UNDEFINED),
1408 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1410 $$ = check_scheme_arg (parser, @4,
1411 scm_difference ($5, SCM_UNDEFINED),
1416 function_arglist_closed_nonbackup:
1417 function_arglist_nonbackup_common
1418 | function_arglist_closed_common
1419 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg_closed
1421 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1423 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_closed
1425 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1427 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1429 $$ = check_scheme_arg (parser, @4,
1430 try_string_variants ($2, $4),
1433 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1435 $$ = check_scheme_arg (parser, @4,
1436 try_string_variants ($2, $4),
1439 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1441 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1447 | SYMBOL_LIST '.' symbol_list_rev
1449 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1455 | symbol_list_rev '.' symbol_list_part
1457 $$ = scm_append_x (scm_list_2 ($3, $1));
1461 // symbol_list_part delivers elements in reverse copy.
1466 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1467 $$ = try_string_variants (sym_l_p, $1);
1468 if (SCM_UNBNDP ($$)) {
1469 parser->parser_error (@1, _("not a symbol"));
1472 $$ = scm_reverse ($$);
1477 symbol_list_element:
1483 function_arglist_nonbackup:
1484 function_arglist_nonbackup_common
1485 | function_arglist_common
1486 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1488 if (scm_is_true (scm_call_1 ($2, $4)))
1489 $$ = scm_cons ($4, $3);
1491 $$ = check_scheme_arg (parser, @4,
1492 make_music_from_simple
1496 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1498 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1500 | function_arglist_nonbackup_reparse REPARSE duration_length
1502 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1504 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1506 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1508 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1510 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1512 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1514 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1516 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1518 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1522 function_arglist_nonbackup_reparse:
1523 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1526 SCM res = try_string_variants ($2, $4);
1527 if (!SCM_UNBNDP (res))
1528 if (scm_is_pair (res))
1529 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1531 MYREPARSE (@4, $2, SCM_ARG, res);
1532 else if (scm_is_true
1534 ($2, make_music_from_simple
1536 MYREPARSE (@4, $2, STRING, $4);
1538 MYREPARSE (@4, $2, SCM_ARG, $4);
1540 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1543 SCM res = try_string_variants ($2, $4);
1544 if (!SCM_UNBNDP (res))
1545 if (scm_is_pair (res))
1546 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1548 MYREPARSE (@4, $2, SCM_ARG, res);
1549 else if (scm_is_true
1551 ($2, make_music_from_simple
1553 MYREPARSE (@4, $2, STRING, $4);
1555 MYREPARSE (@4, $2, SCM_ARG, $4);
1557 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1560 if (scm_is_true (scm_call_1 ($2, $4)))
1561 MYREPARSE (@4, $2, SCM_ARG, $4);
1562 else if (scm_is_true
1564 ($2, make_music_from_simple
1566 MYREPARSE (@4, $2, STRING, $4);
1568 MYREPARSE (@4, $2, SCM_ARG, $4);
1570 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1573 if (scm_is_true (scm_call_1 ($2, $4)))
1574 MYREPARSE (@4, $2, REAL, $4);
1576 SCM d = make_duration ($4);
1577 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1578 MYREPARSE (@4, $2, REAL, $4); // trigger error
1580 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1583 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1585 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1590 // function_arglist_backup can't occur at the end of an argument
1591 // list. It needs to be careful about avoiding lookahead only until
1592 // it has made a decision whether or not to accept the parsed entity.
1593 // At that point of time, music requiring lookahead to parse becomes
1595 function_arglist_backup:
1596 function_arglist_common
1597 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg_closed
1599 if (scm_is_true (scm_call_1 ($2, $4)))
1601 $$ = scm_cons ($4, $3);
1603 $$ = scm_cons (loc_on_music (@3, $1), $3);
1604 MYBACKUP (SCM_ARG, $4, @4);
1607 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REPEAT simple_string unsigned_number
1609 $4 = MAKE_SYNTAX ("repeat", @4, $5, $6,
1610 MY_MAKE_MUSIC ("Music", @4)->unprotect (),
1612 if (scm_is_true (scm_call_1 ($2, $4)))
1615 MYREPARSE (@4, $2, REPEAT_IDENTIFIER, scm_cons ($5, $6));
1617 $$ = scm_cons (loc_on_music (@3, $1), $3);
1618 MYBACKUP (REPEAT_IDENTIFIER, scm_cons ($5, $6), @4);
1621 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup chord_body
1623 if (scm_is_true (scm_call_1 ($2, $4)))
1626 MYREPARSE (@4, $2, CHORD_BODY_IDENTIFIER, $4);
1628 $$ = scm_cons (loc_on_music (@3, $1), $3);
1629 MYBACKUP (CHORD_BODY_IDENTIFIER, $4, @4);
1632 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1634 if (scm_is_true (scm_call_1 ($2, $4)))
1636 $$ = scm_cons ($4, $3);
1638 $$ = scm_cons (loc_on_music (@3, $1), $3);
1639 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1642 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1644 if (scm_is_true (scm_call_1 ($2, $4)))
1645 $$ = scm_cons ($4, $3);
1647 $$ = scm_cons (loc_on_music (@3, $1), $3);
1648 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1651 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1653 if (scm_is_true (scm_call_1 ($2, $4)))
1655 MYREPARSE (@4, $2, REAL, $4);
1658 SCM d = make_duration ($4);
1659 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1661 $$ = scm_cons (loc_on_music (@3, $1), $3);
1662 MYBACKUP (UNSIGNED, $4, @4);
1664 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1669 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1671 if (scm_is_true (scm_call_1 ($2, $4)))
1674 MYREPARSE (@4, $2, REAL, $4);
1676 $$ = scm_cons (loc_on_music (@3, $1), $3);
1677 MYBACKUP (REAL, $4, @4);
1680 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1682 if (scm_is_true (scm_call_1 ($2, $4)))
1684 $$ = scm_cons ($4, $3);
1686 $$ = scm_cons (loc_on_music (@3, $1), $3);
1687 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1690 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1692 SCM n = scm_difference ($5, SCM_UNDEFINED);
1693 if (scm_is_true (scm_call_1 ($2, n))) {
1695 MYREPARSE (@5, $2, REAL, n);
1697 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1698 t->set_property ("digit", $5);
1699 $$ = t->unprotect ();
1700 if (scm_is_true (scm_call_1 ($2, $$)))
1701 $$ = scm_cons ($$, $3);
1703 $$ = scm_cons (loc_on_music (@3, $1), $3);
1704 MYBACKUP (UNSIGNED, $5, @5);
1705 parser->lexer_->push_extra_token ('-');
1710 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1712 SCM n = scm_difference ($5, SCM_UNDEFINED);
1713 if (scm_is_true (scm_call_1 ($2, n))) {
1714 MYREPARSE (@5, $2, REAL, n);
1717 $$ = scm_cons (loc_on_music (@3, $1), $3);
1718 MYBACKUP (REAL, n, @5);
1721 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1723 SCM n = scm_difference ($5, SCM_UNDEFINED);
1724 if (scm_is_true (scm_call_1 ($2, n))) {
1725 $$ = scm_cons (n, $3);
1727 $$ = scm_cons (loc_on_music (@3, $1), $3);
1728 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1731 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup PITCH_IDENTIFIER
1733 SCM m = make_music_from_simple (parser, @4, $4);
1734 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1736 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1738 } else if (scm_is_true (scm_call_1 ($2, $4)))
1740 MYREPARSE (@4, $2, PITCH_ARG, $4);
1743 $$ = scm_cons (loc_on_music (@3, $1), $3);
1744 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1747 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NOTENAME_PITCH
1749 SCM m = make_music_from_simple (parser, @4, $4);
1750 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1752 MYREPARSE (@4, $2, NOTENAME_PITCH, $4);
1754 } else if (scm_is_true (scm_call_1 ($2, $4)))
1756 MYREPARSE (@4, $2, PITCH_ARG, $4);
1759 $$ = scm_cons (loc_on_music (@3, $1), $3);
1760 MYBACKUP (NOTENAME_PITCH, $4, @4);
1763 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup TONICNAME_PITCH
1765 SCM m = make_music_from_simple (parser, @4, $4);
1766 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1768 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1770 } else if (scm_is_true (scm_call_1 ($2, $4)))
1772 MYREPARSE (@4, $2, PITCH_ARG, $4);
1775 $$ = scm_cons (loc_on_music (@3, $1), $3);
1776 MYBACKUP (TONICNAME_PITCH, $4, @4);
1779 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1781 if (scm_is_true (scm_call_1 ($2, $4)))
1783 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1786 $$ = scm_cons (loc_on_music (@3, $1), $3);
1787 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1790 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1792 SCM res = try_string_variants ($2, $4);
1793 if (!SCM_UNBNDP (res))
1794 if (scm_is_pair (res)) {
1796 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1799 $$ = scm_cons (res, $3);
1801 $$ = scm_cons (loc_on_music (@3, $1), $3);
1802 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1805 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1807 SCM res = try_string_variants ($2, $4);
1808 if (!SCM_UNBNDP (res))
1809 if (scm_is_pair (res)) {
1811 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1814 $$ = scm_cons (res, $3);
1816 $$ = scm_cons (loc_on_music (@3, $1), $3);
1817 MYBACKUP (STRING, $4, @4);
1820 | function_arglist_backup REPARSE music_assign
1822 if (scm_is_true (scm_call_1 ($2, $3)))
1823 $$ = scm_cons ($3, $1);
1825 $$ = check_scheme_arg (parser, @3,
1826 make_music_from_simple
1830 | function_arglist_backup REPARSE pitch_arg
1832 $$ = check_scheme_arg (parser, @3,
1835 | function_arglist_backup REPARSE bare_number_common
1837 $$ = check_scheme_arg (parser, @3,
1840 | function_arglist_backup REPARSE duration_length
1842 $$ = check_scheme_arg (parser, @3,
1845 | function_arglist_backup REPARSE symbol_list_arg
1847 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1852 function_arglist_nonbackup
1853 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1855 $$ = scm_cons (loc_on_music (@4, $1), $3);
1859 function_arglist_skip_nonbackup:
1860 function_arglist_nonbackup
1861 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1863 $$ = scm_cons (loc_on_music (@3, $1), $3);
1867 function_arglist_common:
1868 EXPECT_NO_MORE_ARGS {
1871 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1873 if (scm_is_true (scm_call_1 ($1, $3)))
1874 $$ = scm_cons ($3, $2);
1876 $$ = check_scheme_arg (parser, @3,
1877 make_music_from_simple
1881 | EXPECT_SCM function_arglist_optional bare_number_common
1883 $$ = check_scheme_arg (parser, @3,
1886 | EXPECT_SCM function_arglist_optional post_event_nofinger
1888 $$ = check_scheme_arg (parser, @3,
1891 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1893 SCM n = scm_difference ($4, SCM_UNDEFINED);
1894 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1896 | function_arglist_common_reparse REPARSE SCM_ARG
1898 $$ = check_scheme_arg (parser, @3,
1901 | function_arglist_common_reparse REPARSE lyric_element_music
1903 $$ = check_scheme_arg (parser, @3,
1906 | function_arglist_common_reparse REPARSE bare_number_common
1908 $$ = check_scheme_arg (parser, @3,
1911 | function_arglist_common_reparse REPARSE duration_length
1913 $$ = check_scheme_arg (parser, @3,
1916 | function_arglist_common_reparse REPARSE symbol_list_arg
1918 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1922 function_arglist_common_reparse:
1923 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1926 SCM res = try_string_variants ($1, $3);
1927 if (!SCM_UNBNDP (res))
1928 if (scm_is_pair (res))
1929 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1931 MYREPARSE (@3, $1, SCM_ARG, res);
1932 else if (scm_is_true
1934 ($1, make_music_from_simple (parser, @3, $3))))
1935 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1937 // This is going to flag a syntax error, we
1938 // know the predicate to be false.
1939 MYREPARSE (@3, $1, SCM_ARG, $3);
1941 | EXPECT_SCM function_arglist_optional STRING
1944 SCM res = try_string_variants ($1, $3);
1945 if (!SCM_UNBNDP (res))
1946 if (scm_is_pair (res))
1947 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1949 MYREPARSE (@3, $1, SCM_ARG, res);
1950 else if (scm_is_true
1952 ($1, make_music_from_simple (parser, @3, $3))))
1953 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1955 // This is going to flag a syntax error, we
1956 // know the predicate to be false.
1957 MYREPARSE (@3, $1, SCM_ARG, $3);
1959 | EXPECT_SCM function_arglist_optional full_markup
1962 if (scm_is_true (scm_call_1 ($1, $3)))
1963 MYREPARSE (@3, $1, SCM_ARG, $3);
1964 else if (scm_is_true
1966 ($1, make_music_from_simple (parser, @3, $3))))
1967 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1969 // This is going to flag a syntax error, we
1970 // know the predicate to be false.
1971 MYREPARSE (@3, $1, SCM_ARG, $3);
1973 | EXPECT_SCM function_arglist_optional UNSIGNED
1976 if (scm_is_true (scm_call_1 ($1, $3)))
1977 MYREPARSE (@3, $1, REAL, $3);
1979 SCM d = make_duration ($3);
1980 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
1981 MYREPARSE (@3, $1, REAL, $3);
1983 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
1986 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
1989 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
1991 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
1994 SCM n = scm_difference ($4, SCM_UNDEFINED);
1995 if (scm_is_true (scm_call_1 ($1, n)))
1996 MYREPARSE (@4, $1, REAL, n);
1998 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1999 t->set_property ("digit", $4);
2000 SCM m = t->unprotect ();
2001 if (scm_is_true (scm_call_1 ($1, m)))
2002 MYREPARSE (@4, $1, SCM_ARG, m);
2004 MYREPARSE (@4, $1, SCM_ARG, $4);
2008 | EXPECT_SCM function_arglist_optional '-' REAL
2011 SCM n = scm_difference ($4, SCM_UNDEFINED);
2012 MYREPARSE (@4, $1, REAL, n);
2016 function_arglist_closed:
2017 function_arglist_closed_nonbackup
2018 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2020 $$ = scm_cons (loc_on_music (@4, $1), $3);
2024 function_arglist_closed_common:
2025 EXPECT_NO_MORE_ARGS {
2028 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
2030 $$ = check_scheme_arg (parser, @3,
2033 | EXPECT_SCM function_arglist_optional bare_number_common_closed
2035 $$ = check_scheme_arg (parser, @3,
2038 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2040 $$ = check_scheme_arg (parser, @3,
2041 scm_difference ($4, SCM_UNDEFINED),
2044 | EXPECT_SCM function_arglist_optional post_event_nofinger
2046 $$ = check_scheme_arg (parser, @3,
2049 | function_arglist_common_reparse REPARSE SCM_ARG
2051 $$ = check_scheme_arg (parser, @3,
2054 | function_arglist_common_reparse REPARSE bare_number_common_closed
2056 $$ = check_scheme_arg (parser, @3,
2059 | function_arglist_common_reparse REPARSE symbol_list_arg
2061 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2065 function_arglist_optional:
2066 function_arglist_backup
2067 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2069 $$ = scm_cons (loc_on_music (@4, $1), $3);
2071 | function_arglist_skip_backup BACKUP
2074 function_arglist_skip_backup:
2075 function_arglist_backup
2076 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2078 $$ = scm_cons (loc_on_music (@3, $1), $3);
2082 embedded_scm_closed:
2084 | scm_function_call_closed
2087 embedded_scm_arg_closed:
2088 embedded_scm_bare_arg
2089 | scm_function_call_closed
2093 scm_function_call_closed:
2094 SCM_FUNCTION function_arglist_closed {
2095 $$ = MAKE_SYNTAX ("music-function", @$,
2100 music_function_call:
2101 MUSIC_FUNCTION function_arglist {
2102 $$ = MAKE_SYNTAX ("music-function", @$,
2109 /**/ { $$ = SCM_EOL; }
2110 | '=' simple_string {
2117 | repeated_music { $$ = $1; }
2118 | re_rhythmed_music { $$ = $1; }
2119 | complex_music_prefix music
2121 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2125 complex_music_prefix:
2126 CONTEXT symbol optional_id optional_context_mod {
2127 Context_mod *ctxmod = unsmob_context_mod ($4);
2130 mods = ctxmod->get_mods ();
2131 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2133 | NEWCONTEXT symbol optional_id optional_context_mod {
2134 Context_mod *ctxmod = unsmob_context_mod ($4);
2137 mods = ctxmod->get_mods ();
2138 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2143 mode_changing_head grouped_music_list {
2144 if ($1 == ly_symbol2scm ("chords"))
2146 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2152 parser->lexer_->pop_state ();
2154 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2155 Context_mod *ctxmod = unsmob_context_mod ($2);
2158 mods = ctxmod->get_mods ();
2159 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2160 if ($1 == ly_symbol2scm ("ChordNames"))
2162 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2164 parser->lexer_->pop_state ();
2170 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2171 parser->lexer_->push_note_state (nn);
2173 $$ = ly_symbol2scm ("notes");
2177 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2178 parser->lexer_->push_note_state (nn);
2180 $$ = ly_symbol2scm ("drums");
2183 parser->lexer_->push_figuredbass_state ();
2185 $$ = ly_symbol2scm ("figures");
2188 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2189 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2190 nn = parser->lexer_->lookup_identifier ("pitchnames");
2191 parser->lexer_->push_chord_state (nn);
2192 $$ = ly_symbol2scm ("chords");
2196 { parser->lexer_->push_lyric_state ();
2197 $$ = ly_symbol2scm ("lyrics");
2201 mode_changing_head_with_context:
2203 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2204 parser->lexer_->push_note_state (nn);
2206 $$ = ly_symbol2scm ("DrumStaff");
2209 parser->lexer_->push_figuredbass_state ();
2211 $$ = ly_symbol2scm ("FiguredBass");
2214 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2215 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2216 nn = parser->lexer_->lookup_identifier ("pitchnames");
2217 parser->lexer_->push_chord_state (nn);
2218 $$ = ly_symbol2scm ("ChordNames");
2221 { parser->lexer_->push_lyric_state ();
2222 $$ = ly_symbol2scm ("Lyrics");
2227 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2230 /* Can also use music at the expensive of two S/Rs similar to
2231 \repeat \alternative */
2232 parser->lexer_->pop_state ();
2234 $$ = scm_cons ($3, SCM_EOL);
2236 | new_lyrics ADDLYRICS {
2237 parser->lexer_->push_lyric_state ();
2239 parser->lexer_->pop_state ();
2240 $$ = scm_cons ($4, $1);
2245 composite_music new_lyrics {
2246 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2248 | LYRICSTO simple_string {
2249 parser->lexer_->push_lyric_state ();
2251 parser->lexer_->pop_state ();
2252 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2257 CHANGE symbol '=' simple_string {
2258 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2265 $$ = scm_reverse_x ($1, SCM_EOL);
2267 | symbol_list_rev property_path {
2268 $$ = scm_reverse_x ($1, $2);
2274 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2277 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2279 | OVERRIDE property_path '=' scalar {
2280 if (scm_ilength ($2) < 2) {
2281 parser->parser_error (@2, _("bad grob property path"));
2284 $$ = scm_cons (ly_symbol2scm ("push"),
2285 scm_cons2 (scm_car ($2),
2290 | REVERT revert_arg {
2291 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2295 // This is all quite awkward for the sake of substantial backward
2296 // compatibility while at the same time allowing a more "natural" form
2297 // of specification not separating grob specification from grob
2298 // property path. The purpose of this definition of revert_arg is to
2299 // allow the symbol list which specifies grob and property to revert
2300 // to be optionally be split into two parts after the grob (which in
2301 // this case is just the first element of the list). symbol_list_part
2302 // is only one path component, but it can be parsed without lookahead,
2303 // so we can follow it with a synthetic BACKUP token when needed. If
2304 // the first symbol_list_part already contains multiple elements (only
2305 // possible if a Scheme expression provides them), we just parse for
2306 // additional elements introduced by '.', which is what the
2307 // SYMBOL_LIST backup in connection with the immediately following
2308 // rule using symbol_list_arg does.
2310 // As long as we don't have our coffers filled with both grob and at
2311 // least one grob property specification, the rest of the required
2312 // symbol list chain may be provided either with or without a leading
2313 // dot. This is for both allowing the traditional
2314 // \revert Accidental #'color
2315 // as well as well as the "naive" form
2316 // \revert Accidental.color
2319 revert_arg_backup BACKUP symbol_list_arg
2328 if (scm_is_null ($1)
2329 || scm_is_null (scm_cdr ($1)))
2330 MYBACKUP (SCM_ARG, $1, @1);
2332 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2336 // revert_arg_part delivers results in reverse
2339 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2341 $$ = scm_append_x (scm_list_2 ($5, $3));
2343 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2345 $$ = scm_append_x (scm_list_2 ($4, $3));
2350 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2351 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2353 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2354 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2355 | DENIES { $$ = ly_symbol2scm ("denies"); }
2357 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2358 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2359 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2360 | NAME { $$ = ly_symbol2scm ("context-name"); }
2364 property_operation { $$ = $1; }
2365 | context_def_mod STRING {
2366 $$ = scm_list_2 ($1, $2);
2368 | context_def_mod embedded_scm
2370 if (!scm_is_string ($2)
2371 && ly_symbol2scm ("consists") != $1
2372 && ly_symbol2scm ("remove") != $1)
2375 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2379 $$ = scm_list_2 ($1, $2);
2384 // If defined, at least two members.
2388 SCM l = scm_reverse_x ($1, SCM_EOL);
2391 (scm_object_property (scm_car (l),
2392 ly_symbol2scm ("is-grob?"))))
2393 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2394 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2395 parser->parser_error (@1, _ ("bad grob property path"));
2402 // If defined, at least three members
2406 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2408 parser->parser_error (@1, _ ("bad grob property path"));
2412 | grob_prop_spec property_path
2414 if (!SCM_UNBNDP ($1)) {
2415 $$ = scm_append_x (scm_list_2 ($1, $2));
2416 if (scm_is_null (scm_cddr ($$))) {
2417 parser->parser_error (@$, _ ("bad grob property path"));
2425 // Exactly two elements or undefined
2429 SCM l = scm_reverse_x ($1, SCM_EOL);
2430 switch (scm_ilength (l)) {
2432 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2436 parser->parser_error (@1, _ ("bad context property path"));
2443 simple_music_property_def:
2444 OVERRIDE grob_prop_path '=' scalar {
2445 if (SCM_UNBNDP ($2))
2448 $$ = scm_list_5 (scm_car ($2),
2449 ly_symbol2scm ("OverrideProperty"),
2455 | REVERT simple_revert_context revert_arg {
2456 $$ = scm_list_4 ($2,
2457 ly_symbol2scm ("RevertProperty"),
2461 | SET context_prop_spec '=' scalar {
2462 if (SCM_UNBNDP ($2))
2465 $$ = scm_list_4 (scm_car ($2),
2466 ly_symbol2scm ("PropertySet"),
2470 | UNSET context_prop_spec {
2471 if (SCM_UNBNDP ($2))
2474 $$ = scm_list_3 (scm_car ($2),
2475 ly_symbol2scm ("PropertyUnset"),
2481 // This is all quite awkward for the sake of substantial backward
2482 // compatibility while at the same time allowing a more "natural" form
2483 // of specification not separating grob specification from grob
2484 // property path. The purpose of this definition of
2485 // simple_revert_context is to allow the symbol list which specifies
2486 // grob and property to revert to be optionally be split into two
2487 // parts after the grob (which may be preceded by a context
2488 // specification, a case which we distinguish by checking whether the
2489 // first symbol is a valid grob symbol instead).
2491 // See revert_arg above for the main work horse of this arrangement.
2492 // simple_revert_context just caters for the context and delegates the
2493 // rest of the job to revert_arg.
2495 simple_revert_context:
2498 $1 = scm_reverse_x ($1, SCM_EOL);
2499 if (scm_is_null ($1)
2501 (scm_object_property (scm_car ($1),
2502 ly_symbol2scm ("is-grob?")))) {
2503 $$ = ly_symbol2scm ("Bottom");
2504 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2507 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2514 simple_music_property_def {
2515 if (SCM_UNBNDP ($1))
2516 $$ = MAKE_SYNTAX ("void-music", @1);
2518 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2529 simple_string: STRING {
2534 if (scm_is_string ($1)) {
2537 parser->parser_error (@1, (_ ("simple string expected")));
2538 $$ = scm_string (SCM_EOL);
2545 $$ = scm_string_to_symbol ($1);
2549 // This is a bit of overkill but makes the same
2550 // routine responsible for all symbol interpretations.
2551 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2553 if (SCM_UNBNDP ($$))
2555 parser->parser_error (@1, (_ ("symbol expected")));
2556 // Generate a unique symbol in case it is used
2557 // for an assignment or similar
2558 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2567 // The following is a rather defensive variant of admitting
2568 // negative numbers: the grammar would permit number_factor or
2569 // even number_expression. However, function arguments allow
2570 // only this simple kind of negative number, so to have things
2571 // like \tweak and \override behave reasonably similar, it
2572 // makes sense to rule out things like -- which are rather an
2573 // accent in function argument contexts.
2576 $$ = scm_difference ($2, SCM_UNDEFINED);
2583 simple_element post_events {
2584 // Let the rhythmic music iterator sort this mess out.
2585 if (scm_is_pair ($2)) {
2586 $$ = make_music_from_simple (parser, @1, $1);
2587 if (unsmob_music ($$))
2588 unsmob_music ($$)->set_property ("articulations",
2589 scm_reverse_x ($2, SCM_EOL));
2592 parser->parser_error (@1, _("music expected"));
2593 $$ = MAKE_SYNTAX ("void-music", @1);
2597 | simple_chord_elements post_events {
2598 if (scm_is_pair ($2)) {
2599 if (unsmob_pitch ($1))
2600 $1 = make_chord_elements (@1,
2602 parser->default_duration_.smobbed_copy (),
2605 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2607 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
2608 } else if (!unsmob_pitch ($1))
2609 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
2610 // A mere pitch drops through.
2612 | CHORD_REPETITION optional_notemode_duration post_events {
2614 i.set_location (@1, @3);
2615 $$ = MAKE_SYNTAX ("repetition-chord", i,
2616 $2, scm_reverse_x ($3, SCM_EOL));
2618 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2620 i.set_location (@1, @3);
2621 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2622 scm_reverse_x ($3, SCM_EOL));
2625 | note_chord_element
2630 chord_body optional_notemode_duration post_events
2632 Music *m = unsmob_music ($1);
2633 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2634 SCM es = m->get_property ("elements");
2635 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2637 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2638 unsmob_music (scm_car (s))->set_property ("duration", dur);
2639 es = ly_append2 (es, postevs);
2641 m-> set_property ("elements", es);
2643 $$ = m->self_scm ();
2648 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2650 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2652 | CHORD_BODY_IDENTIFIER
2655 chord_body_elements:
2656 /* empty */ { $$ = SCM_EOL; }
2657 | chord_body_elements chord_body_element {
2658 if (!SCM_UNBNDP ($2))
2659 $$ = scm_cons ($2, $1);
2664 pitch exclamations questions octave_check post_events
2666 bool q = to_boolean ($3);
2667 bool ex = to_boolean ($2);
2671 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2672 n->set_property ("pitch", $1);
2674 n->set_property ("cautionary", SCM_BOOL_T);
2676 n->set_property ("force-accidental", SCM_BOOL_T);
2678 if (scm_is_pair (post)) {
2679 SCM arts = scm_reverse_x (post, SCM_EOL);
2680 n->set_property ("articulations", arts);
2682 if (scm_is_number (check))
2684 int q = scm_to_int (check);
2685 n->set_property ("absolute-octave", scm_from_int (q-1));
2688 $$ = n->unprotect ();
2690 | DRUM_PITCH post_events {
2691 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2692 n->set_property ("drum-type", $1);
2694 if (scm_is_pair ($2)) {
2695 SCM arts = scm_reverse_x ($2, SCM_EOL);
2696 n->set_property ("articulations", arts);
2698 $$ = n->unprotect ();
2700 | music_function_chord_body
2702 Music *m = unsmob_music ($1);
2704 while (m && m->is_mus_type ("music-wrapper-music")) {
2705 $$ = m->get_property ("element");
2706 m = unsmob_music ($$);
2709 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2710 parser->parser_error (@$, _ ("not a rhythmic event"));
2716 music_function_chord_body:
2721 // Event functions may only take closed arglists, otherwise it would
2722 // not be clear whether a following postevent should be associated
2723 // with the last argument of the event function or with the expression
2724 // for which the function call acts itself as event.
2726 music_function_call_closed:
2727 MUSIC_FUNCTION function_arglist_closed {
2728 $$ = MAKE_SYNTAX ("music-function", @$,
2733 event_function_event:
2734 EVENT_FUNCTION function_arglist_closed {
2735 $$ = MAKE_SYNTAX ("music-function", @$,
2757 | post_events post_event {
2759 if (Music *m = unsmob_music ($2))
2761 if (m->is_mus_type ("post-event-wrapper"))
2763 for (SCM p = m->get_property ("elements");
2767 $$ = scm_cons (scm_car (p), $$);
2771 $$ = scm_cons ($2, $$);
2777 post_event_nofinger:
2778 direction_less_event {
2781 | script_dir music_function_call_closed {
2783 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2784 parser->parser_error (@2, _ ("post-event expected"));
2785 $$ = SCM_UNSPECIFIED;
2786 } else if (!SCM_UNBNDP ($1))
2788 unsmob_music ($$)->set_property ("direction", $1);
2792 if (!parser->lexer_->is_lyric_state ())
2793 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2794 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2797 if (!parser->lexer_->is_lyric_state ())
2798 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2799 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2801 | script_dir direction_reqd_event {
2802 if (!SCM_UNBNDP ($1))
2804 Music *m = unsmob_music ($2);
2805 m->set_property ("direction", $1);
2809 | script_dir direction_less_event {
2810 if (!SCM_UNBNDP ($1))
2812 Music *m = unsmob_music ($2);
2813 m->set_property ("direction", $1);
2820 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2825 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2836 string_number_event:
2838 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2839 s->set_property ("string-number", $1);
2840 $$ = s->unprotect ();
2844 direction_less_event:
2846 | EVENT_IDENTIFIER {
2850 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2851 a->set_property ("tremolo-type", $1);
2852 $$ = a->unprotect ();
2854 | event_function_event
2857 direction_reqd_event:
2861 | script_abbreviation {
2862 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2863 if (scm_is_string (s)) {
2864 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2865 a->set_property ("articulation-type", s);
2866 $$ = a->unprotect ();
2868 Music *original = unsmob_music (s);
2869 if (original && original->is_mus_type ("post-event")) {
2870 Music *a = original->clone ();
2871 a->set_spot (parser->lexer_->override_input (@$));
2872 $$ = a->unprotect ();
2874 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2875 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2882 /**/ { $$ = SCM_EOL; }
2883 | '=' quotes { $$ = $2; }
2897 $$ = scm_from_int (1);
2900 $$ = scm_oneplus ($1);
2906 $$ = scm_from_int (-1);
2909 $$ = scm_oneminus ($1);
2914 NOTENAME_PITCH quotes {
2915 if (!scm_is_eq (SCM_INUM0, $2))
2917 Pitch p = *unsmob_pitch ($1);
2918 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2919 $$ = p.smobbed_copy ();
2929 TONICNAME_PITCH quotes {
2930 if (!scm_is_eq (SCM_INUM0, $2))
2932 Pitch p = *unsmob_pitch ($1);
2933 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2934 $$ = p.smobbed_copy ();
2941 | PITCH_IDENTIFIER quotes {
2942 if (!scm_is_eq (SCM_INUM0, $2))
2944 Pitch p = *unsmob_pitch ($1);
2945 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2946 $$ = p.smobbed_copy ();
2953 if (!scm_is_eq (SCM_INUM0, $2))
2955 Pitch p = *unsmob_pitch ($1);
2956 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2957 $$ = p.smobbed_copy ();
2964 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2965 t->set_property ("text", $1);
2966 $$ = t->unprotect ();
2969 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2970 t->set_property ("text",
2971 make_simple_markup ($1));
2972 $$ = t->unprotect ();
2974 | embedded_scm_closed
2976 Music *m = unsmob_music ($1);
2977 if (m && m->is_mus_type ("post-event"))
2979 else if (Text_interface::is_markup ($1)) {
2980 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2981 t->set_property ("text", $1);
2982 $$ = t->unprotect ();
2984 parser->parser_error (@1, _ ("not an articulation"));
2990 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2991 t->set_property ("digit", $1);
2992 $$ = t->unprotect ();
2996 script_abbreviation:
2998 $$ = scm_from_locale_string ("Hat");
3001 $$ = scm_from_locale_string ("Plus");
3004 $$ = scm_from_locale_string ("Dash");
3007 $$ = scm_from_locale_string ("Bang");
3010 $$ = scm_from_locale_string ("Larger");
3013 $$ = scm_from_locale_string ("Dot");
3016 $$ = scm_from_locale_string ("Underscore");
3021 '_' { $$ = scm_from_int (DOWN); }
3022 | '^' { $$ = scm_from_int (UP); }
3023 | '-' { $$ = SCM_UNDEFINED; }
3027 multiplied_duration {
3032 maybe_notemode_duration:
3036 | multiplied_duration {
3038 parser->default_duration_ = *unsmob_duration ($$);
3043 optional_notemode_duration:
3044 maybe_notemode_duration
3046 if (SCM_UNBNDP ($$))
3047 $$ = parser->default_duration_.smobbed_copy ();
3053 $$ = make_duration ($1, scm_to_int ($2));
3054 if (SCM_UNBNDP ($$))
3056 parser->parser_error (@1, _ ("not a duration"));
3057 $$ = Duration ().smobbed_copy ();
3060 | DURATION_IDENTIFIER dots {
3061 Duration *d = unsmob_duration ($1);
3062 Duration k (d->duration_log (),
3063 d->dot_count () + scm_to_int ($2));
3064 k = k.compressed (d->factor ());
3065 scm_remember_upto_here_1 ($1);
3066 $$ = k.smobbed_copy ();
3070 multiplied_duration:
3074 | multiplied_duration '*' UNSIGNED {
3075 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
3077 | multiplied_duration '*' FRACTION {
3078 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
3080 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
3089 $$ = scm_oneplus ($1);
3098 if (SCM_UNBNDP (make_duration ($2)))
3099 parser->parser_error (@2, _ ("not a duration"));
3105 UNSIGNED { $$ = $1; }
3106 | STRING { $$ = $1; }
3107 | full_markup { $$ = $1; }
3110 // as an integer, it needs to be non-negative, and otherwise
3111 // it needs to be suitable as a markup.
3112 if (scm_is_integer ($1)
3113 ? scm_is_true (scm_negative_p ($1))
3114 : !Text_interface::is_markup ($1))
3116 parser->parser_error (@1, _ ("bass number expected"));
3122 figured_bass_alteration:
3123 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3124 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3125 | '!' { $$ = scm_from_int (0); }
3130 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3131 $$ = bfr->unprotect ();
3134 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3135 $$ = bfr->self_scm ();
3137 if (scm_is_number ($1))
3138 bfr->set_property ("figure", $1);
3139 else if (Text_interface::is_markup ($1))
3140 bfr->set_property ("text", $1);
3146 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3148 | bass_figure figured_bass_alteration {
3149 Music *m = unsmob_music ($1);
3150 if (scm_to_double ($2)) {
3151 SCM salter = m->get_property ("alteration");
3152 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3153 m->set_property ("alteration",
3154 scm_sum (alter, $2));
3156 m->set_property ("alteration", scm_from_int (0));
3159 | bass_figure figured_bass_modification {
3160 Music *m = unsmob_music ($1);
3161 m->set_property ($2, SCM_BOOL_T);
3166 figured_bass_modification:
3168 $$ = ly_symbol2scm ("augmented");
3171 $$ = ly_symbol2scm ("no-continuation");
3174 $$ = ly_symbol2scm ("diminished");
3177 $$ = ly_symbol2scm ("augmented-slash");
3187 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3195 | figure_list br_bass_figure {
3196 $$ = scm_cons ($2, $1);
3201 FIGURE_OPEN figure_list FIGURE_CLOSE {
3202 $$ = scm_reverse_x ($2, SCM_EOL);
3208 /**/ { $$ = SCM_BOOL_F; }
3209 | REST { $$ = SCM_BOOL_T; }
3213 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3214 if (!parser->lexer_->is_note_state ())
3215 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3216 if (!SCM_UNBNDP ($2)
3218 || scm_is_number ($4)
3220 || scm_is_true ($6))
3223 if (scm_is_true ($6))
3224 n = MY_MAKE_MUSIC ("RestEvent", @$);
3226 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3228 n->set_property ("pitch", $1);
3229 if (SCM_UNBNDP ($5))
3230 n->set_property ("duration",
3231 parser->default_duration_.smobbed_copy ());
3233 n->set_property ("duration", $5);
3235 if (scm_is_number ($4))
3237 int q = scm_to_int ($4);
3238 n->set_property ("absolute-octave", scm_from_int (q-1));
3241 if (to_boolean ($3))
3242 n->set_property ("cautionary", SCM_BOOL_T);
3243 if (to_boolean ($2) || to_boolean ($3))
3244 n->set_property ("force-accidental", SCM_BOOL_T);
3246 $$ = n->unprotect ();
3249 | DRUM_PITCH optional_notemode_duration {
3250 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3251 n->set_property ("duration", $2);
3252 n->set_property ("drum-type", $1);
3254 $$ = n->unprotect ();
3256 | RESTNAME optional_notemode_duration {
3258 if (ly_scm2string ($1) == "s") {
3260 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3263 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3266 ev->set_property ("duration", $2);
3267 $$ = ev->unprotect ();
3271 // Can return a single pitch rather than a list.
3272 simple_chord_elements:
3274 if (!parser->lexer_->is_chord_state ())
3275 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3278 | figure_spec optional_notemode_duration {
3279 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3281 unsmob_music (scm_car (s))->set_property ("duration", $2);
3289 if (!parser->lexer_->is_lyric_state ())
3290 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3294 if (!parser->lexer_->is_lyric_state ())
3295 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3301 lyric_element_music:
3302 lyric_element optional_notemode_duration post_events {
3303 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3304 if (scm_is_pair ($3))
3305 unsmob_music ($$)->set_property
3306 ("articulations", scm_reverse_x ($3, SCM_EOL));
3310 // Can return a single pitch rather than a list.
3312 steno_tonic_pitch maybe_notemode_duration {
3313 if (SCM_UNBNDP ($2))
3316 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3318 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3319 SCM its = scm_reverse_x ($4, SCM_EOL);
3320 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3328 | chord_items chord_item {
3329 $$ = scm_cons ($2, $$);
3335 $$ = ly_symbol2scm ("chord-colon");
3338 $$ = ly_symbol2scm ("chord-caret");
3340 | CHORD_SLASH steno_tonic_pitch {
3341 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3343 | CHORD_BASS steno_tonic_pitch {
3344 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3353 $$ = scm_reverse_x ($1, SCM_EOL);
3361 step_number { $$ = scm_cons ($1, SCM_EOL); }
3362 | step_numbers '.' step_number {
3363 $$ = scm_cons ($3, $$);
3369 $$ = make_chord_step ($1, 0);
3372 $$ = make_chord_step ($1, SHARP_ALTERATION);
3374 | UNSIGNED CHORD_MINUS {
3375 $$ = make_chord_step ($1, FLAT_ALTERATION);
3383 | unsigned_number '-' unsigned_number {
3384 $$ = scm_cons ($1, $3);
3391 TODO: should deprecate in favor of Scheme?
3395 number_expression '+' number_term {
3396 $$ = scm_sum ($1, $3);
3398 | number_expression '-' number_term {
3399 $$ = scm_difference ($1, $3);
3408 | number_factor '*' number_factor {
3409 $$ = scm_product ($1, $3);
3411 | number_factor '/' number_factor {
3412 $$ = scm_divide ($1, $3);
3417 '-' number_factor { /* %prec UNARY_MINUS */
3418 $$ = scm_difference ($2, SCM_UNDEFINED);
3424 bare_number_common_closed
3425 | REAL NUMBER_IDENTIFIER
3427 $$ = scm_product ($1, $2);
3431 bare_number_common_closed:
3439 | UNSIGNED NUMBER_IDENTIFIER {
3440 $$ = scm_product ($1, $2);
3446 | bare_number_common_closed
3453 if (!scm_is_integer ($1)
3454 || scm_is_true (scm_negative_p ($1)))
3456 parser->parser_error (@1, _("not an unsigned integer"));
3462 if (!scm_is_integer ($1)
3463 || scm_is_true (scm_negative_p ($1)))
3465 parser->parser_error (@1, _("not an unsigned integer"));
3472 { $$ = SCM_UNDEFINED; }
3475 if (SCM_UNBNDP ($1))
3483 { $$ = SCM_UNDEFINED; }
3486 if (SCM_UNBNDP ($1))
3495 { parser->lexer_->push_markup_state (); }
3498 parser->lexer_->pop_state ();
3504 { parser->lexer_->push_markup_state (); }
3507 parser->lexer_->pop_state ();
3513 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3515 | markup_head_1_list simple_markup
3517 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3518 @2, $1, scm_list_1 ($2)));
3528 if (Text_interface::is_markup ($1))
3529 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3530 else if (Text_interface::is_markup_list ($1))
3531 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3533 parser->parser_error (@1, _ ("not a markup"));
3534 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3541 markup_composed_list {
3544 | markup_uncomposed_list
3547 markup_uncomposed_list:
3548 markup_braced_list {
3551 | markup_command_list {
3552 $$ = scm_list_1 ($1);
3554 | markup_scm MARKUPLIST_IDENTIFIER
3559 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3560 parser->lexer_->push_note_state (nn);
3561 } '{' score_body '}' {
3562 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3563 parser->lexer_->pop_state ();
3567 markup_composed_list:
3568 markup_head_1_list markup_uncomposed_list {
3569 $$ = MAKE_SYNTAX ("composed-markup-list",
3575 '{' markup_braced_list_body '}' {
3576 $$ = scm_reverse_x ($2, SCM_EOL);
3580 markup_braced_list_body:
3581 /* empty */ { $$ = SCM_EOL; }
3582 | markup_braced_list_body markup {
3583 $$ = scm_cons ($2, $1);
3585 | markup_braced_list_body markup_list {
3586 $$ = scm_reverse_x ($2, $1);
3590 markup_command_list:
3591 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3592 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3596 markup_command_basic_arguments:
3597 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3598 $$ = scm_cons ($3, $2);
3600 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3601 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3603 | EXPECT_NO_MORE_ARGS {
3608 markup_command_list_arguments:
3609 markup_command_basic_arguments { $$ = $1; }
3610 | EXPECT_MARKUP markup_command_list_arguments markup {
3611 $$ = scm_cons ($3, $2);
3616 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3617 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3622 markup_head_1_item {
3623 $$ = scm_list_1 ($1);
3625 | markup_head_1_list markup_head_1_item {
3626 $$ = scm_cons ($2, $1);
3632 $$ = make_simple_markup ($1);
3635 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3636 parser->lexer_->push_note_state (nn);
3637 } '{' score_body '}' {
3638 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3639 parser->lexer_->pop_state ();
3641 | MARKUP_FUNCTION markup_command_basic_arguments {
3642 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3644 | markup_scm MARKUP_IDENTIFIER
3651 markup_head_1_list simple_markup
3653 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3654 @2, $1, scm_list_1 ($2)));
3664 Lily_parser::set_yydebug (bool x)
3670 Lily_parser::do_yyparse ()
3672 SCM retval = SCM_UNDEFINED;
3673 yyparse (this, &retval);
3683 It is a little strange to have this function in this file, but
3684 otherwise, we have to import music classes into the lexer.
3688 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3690 if (unsmob_book (sid)) {
3691 Book *book = unsmob_book (sid)->clone ();
3692 *destination = book->self_scm ();
3695 return BOOK_IDENTIFIER;
3696 } else if (scm_is_number (sid)) {
3698 return NUMBER_IDENTIFIER;
3699 } else if (unsmob_context_def (sid)) {
3700 Context_def *def= unsmob_context_def (sid)->clone ();
3702 *destination = def->self_scm ();
3705 return CONTEXT_DEF_IDENTIFIER;
3706 } else if (unsmob_context_mod (sid)) {
3707 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3709 return CONTEXT_MOD_IDENTIFIER;
3710 } else if (Music *mus = unsmob_music (sid)) {
3711 mus = mus->clone ();
3712 *destination = mus->self_scm ();
3713 bool is_event = mus->is_mus_type ("post-event");
3715 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3716 } else if (unsmob_pitch (sid)) {
3717 *destination = unsmob_pitch (sid)->smobbed_copy ();
3718 return PITCH_IDENTIFIER;
3719 } else if (unsmob_duration (sid)) {
3720 *destination = unsmob_duration (sid)->smobbed_copy ();
3721 return DURATION_IDENTIFIER;
3722 } else if (unsmob_output_def (sid)) {
3723 Output_def *p = unsmob_output_def (sid);
3726 *destination = p->self_scm ();
3728 return OUTPUT_DEF_IDENTIFIER;
3735 get_next_unique_context_id ()
3737 return scm_from_locale_string ("$uniqueContextId");
3742 get_next_unique_lyrics_context_id ()
3744 static int new_context_count;
3746 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3747 return scm_from_locale_string (s);
3750 // check_scheme_arg checks one argument with a given predicate for use
3751 // in an argument list and throws a syntax error if it is unusable.
3752 // The argument is prepended to the argument list in any case. After
3753 // throwing a syntax error, the argument list is terminated with #f as
3754 // its last cdr in order to mark it as uncallable while not losing
3755 // track of its total length.
3757 // There are a few special considerations: if optional argument disp
3758 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3759 // instead of arg in a prospective error message. This is useful if
3760 // arg is not the actual argument but rather a transformation of it.
3762 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3763 // and an error message using disp is produced unconditionally.
3765 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3766 SCM arg, SCM args, SCM pred, SCM disp)
3768 if (SCM_UNBNDP (arg))
3769 args = scm_cons (disp, args);
3771 args = scm_cons (arg, args);
3772 if (scm_is_true (scm_call_1 (pred, arg)))
3775 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3776 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3777 SCM_UNBNDP (disp) ? arg : disp);
3778 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3782 SCM loc_on_music (Input loc, SCM arg)
3784 if (Music *m = unsmob_music (arg))
3788 return m->unprotect ();
3794 try_string_variants (SCM pred, SCM str)
3796 // a matching predicate is always ok
3797 if (scm_is_true (scm_call_1 (pred, str)))
3799 // a symbol may be interpreted as a list of symbols if it helps
3800 if (scm_is_symbol (str)) {
3801 str = scm_list_1 (str);
3802 if (scm_is_true (scm_call_1 (pred, str)))
3804 return SCM_UNDEFINED;
3807 // If this cannot be a string representation of a symbol list,
3810 if (!is_regular_identifier (str, true))
3811 return SCM_UNDEFINED;
3813 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3814 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3815 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3817 // Let's attempt the symbol list interpretation first.
3819 if (scm_is_true (scm_call_1 (pred, str)))
3822 // If there is just one symbol in the list, we might interpret
3823 // it as a single symbol
3825 if (scm_is_null (scm_cdr (str)))
3827 str = scm_car (str);
3828 if (scm_is_true (scm_call_1 (pred, str)))
3832 return SCM_UNDEFINED;
3836 is_regular_identifier (SCM id, bool multiple)
3838 if (!scm_is_string (id))
3841 string str = ly_scm2string (id);
3843 bool middle = false;
3845 for (string::iterator it=str.begin(); it != str.end (); it++)
3848 if ((c >= 'a' && c <= 'z')
3849 || (c >= 'A' && c <= 'Z')
3852 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3861 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3863 if (unsmob_music (simple))
3865 if (parser->lexer_->is_note_state ()) {
3866 if (scm_is_symbol (simple)) {
3867 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3868 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3869 n->set_property ("drum-type", simple);
3870 return n->unprotect ();
3872 if (unsmob_pitch (simple)) {
3873 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3874 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3875 n->set_property ("pitch", simple);
3876 return n->unprotect ();
3879 } else if (parser->lexer_->is_lyric_state ()) {
3880 if (Text_interface::is_markup (simple))
3881 return MAKE_SYNTAX ("lyric-event", loc, simple,
3882 parser->default_duration_.smobbed_copy ());
3883 } else if (parser->lexer_->is_chord_state ()) {
3884 if (unsmob_pitch (simple))
3888 make_chord_elements (loc, simple,
3889 parser->default_duration_.smobbed_copy (),
3896 make_music_with_input (SCM name, Input where)
3898 Music *m = make_music_by_name (name);
3899 m->set_spot (where);
3904 make_simple_markup (SCM a)
3910 make_duration (SCM d, int dots)
3912 int t = scm_to_int (d);
3913 if (t > 0 && (t & (t-1)) == 0)
3914 return Duration (intlog2 (t), dots).smobbed_copy ();
3916 return SCM_UNDEFINED;
3920 make_chord_step (SCM step_scm, Rational alter)
3922 int step = scm_to_int (step_scm);
3925 alter += FLAT_ALTERATION;
3929 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3930 return m.smobbed_copy ();
3935 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3937 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3938 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3939 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3941 unsmob_music (scm_car (s))->set_spot (loc);
3947 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3949 Lily_lexer *lex = parser->lexer_;
3953 lex->prepare_for_next_token ();
3954 return lex->yylex ();