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 // The following are somewhat precarious constructs as they may change
150 // the value of the lookahead token. That implies that the lookahead
151 // token must not yet have made an impact on the state stack other
152 // than causing the reduction of the current rule, or switching the
153 // lookahead token while Bison is mulling it over will cause trouble.
155 #define MYBACKUP(Token, Value, Location) \
157 if (yychar != YYEMPTY) \
158 parser->lexer_->push_extra_token \
159 (yylloc, yychar, yylval); \
161 parser->lexer_->push_extra_token \
162 (Location, Token, Value); \
163 parser->lexer_->push_extra_token (Location, BACKUP); \
168 #define MYREPARSE(Location, Pred, Token, Value) \
170 if (yychar != YYEMPTY) \
171 parser->lexer_->push_extra_token \
172 (yylloc, yychar, yylval); \
173 parser->lexer_->push_extra_token \
174 (Location, Token, Value); \
175 parser->lexer_->push_extra_token \
176 (Location, REPARSE, Pred); \
185 #define MY_MAKE_MUSIC(x, spot) \
186 make_music_with_input (ly_symbol2scm (x), \
187 parser->lexer_->override_input (spot))
190 - Don't use lily module, create a new module instead.
191 - delay application of the function
193 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
194 scm_apply_0 (proc, args)
195 /* Syntactic Sugar. */
196 #define MAKE_SYNTAX(name, location, ...) \
197 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))
198 #define START_MAKE_SYNTAX(name, ...) \
199 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
200 #define FINISH_MAKE_SYNTAX(start, location, ...) \
201 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)))))
203 SCM get_next_unique_context_id ();
204 SCM get_next_unique_lyrics_context_id ();
211 #define _(x) gettext (x)
215 static Music *make_music_with_input (SCM name, Input where);
216 SCM check_scheme_arg (Lily_parser *parser, Input loc,
217 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
218 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
219 SCM loc_on_music (Input loc, SCM arg);
220 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
221 SCM make_chord_step (SCM step, Rational alter);
222 SCM make_simple_markup (SCM a);
223 SCM make_duration (SCM t, int dots = 0);
224 bool is_regular_identifier (SCM id, bool multiple=false);
225 SCM try_string_variants (SCM pred, SCM str);
226 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
230 /* The third option is an alias that will be used to display the
231 syntax error. Bison CVS now correctly handles backslash escapes.
233 FIXME: Bison needs to translate some of these, eg, STRING.
237 /* Keyword tokens with plain escaped name. */
238 %token END_OF_FILE 0 "end of input"
239 %token ACCEPTS "\\accepts"
240 %token ADDLYRICS "\\addlyrics"
241 %token ALIAS "\\alias"
242 %token ALTERNATIVE "\\alternative"
244 %token BOOKPART "\\bookpart"
245 %token CHANGE "\\change"
246 %token CHORDMODE "\\chordmode"
247 %token CHORDS "\\chords"
248 %token CONSISTS "\\consists"
249 %token CONTEXT "\\context"
250 %token DEFAULT "\\default"
251 %token DEFAULTCHILD "\\defaultchild"
252 %token DENIES "\\denies"
253 %token DESCRIPTION "\\description"
254 %token DRUMMODE "\\drummode"
255 %token DRUMS "\\drums"
256 %token FIGUREMODE "\\figuremode"
257 %token FIGURES "\\figures"
258 %token HEADER "\\header"
259 %token INVALID "\\version-error"
260 %token LAYOUT "\\layout"
261 %token LYRICMODE "\\lyricmode"
262 %token LYRICS "\\lyrics"
263 %token LYRICSTO "\\lyricsto"
264 %token MARKUP "\\markup"
265 %token MARKUPLIST "\\markuplist"
268 %token NOTEMODE "\\notemode"
269 %token OVERRIDE "\\override"
270 %token PAPER "\\paper"
271 %token REMOVE "\\remove"
272 %token REPEAT "\\repeat"
274 %token REVERT "\\revert"
275 %token SCORE "\\score"
276 %token SCORELINES "\\score-lines"
277 %token SEQUENTIAL "\\sequential"
279 %token SIMULTANEOUS "\\simultaneous"
280 %token TEMPO "\\tempo"
282 %token UNSET "\\unset"
285 /* Keyword token exceptions. */
286 %token NEWCONTEXT "\\new"
289 /* Other string tokens. */
291 %token CHORD_BASS "/+"
292 %token CHORD_CARET "^"
293 %token CHORD_COLON ":"
294 %token CHORD_MINUS "-"
295 %token CHORD_SLASH "/"
296 %token ANGLE_OPEN "<"
297 %token ANGLE_CLOSE ">"
298 %token DOUBLE_ANGLE_OPEN "<<"
299 %token DOUBLE_ANGLE_CLOSE ">>"
300 %token E_BACKSLASH "\\"
301 %token E_EXCLAMATION "\\!"
306 If we give names, Bison complains.
308 %token FIGURE_CLOSE /* "\\>" */
309 %token FIGURE_OPEN /* "\\<" */
310 %token FIGURE_SPACE "_"
313 %token MULTI_MEASURE_REST
319 /* Artificial tokens, for more generic function syntax */
320 %token EXPECT_MARKUP "markup?"
321 %token EXPECT_SCM "scheme?"
322 %token BACKUP "(backed-up?)"
323 %token REPARSE "(reparsed?)"
324 %token EXPECT_MARKUP_LIST "markup-list?"
325 %token EXPECT_OPTIONAL "optional?"
326 /* After the last argument. */
327 %token EXPECT_NO_MORE_ARGS;
329 /* An artificial token for parsing embedded Lilypond */
330 %token EMBEDDED_LILY "#{"
332 %token BOOK_IDENTIFIER
333 %token CHORD_BODY_IDENTIFIER
334 %token CHORD_MODIFIER
335 %token CHORD_REPETITION
336 %token CONTEXT_DEF_IDENTIFIER
337 %token CONTEXT_MOD_IDENTIFIER
339 %token PITCH_IDENTIFIER
341 %token DURATION_IDENTIFIER
342 %token EVENT_IDENTIFIER
343 %token EVENT_FUNCTION
346 %token MARKUP_FUNCTION
347 %token MARKUP_LIST_FUNCTION
348 %token MARKUP_IDENTIFIER
349 %token MARKUPLIST_IDENTIFIER
350 %token MUSIC_FUNCTION
351 %token MUSIC_IDENTIFIER
352 %token NOTENAME_PITCH
353 %token NUMBER_IDENTIFIER
354 %token OUTPUT_DEF_IDENTIFIER
356 %token REPEAT_IDENTIFIER
360 %token SCM_IDENTIFIER
364 %token TONICNAME_PITCH
368 /* We don't assign precedence to / and *, because we might need varied
369 prec levels in different prods */
378 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
379 parser->lexer_->push_note_state (nn);
380 } embedded_lilypond {
381 parser->lexer_->pop_state ();
386 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
387 | lilypond toplevel_expression {
389 | lilypond assignment {
392 parser->error_level_ = 1;
395 parser->error_level_ = 1;
402 parser->lexer_->add_scope (get_header (parser));
404 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
407 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
408 scm_call_2 (proc, parser->self_scm (), $1);
411 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
412 scm_call_2 (proc, parser->self_scm (), $1);
415 SCM proc = parser->lexer_->lookup_identifier
416 (unsmob_book($1)->paper_
417 ? "toplevel-book-handler"
418 : "toplevel-bookpart-handler");
419 scm_call_2 (proc, parser->self_scm (), $1);
422 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
423 scm_call_2 (proc, parser->self_scm (), $1);
426 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
427 scm_call_2 (proc, parser->self_scm (), $1);
430 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
431 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
434 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
435 scm_call_2 (proc, parser->self_scm (), $1);
438 // Evaluate and ignore #xxx, as opposed to \xxx
439 parser->lexer_->eval_scm_token ($1);
441 | embedded_scm_active
443 SCM out = SCM_UNDEFINED;
444 if (Text_interface::is_markup ($1))
445 out = scm_list_1 ($1);
446 else if (Text_interface::is_markup_list ($1))
448 if (scm_is_pair (out))
450 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
451 scm_call_2 (proc, parser->self_scm (), out);
452 } else if (unsmob_score ($1))
454 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
455 scm_call_2 (proc, parser->self_scm (), $1);
456 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
457 parser->parser_error (@1, _("bad expression type"));
461 Output_def * od = unsmob_output_def ($1);
463 if (od->c_variable ("is-paper") == SCM_BOOL_T)
464 id = ly_symbol2scm ("$defaultpaper");
465 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
466 id = ly_symbol2scm ("$defaultmidi");
467 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
468 id = ly_symbol2scm ("$defaultlayout");
470 parser->lexer_->set_identifier (id, $1);
477 $$ = parser->lexer_->eval_scm_token ($1);
487 embedded_scm_bare_arg:
491 $$ = parser->lexer_->eval_scm_token ($1);
495 | context_modification
497 | context_def_spec_block
503 /* The generic version may end in music, or not */
510 /* embedded_scm_arg is _not_ casting pitches to music by default, this
511 * has to be done by the function itself. Note that this may cause
512 * the results of scm_function_call or embedded_scm_bare_arg to be
513 * turned into music from pitches as well. Note that this creates a
514 * distinctly awkward situation for calculated drum pitches. Those
515 * are at the current point of time rejected as music constituents as
516 * they can't be distinguished from "proper" symbols.
520 embedded_scm_bare_arg
526 SCM_FUNCTION function_arglist {
527 $$ = MAKE_SYNTAX ("music-function", @$,
532 embedded_lilypond_number:
533 '-' embedded_lilypond_number
535 $$ = scm_difference ($2, SCM_UNDEFINED);
538 | UNSIGNED NUMBER_IDENTIFIER
540 $$ = scm_product ($1, $2);
547 // FIXME: @$ does not contain a useful source location
548 // for empty rules, and the only token in the whole
549 // production, EMBEDDED_LILY, is synthetic and also
550 // contains no source location.
551 $$ = MAKE_SYNTAX ("void-music", @$);
553 | identifier_init_nonumber
554 | embedded_lilypond_number
555 | post_event post_events
557 $$ = scm_reverse_x ($2, SCM_EOL);
558 if (Music *m = unsmob_music ($1))
560 if (m->is_mus_type ("post-event-wrapper"))
562 (scm_list_2 (m->get_property ("elements"),
565 $$ = scm_cons ($1, $$);
568 && scm_is_null (scm_cdr ($$)))
572 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
573 m->set_property ("elements", $$);
574 $$ = m->unprotect ();
577 | multiplied_duration
578 | music_embedded music_embedded music_list {
579 $3 = scm_reverse_x ($3, SCM_EOL);
580 if (unsmob_music ($2))
581 $3 = scm_cons ($2, $3);
582 if (unsmob_music ($1))
583 $3 = scm_cons ($1, $3);
584 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
587 parser->error_level_ = 1;
588 $$ = SCM_UNSPECIFIED;
590 | INVALID embedded_lilypond {
591 parser->error_level_ = 1;
597 lilypond_header_body:
598 /* empty */ { $$ = SCM_UNSPECIFIED; }
599 | lilypond_header_body assignment {
602 | lilypond_header_body embedded_scm {
608 HEADER '{' lilypond_header_body '}' {
609 $$ = parser->lexer_->remove_scope ();
621 assignment_id '=' identifier_init {
622 parser->lexer_->set_identifier ($1, $3);
623 $$ = SCM_UNSPECIFIED;
625 | assignment_id property_path '=' identifier_init {
626 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
627 parser->lexer_->set_identifier (path, $4);
628 $$ = SCM_UNSPECIFIED;
634 identifier_init_nonumber
636 | post_event_nofinger post_events
638 $$ = scm_reverse_x ($2, SCM_EOL);
639 if (Music *m = unsmob_music ($1))
641 if (m->is_mus_type ("post-event-wrapper"))
643 (scm_list_2 (m->get_property ("elements"),
646 $$ = scm_cons ($1, $$);
649 && scm_is_null (scm_cdr ($$)))
653 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
654 m->set_property ("elements", $$);
655 $$ = m->unprotect ();
660 identifier_init_nonumber:
665 | context_def_spec_block
671 | context_modification
674 context_def_spec_block:
675 CONTEXT '{' context_def_spec_body '}'
678 unsmob_context_def ($$)->origin ()->set_spot (@$);
686 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
687 parser->lexer_->push_note_state (nn);
691 parser->lexer_->pop_state ();
696 context_mod_embedded:
699 if (unsmob_music ($1)) {
700 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
701 $1 = scm_call_2 (proc, parser->self_scm (), $1);
703 if (unsmob_context_mod ($1))
706 parser->parser_error (@1, _ ("not a context mod"));
707 $$ = Context_mod ().smobbed_copy ();
713 context_def_spec_body:
715 $$ = Context_def::make_scm ();
717 | CONTEXT_DEF_IDENTIFIER {
720 | context_def_spec_body context_mod {
721 if (!SCM_UNBNDP ($2))
722 unsmob_context_def ($$)->add_context_mod ($2);
724 | context_def_spec_body context_modification {
725 Context_def *td = unsmob_context_def ($$);
726 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
727 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
728 td->add_context_mod (scm_car (m));
731 | context_def_spec_body context_mod_embedded {
732 Context_def *td = unsmob_context_def ($$);
733 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
734 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
735 td->add_context_mod (scm_car (m));
743 BOOK '{' book_body '}' {
745 unsmob_book ($$)->origin ()->set_spot (@$);
747 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
752 * Use 'handlers' like for toplevel-* stuff?
753 * grok \layout and \midi? */
756 Book *book = new Book;
757 init_papers (parser);
758 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
759 book->paper_->unprotect ();
760 push_paper (parser, book->paper_);
761 book->header_ = get_header (parser);
762 $$ = book->unprotect ();
763 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
766 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
768 | book_body paper_block {
769 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
770 set_paper (parser, unsmob_output_def ($2));
772 | book_body bookpart_block {
773 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
774 scm_call_2 (proc, $1, $2);
776 | book_body score_block {
777 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
778 scm_call_2 (proc, $1, $2);
780 | book_body composite_music {
781 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
782 scm_call_3 (proc, parser->self_scm (), $1, $2);
784 | book_body full_markup {
785 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
786 scm_call_2 (proc, $1, scm_list_1 ($2));
788 | book_body full_markup_list {
789 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
790 scm_call_2 (proc, $1, $2);
792 | book_body SCM_TOKEN {
793 // Evaluate and ignore #xxx, as opposed to \xxx
794 parser->lexer_->eval_scm_token ($2);
796 | book_body embedded_scm_active
798 SCM out = SCM_UNDEFINED;
799 if (Text_interface::is_markup ($2))
800 out = scm_list_1 ($2);
801 else if (Text_interface::is_markup_list ($2))
803 if (scm_is_pair (out))
805 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
806 scm_call_2 (proc, $1, out);
807 } else if (unsmob_score ($2))
809 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
810 scm_call_2 (proc, $1, $2);
811 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
812 parser->parser_error (@2, _("bad expression type"));
816 parser->lexer_->add_scope (unsmob_book ($1)->header_);
819 Book *book = unsmob_book ($1);
821 book->scores_ = SCM_EOL;
822 book->bookparts_ = SCM_EOL;
827 BOOKPART '{' bookpart_body '}' {
829 unsmob_book ($$)->origin ()->set_spot (@$);
830 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
836 Book *book = new Book;
837 $$ = book->unprotect ();
838 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
841 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
843 | bookpart_body paper_block {
844 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
846 | bookpart_body score_block {
847 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
848 scm_call_2 (proc, $1, $2);
850 | bookpart_body composite_music {
851 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
852 scm_call_3 (proc, parser->self_scm (), $1, $2);
854 | bookpart_body full_markup {
855 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
856 scm_call_2 (proc, $1, scm_list_1 ($2));
858 | bookpart_body full_markup_list {
859 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
860 scm_call_2 (proc, $1, $2);
862 | bookpart_body SCM_TOKEN {
863 // Evaluate and ignore #xxx, as opposed to \xxx
864 parser->lexer_->eval_scm_token ($2);
866 | bookpart_body embedded_scm_active
868 SCM out = SCM_UNDEFINED;
869 if (Text_interface::is_markup ($2))
870 out = scm_list_1 ($2);
871 else if (Text_interface::is_markup_list ($2))
873 if (scm_is_pair (out))
875 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
876 scm_call_2 (proc, $1, out);
877 } else if (unsmob_score ($2))
879 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
880 scm_call_2 (proc, $1, $2);
881 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
882 parser->parser_error (@2, _("bad expression type"));
886 Book *book = unsmob_book ($1);
887 if (!ly_is_module (book->header_))
888 book->header_ = ly_make_module (false);
889 parser->lexer_->add_scope (book->header_);
891 | bookpart_body error {
892 Book *book = unsmob_book ($1);
894 book->scores_ = SCM_EOL;
899 SCORE '{' score_body '}' {
900 unsmob_score ($3)->origin ()->set_spot (@$);
912 if (!scm_is_pair ($1)
913 || !ly_is_module (scm_car ($1)))
914 $1 = scm_cons (ly_make_module (false), $1);
915 parser->lexer_->add_scope (scm_car ($1));
920 | score_headers output_def
922 Output_def *od = unsmob_output_def ($2);
923 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
925 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
930 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
931 scm_set_cdr_x ($1, scm_cons ($2, scm_cdr ($1)));
933 $$ = scm_cons ($2, $1);
941 score_headers music {
942 SCM scorify = ly_lily_module_constant ("scorify-music");
943 $$ = scm_call_2 (scorify, $2, parser->self_scm ());
945 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
947 unsmob_score ($$)->set_header (scm_car ($1));
950 for (SCM p = scm_reverse_x ($1, SCM_EOL);
951 scm_is_pair (p); p = scm_cdr (p))
954 add_output_def (unsmob_output_def (scm_car (p)));
957 | embedded_scm_active {
958 if (!unsmob_score ($1))
960 $$ = (new Score)->unprotect ();
961 parser->parser_error (@1, _("score expected"));
966 Score *score = unsmob_score ($1);
967 if (!ly_is_module (score->get_header ()))
968 score->set_header (ly_make_module (false));
969 parser->lexer_->add_scope (score->get_header ());
971 | score_body output_def {
972 Output_def *od = unsmob_output_def ($2);
973 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
975 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
980 unsmob_score ($1)->add_output_def (od);
984 unsmob_score ($$)->error_found_ = true;
995 Output_def *od = unsmob_output_def ($1);
997 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
999 parser->parser_error (@1, _ ("need \\paper for paper block"));
1000 $$ = get_paper (parser)->unprotect ();
1007 output_def_body '}' {
1010 parser->lexer_->remove_scope ();
1011 parser->lexer_->pop_state ();
1017 Output_def *p = get_paper (parser);
1018 p->input_origin_ = @$;
1019 parser->lexer_->add_scope (p->scope_);
1020 $$ = p->unprotect ();
1023 Output_def *p = get_midi (parser);
1024 $$ = p->unprotect ();
1025 parser->lexer_->add_scope (p->scope_);
1028 Output_def *p = get_layout (parser);
1030 parser->lexer_->add_scope (p->scope_);
1031 $$ = p->unprotect ();
1035 output_def_head_with_mode_switch:
1037 parser->lexer_->push_initial_state ();
1042 // We need this weird nonterminal because both music as well as a
1043 // context definition can start with \context and the difference is
1044 // only apparent after looking at the next token. If it is '{', there
1045 // is still time to escape from notes mode.
1047 music_or_context_def:
1049 | context_def_spec_block
1053 output_def_head_with_mode_switch '{' {
1055 unsmob_output_def ($$)->input_origin_.set_spot (@$);
1057 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1058 Output_def *o = unsmob_output_def ($3);
1059 o->input_origin_.set_spot (@$);
1060 $$ = o->self_scm ();
1061 parser->lexer_->remove_scope ();
1062 parser->lexer_->add_scope (o->scope_);
1064 | output_def_body assignment {
1067 | output_def_body embedded_scm {
1072 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1073 parser->lexer_->push_note_state (nn);
1074 } music_or_context_def
1076 parser->lexer_->pop_state ();
1077 if (unsmob_context_def ($3))
1078 assign_context_def (unsmob_output_def ($1), $3);
1081 SCM proc = parser->lexer_->lookup_identifier
1082 ("output-def-music-handler");
1083 scm_call_3 (proc, parser->self_scm (),
1087 | output_def_body error {
1093 TEMPO steno_duration '=' tempo_range {
1094 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1096 | TEMPO scalar steno_duration '=' tempo_range {
1097 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1100 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1105 The representation of a list is reversed to have efficient append. */
1111 | music_list music_embedded {
1112 if (unsmob_music ($2))
1113 $$ = scm_cons ($2, $1);
1115 | music_list error {
1116 Music *m = MY_MAKE_MUSIC("Music", @$);
1118 m->set_property ("error-found", SCM_BOOL_T);
1119 $$ = scm_cons (m->self_scm (), $1);
1120 m->unprotect (); /* UGH */
1127 $$ = scm_reverse_x ($2, SCM_EOL);
1132 | lyric_element_music
1138 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1139 parser->parser_error (@1, _ ("unexpected post-event"));
1140 $$ = SCM_UNSPECIFIED;
1143 | music_embedded_backup
1147 | music_embedded_backup BACKUP lyric_element_music
1151 | multiplied_duration post_events
1153 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1155 parser->default_duration_ = *unsmob_duration ($1);
1156 n->set_property ("duration", $1);
1158 if (scm_is_pair ($2))
1159 n->set_property ("articulations",
1160 scm_reverse_x ($2, SCM_EOL));
1161 $$ = n->unprotect ();
1165 music_embedded_backup:
1168 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1170 else if (Music *m = unsmob_music ($1)) {
1171 if (m->is_mus_type ("post-event")) {
1172 parser->parser_error
1173 (@1, _ ("unexpected post-event"));
1174 $$ = SCM_UNSPECIFIED;
1177 } else if (parser->lexer_->is_lyric_state ()
1178 && Text_interface::is_markup ($1))
1179 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1181 @$.warning (_ ("Ignoring non-music expression"));
1190 $$ = make_music_from_simple (parser, @1, $1);
1191 if (!unsmob_music ($$))
1193 parser->parser_error (@1, _ ("music expected"));
1194 $$ = MAKE_SYNTAX ("void-music", @$);
1197 | composite_music %prec COMPOSITE
1202 | composite_music %prec COMPOSITE
1206 REPEAT simple_string unsigned_number music
1208 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1210 | REPEAT_IDENTIFIER music
1212 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1215 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1217 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1219 | REPEAT_IDENTIFIER music ALTERNATIVE braced_music_list
1221 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1227 SEQUENTIAL braced_music_list {
1228 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1230 | braced_music_list {
1231 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1236 SIMULTANEOUS braced_music_list {
1237 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1239 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1240 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1246 | music_property_def
1250 context_modification:
1253 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1254 parser->lexer_->push_note_state (nn);
1255 } '{' context_mod_list '}'
1257 parser->lexer_->pop_state ();
1260 | WITH CONTEXT_MOD_IDENTIFIER
1264 | CONTEXT_MOD_IDENTIFIER
1268 | WITH context_modification_arg
1270 if (unsmob_music ($2)) {
1271 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1272 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1274 if (unsmob_context_mod ($2))
1277 parser->parser_error (@2, _ ("not a context mod"));
1278 $$ = Context_mod ().smobbed_copy ();
1283 context_modification_arg:
1288 optional_context_mod:
1292 | context_modification
1300 $$ = Context_mod ().smobbed_copy ();
1302 | context_mod_list context_mod {
1303 if (!SCM_UNBNDP ($2))
1304 unsmob_context_mod ($1)->add_context_mod ($2);
1306 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1307 Context_mod *md = unsmob_context_mod ($2);
1309 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1311 | context_mod_list context_mod_embedded {
1312 unsmob_context_mod ($1)->add_context_mods
1313 (unsmob_context_mod ($2)->get_mods ());
1322 /* Music that can be parsed without lookahead */
1325 | complex_music_prefix closed_music
1327 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1329 | music_function_call_closed
1335 | grouped_music_list
1339 simultaneous_music { $$ = $1; }
1340 | sequential_music { $$ = $1; }
1343 /* Function argument lists are arguably the most complex part in the
1344 * parser. They are pretty tricky to understand because of the way
1345 * they are processed, and because of optional arguments that can be
1346 * omitted. When there are several optional arguments in a row,
1347 * omitting one automatically omits all following arguments. Optional
1348 * arguments can only be omitted when either
1350 * a) the omission is explicitly started with \default
1351 * b) the omission is implicitly started by an argument not matching
1352 * its predicate, and there is a mandatory argument later that can
1353 * "catch" the argument that does not fit.
1355 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1356 * (corresponding to mandatory arguments and having a predicate
1357 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1358 * the semantic value of the EXPECT_OPTIONAL token is the default to
1359 * use when the optional argument is omitted, and EXPECT_SCM again has
1360 * the argument predicate as semantic value) in reverse order to the
1361 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1362 * processed inside-out while actual tokens are consumed.
1364 * This means that the argument list tokens determine the actions
1365 * taken as they arrive. The structure of the argument list is known
1366 * to the parser and stored in its parse stack when the first argument
1367 * is being parsed. What the parser does not know is which predicates
1368 * will match and whether or not \default will be appearing in the
1369 * argument list, and where.
1371 * Many of the basic nonterminals used for argument list scanning come
1372 * in a "normal" and a "closed" flavor. A closed expression is one
1373 * that can be parsed without a lookahead token. That makes it
1374 * feasible for an optional argument that may need to be skipped:
1375 * skipping can only be accomplished by pushing back the token into
1376 * the lexer, and that only works when there is no lookahead token.
1378 * Sequences of 0 or more optional arguments are scanned using either
1379 * function_arglist_backup or function_arglist_nonbackup. The first
1380 * is used when optional arguments are followed by at least one
1381 * mandatory argument: in that case optional arguments may be skipped
1382 * by either a false predicate (in which case the expression will be
1383 * pushed back as one or more tokens, preceded by a BACKUP token) or
1384 * by using \default.
1386 * If optional arguments are at the end of the argument list, they are
1387 * instead scanned using function_arglist_nonbackup: here the only
1388 * manner to enter into skipping of optional arguments is the use of
1391 * The argument list of a normal function call is parsed using
1392 * function_arglist. The part of an argument list before a mandatory
1393 * argument is parsed using function_arglist_optional.
1395 * The difference is that leading optional arguments are scanned using
1396 * function_arglist_nonbackup and function_arglist_backup,
1399 * Most other details are obvious in the rules themselves.
1403 function_arglist_nonbackup_common:
1404 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1406 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1408 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1410 SCM n = scm_difference ($5, SCM_UNDEFINED);
1411 if (scm_is_true (scm_call_1 ($2, n)))
1412 $$ = scm_cons (n, $3);
1414 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1415 t->set_property ("digit", $5);
1416 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1421 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1423 $$ = check_scheme_arg (parser, @4,
1424 scm_difference ($5, SCM_UNDEFINED),
1427 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1429 $$ = check_scheme_arg (parser, @4,
1430 scm_difference ($5, SCM_UNDEFINED),
1435 function_arglist_closed_nonbackup:
1436 function_arglist_nonbackup_common
1437 | function_arglist_closed_common
1438 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg_closed
1440 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1442 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_closed
1444 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1446 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1448 $$ = check_scheme_arg (parser, @4,
1449 try_string_variants ($2, $4),
1452 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1454 $$ = check_scheme_arg (parser, @4,
1455 try_string_variants ($2, $4),
1458 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1460 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1466 | SYMBOL_LIST '.' symbol_list_rev
1468 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1474 | symbol_list_rev '.' symbol_list_part
1476 $$ = scm_append_x (scm_list_2 ($3, $1));
1480 // symbol_list_part delivers elements in reverse copy.
1485 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1486 $$ = try_string_variants (sym_l_p, $1);
1487 if (SCM_UNBNDP ($$)) {
1488 parser->parser_error (@1, _("not a symbol"));
1491 $$ = scm_reverse ($$);
1496 symbol_list_element:
1502 function_arglist_nonbackup:
1503 function_arglist_nonbackup_common
1504 | function_arglist_common
1505 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1507 if (scm_is_true (scm_call_1 ($2, $4)))
1508 $$ = scm_cons ($4, $3);
1510 $$ = check_scheme_arg (parser, @4,
1511 make_music_from_simple
1515 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1517 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1519 | function_arglist_nonbackup_reparse REPARSE duration_length
1521 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1523 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1525 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1527 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1529 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1531 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1533 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1535 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1537 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1541 function_arglist_nonbackup_reparse:
1542 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1545 SCM res = try_string_variants ($2, $4);
1546 if (!SCM_UNBNDP (res))
1547 if (scm_is_pair (res))
1548 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1550 MYREPARSE (@4, $2, SCM_ARG, res);
1551 else if (scm_is_true
1553 ($2, make_music_from_simple
1555 MYREPARSE (@4, $2, STRING, $4);
1557 MYREPARSE (@4, $2, SCM_ARG, $4);
1559 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1562 SCM res = try_string_variants ($2, $4);
1563 if (!SCM_UNBNDP (res))
1564 if (scm_is_pair (res))
1565 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1567 MYREPARSE (@4, $2, SCM_ARG, res);
1568 else if (scm_is_true
1570 ($2, make_music_from_simple
1572 MYREPARSE (@4, $2, STRING, $4);
1574 MYREPARSE (@4, $2, SCM_ARG, $4);
1576 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1579 if (scm_is_true (scm_call_1 ($2, $4)))
1580 MYREPARSE (@4, $2, SCM_ARG, $4);
1581 else if (scm_is_true
1583 ($2, make_music_from_simple
1585 MYREPARSE (@4, $2, STRING, $4);
1587 MYREPARSE (@4, $2, SCM_ARG, $4);
1589 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1592 if (scm_is_true (scm_call_1 ($2, $4)))
1593 MYREPARSE (@4, $2, REAL, $4);
1595 SCM d = make_duration ($4);
1596 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1597 MYREPARSE (@4, $2, REAL, $4); // trigger error
1599 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1602 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1604 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1609 // function_arglist_backup can't occur at the end of an argument
1610 // list. It needs to be careful about avoiding lookahead only until
1611 // it has made a decision whether or not to accept the parsed entity.
1612 // At that point of time, music requiring lookahead to parse becomes
1614 function_arglist_backup:
1615 function_arglist_common
1616 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg_closed
1618 if (scm_is_true (scm_call_1 ($2, $4)))
1620 $$ = scm_cons ($4, $3);
1622 $$ = scm_cons (loc_on_music (@3, $1), $3);
1623 MYBACKUP (SCM_ARG, $4, @4);
1626 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REPEAT simple_string unsigned_number
1628 $4 = MAKE_SYNTAX ("repeat", @4, $5, $6,
1629 MY_MAKE_MUSIC ("Music", @4)->unprotect (),
1631 if (scm_is_true (scm_call_1 ($2, $4)))
1634 MYREPARSE (@4, $2, REPEAT_IDENTIFIER, scm_cons ($5, $6));
1636 $$ = scm_cons (loc_on_music (@3, $1), $3);
1637 MYBACKUP (REPEAT_IDENTIFIER, scm_cons ($5, $6), @4);
1640 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup chord_body
1642 if (scm_is_true (scm_call_1 ($2, $4)))
1645 MYREPARSE (@4, $2, CHORD_BODY_IDENTIFIER, $4);
1647 $$ = scm_cons (loc_on_music (@3, $1), $3);
1648 MYBACKUP (CHORD_BODY_IDENTIFIER, $4, @4);
1651 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1653 if (scm_is_true (scm_call_1 ($2, $4)))
1655 $$ = scm_cons ($4, $3);
1657 $$ = scm_cons (loc_on_music (@3, $1), $3);
1658 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1661 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1663 if (scm_is_true (scm_call_1 ($2, $4)))
1664 $$ = scm_cons ($4, $3);
1666 $$ = scm_cons (loc_on_music (@3, $1), $3);
1667 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1670 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1672 if (scm_is_true (scm_call_1 ($2, $4)))
1674 MYREPARSE (@4, $2, REAL, $4);
1677 SCM d = make_duration ($4);
1678 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1680 $$ = scm_cons (loc_on_music (@3, $1), $3);
1681 MYBACKUP (UNSIGNED, $4, @4);
1683 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1688 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1690 if (scm_is_true (scm_call_1 ($2, $4)))
1693 MYREPARSE (@4, $2, REAL, $4);
1695 $$ = scm_cons (loc_on_music (@3, $1), $3);
1696 MYBACKUP (REAL, $4, @4);
1699 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1701 if (scm_is_true (scm_call_1 ($2, $4)))
1703 $$ = scm_cons ($4, $3);
1705 $$ = scm_cons (loc_on_music (@3, $1), $3);
1706 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1709 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1711 SCM n = scm_difference ($5, SCM_UNDEFINED);
1712 if (scm_is_true (scm_call_1 ($2, n))) {
1714 MYREPARSE (@5, $2, REAL, n);
1716 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1717 t->set_property ("digit", $5);
1718 $$ = t->unprotect ();
1719 if (scm_is_true (scm_call_1 ($2, $$)))
1720 $$ = scm_cons ($$, $3);
1722 $$ = scm_cons (loc_on_music (@3, $1), $3);
1723 MYBACKUP (UNSIGNED, $5, @5);
1724 parser->lexer_->push_extra_token (@4, '-');
1729 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1731 SCM n = scm_difference ($5, SCM_UNDEFINED);
1732 if (scm_is_true (scm_call_1 ($2, n))) {
1733 MYREPARSE (@5, $2, REAL, n);
1736 $$ = scm_cons (loc_on_music (@3, $1), $3);
1737 MYBACKUP (REAL, n, @5);
1740 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1742 SCM n = scm_difference ($5, SCM_UNDEFINED);
1743 if (scm_is_true (scm_call_1 ($2, n))) {
1744 $$ = scm_cons (n, $3);
1746 $$ = scm_cons (loc_on_music (@3, $1), $3);
1747 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1750 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup PITCH_IDENTIFIER
1752 SCM m = make_music_from_simple (parser, @4, $4);
1753 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1755 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1757 } else if (scm_is_true (scm_call_1 ($2, $4)))
1759 MYREPARSE (@4, $2, PITCH_ARG, $4);
1762 $$ = scm_cons (loc_on_music (@3, $1), $3);
1763 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1766 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NOTENAME_PITCH
1768 SCM m = make_music_from_simple (parser, @4, $4);
1769 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1771 MYREPARSE (@4, $2, NOTENAME_PITCH, $4);
1773 } else if (scm_is_true (scm_call_1 ($2, $4)))
1775 MYREPARSE (@4, $2, PITCH_ARG, $4);
1778 $$ = scm_cons (loc_on_music (@3, $1), $3);
1779 MYBACKUP (NOTENAME_PITCH, $4, @4);
1782 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup TONICNAME_PITCH
1784 SCM m = make_music_from_simple (parser, @4, $4);
1785 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1787 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1789 } else if (scm_is_true (scm_call_1 ($2, $4)))
1791 MYREPARSE (@4, $2, PITCH_ARG, $4);
1794 $$ = scm_cons (loc_on_music (@3, $1), $3);
1795 MYBACKUP (TONICNAME_PITCH, $4, @4);
1798 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1800 if (scm_is_true (scm_call_1 ($2, $4)))
1802 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1805 $$ = scm_cons (loc_on_music (@3, $1), $3);
1806 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1809 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1811 SCM res = try_string_variants ($2, $4);
1812 if (!SCM_UNBNDP (res))
1813 if (scm_is_pair (res)) {
1815 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1818 $$ = scm_cons (res, $3);
1820 $$ = scm_cons (loc_on_music (@3, $1), $3);
1821 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1824 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1826 SCM res = try_string_variants ($2, $4);
1827 if (!SCM_UNBNDP (res))
1828 if (scm_is_pair (res)) {
1830 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1833 $$ = scm_cons (res, $3);
1835 $$ = scm_cons (loc_on_music (@3, $1), $3);
1836 MYBACKUP (STRING, $4, @4);
1839 | function_arglist_backup REPARSE music_assign
1841 if (scm_is_true (scm_call_1 ($2, $3)))
1842 $$ = scm_cons ($3, $1);
1844 $$ = check_scheme_arg (parser, @3,
1845 make_music_from_simple
1849 | function_arglist_backup REPARSE pitch_arg
1851 $$ = check_scheme_arg (parser, @3,
1854 | function_arglist_backup REPARSE bare_number_common
1856 $$ = check_scheme_arg (parser, @3,
1859 | function_arglist_backup REPARSE duration_length
1861 $$ = check_scheme_arg (parser, @3,
1864 | function_arglist_backup REPARSE symbol_list_arg
1866 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1871 function_arglist_nonbackup
1872 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1874 $$ = scm_cons (loc_on_music (@4, $1), $3);
1878 function_arglist_skip_nonbackup:
1879 function_arglist_nonbackup
1880 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1882 $$ = scm_cons (loc_on_music (@3, $1), $3);
1886 function_arglist_common:
1887 EXPECT_NO_MORE_ARGS {
1890 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1892 if (scm_is_true (scm_call_1 ($1, $3)))
1893 $$ = scm_cons ($3, $2);
1895 $$ = check_scheme_arg (parser, @3,
1896 make_music_from_simple
1900 | EXPECT_SCM function_arglist_optional bare_number_common
1902 $$ = check_scheme_arg (parser, @3,
1905 | EXPECT_SCM function_arglist_optional post_event_nofinger
1907 $$ = check_scheme_arg (parser, @3,
1910 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1912 SCM n = scm_difference ($4, SCM_UNDEFINED);
1913 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1915 | function_arglist_common_reparse REPARSE SCM_ARG
1917 $$ = check_scheme_arg (parser, @3,
1920 | function_arglist_common_reparse REPARSE lyric_element_music
1922 $$ = check_scheme_arg (parser, @3,
1925 | function_arglist_common_reparse REPARSE bare_number_common
1927 $$ = check_scheme_arg (parser, @3,
1930 | function_arglist_common_reparse REPARSE duration_length
1932 $$ = check_scheme_arg (parser, @3,
1935 | function_arglist_common_reparse REPARSE symbol_list_arg
1937 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1941 function_arglist_common_reparse:
1942 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1945 SCM res = try_string_variants ($1, $3);
1946 if (!SCM_UNBNDP (res))
1947 if (scm_is_pair (res))
1948 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1950 MYREPARSE (@3, $1, SCM_ARG, res);
1951 else if (scm_is_true
1953 ($1, make_music_from_simple (parser, @3, $3))))
1954 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1956 // This is going to flag a syntax error, we
1957 // know the predicate to be false.
1958 MYREPARSE (@3, $1, SCM_ARG, $3);
1960 | EXPECT_SCM function_arglist_optional STRING
1963 SCM res = try_string_variants ($1, $3);
1964 if (!SCM_UNBNDP (res))
1965 if (scm_is_pair (res))
1966 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1968 MYREPARSE (@3, $1, SCM_ARG, res);
1969 else if (scm_is_true
1971 ($1, make_music_from_simple (parser, @3, $3))))
1972 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1974 // This is going to flag a syntax error, we
1975 // know the predicate to be false.
1976 MYREPARSE (@3, $1, SCM_ARG, $3);
1978 | EXPECT_SCM function_arglist_optional full_markup
1981 if (scm_is_true (scm_call_1 ($1, $3)))
1982 MYREPARSE (@3, $1, SCM_ARG, $3);
1983 else if (scm_is_true
1985 ($1, make_music_from_simple (parser, @3, $3))))
1986 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1988 // This is going to flag a syntax error, we
1989 // know the predicate to be false.
1990 MYREPARSE (@3, $1, SCM_ARG, $3);
1992 | EXPECT_SCM function_arglist_optional UNSIGNED
1995 if (scm_is_true (scm_call_1 ($1, $3)))
1996 MYREPARSE (@3, $1, REAL, $3);
1998 SCM d = make_duration ($3);
1999 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
2000 MYREPARSE (@3, $1, REAL, $3);
2002 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2005 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2008 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2010 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2013 SCM n = scm_difference ($4, SCM_UNDEFINED);
2014 if (scm_is_true (scm_call_1 ($1, n)))
2015 MYREPARSE (@4, $1, REAL, n);
2017 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2018 t->set_property ("digit", $4);
2019 SCM m = t->unprotect ();
2020 if (scm_is_true (scm_call_1 ($1, m)))
2021 MYREPARSE (@4, $1, SCM_ARG, m);
2023 MYREPARSE (@4, $1, SCM_ARG, $4);
2027 | EXPECT_SCM function_arglist_optional '-' REAL
2030 SCM n = scm_difference ($4, SCM_UNDEFINED);
2031 MYREPARSE (@4, $1, REAL, n);
2035 function_arglist_closed:
2036 function_arglist_closed_nonbackup
2037 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2039 $$ = scm_cons (loc_on_music (@4, $1), $3);
2043 function_arglist_closed_common:
2044 EXPECT_NO_MORE_ARGS {
2047 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
2049 $$ = check_scheme_arg (parser, @3,
2052 | EXPECT_SCM function_arglist_optional bare_number_common_closed
2054 $$ = check_scheme_arg (parser, @3,
2057 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2059 $$ = check_scheme_arg (parser, @3,
2060 scm_difference ($4, SCM_UNDEFINED),
2063 | EXPECT_SCM function_arglist_optional post_event_nofinger
2065 $$ = check_scheme_arg (parser, @3,
2068 | function_arglist_common_reparse REPARSE SCM_ARG
2070 $$ = check_scheme_arg (parser, @3,
2073 | function_arglist_common_reparse REPARSE bare_number_common_closed
2075 $$ = check_scheme_arg (parser, @3,
2078 | function_arglist_common_reparse REPARSE symbol_list_arg
2080 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2084 function_arglist_optional:
2085 function_arglist_backup
2086 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2088 $$ = scm_cons (loc_on_music (@4, $1), $3);
2090 | function_arglist_skip_backup BACKUP
2093 function_arglist_skip_backup:
2094 function_arglist_backup
2095 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2097 $$ = scm_cons (loc_on_music (@3, $1), $3);
2101 embedded_scm_closed:
2103 | scm_function_call_closed
2106 embedded_scm_arg_closed:
2107 embedded_scm_bare_arg
2108 | scm_function_call_closed
2112 scm_function_call_closed:
2113 SCM_FUNCTION function_arglist_closed {
2114 $$ = MAKE_SYNTAX ("music-function", @$,
2119 music_function_call:
2120 MUSIC_FUNCTION function_arglist {
2121 $$ = MAKE_SYNTAX ("music-function", @$,
2128 /**/ { $$ = SCM_EOL; }
2129 | '=' simple_string {
2136 | repeated_music { $$ = $1; }
2137 | re_rhythmed_music { $$ = $1; }
2138 | complex_music_prefix music
2140 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2144 complex_music_prefix:
2145 CONTEXT symbol optional_id optional_context_mod {
2146 Context_mod *ctxmod = unsmob_context_mod ($4);
2149 mods = ctxmod->get_mods ();
2150 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2152 | NEWCONTEXT symbol optional_id optional_context_mod {
2153 Context_mod *ctxmod = unsmob_context_mod ($4);
2156 mods = ctxmod->get_mods ();
2157 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2162 mode_changing_head grouped_music_list {
2163 if ($1 == ly_symbol2scm ("chords"))
2165 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2171 parser->lexer_->pop_state ();
2173 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2174 Context_mod *ctxmod = unsmob_context_mod ($2);
2177 mods = ctxmod->get_mods ();
2178 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2179 if ($1 == ly_symbol2scm ("ChordNames"))
2181 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2183 parser->lexer_->pop_state ();
2189 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2190 parser->lexer_->push_note_state (nn);
2192 $$ = ly_symbol2scm ("notes");
2196 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2197 parser->lexer_->push_note_state (nn);
2199 $$ = ly_symbol2scm ("drums");
2202 parser->lexer_->push_figuredbass_state ();
2204 $$ = ly_symbol2scm ("figures");
2207 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2208 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2209 nn = parser->lexer_->lookup_identifier ("pitchnames");
2210 parser->lexer_->push_chord_state (nn);
2211 $$ = ly_symbol2scm ("chords");
2215 { parser->lexer_->push_lyric_state ();
2216 $$ = ly_symbol2scm ("lyrics");
2220 mode_changing_head_with_context:
2222 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2223 parser->lexer_->push_note_state (nn);
2225 $$ = ly_symbol2scm ("DrumStaff");
2228 parser->lexer_->push_figuredbass_state ();
2230 $$ = ly_symbol2scm ("FiguredBass");
2233 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2234 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2235 nn = parser->lexer_->lookup_identifier ("pitchnames");
2236 parser->lexer_->push_chord_state (nn);
2237 $$ = ly_symbol2scm ("ChordNames");
2240 { parser->lexer_->push_lyric_state ();
2241 $$ = ly_symbol2scm ("Lyrics");
2246 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2249 /* Can also use music at the expensive of two S/Rs similar to
2250 \repeat \alternative */
2251 parser->lexer_->pop_state ();
2253 $$ = scm_cons ($3, SCM_EOL);
2255 | new_lyrics ADDLYRICS {
2256 parser->lexer_->push_lyric_state ();
2258 parser->lexer_->pop_state ();
2259 $$ = scm_cons ($4, $1);
2264 composite_music new_lyrics {
2265 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2267 | LYRICSTO simple_string {
2268 parser->lexer_->push_lyric_state ();
2270 parser->lexer_->pop_state ();
2271 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2276 CHANGE symbol '=' simple_string {
2277 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2284 $$ = scm_reverse_x ($1, SCM_EOL);
2286 | symbol_list_rev property_path {
2287 $$ = scm_reverse_x ($1, $2);
2293 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2296 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2298 | OVERRIDE property_path '=' scalar {
2299 if (scm_ilength ($2) < 2) {
2300 parser->parser_error (@2, _("bad grob property path"));
2303 $$ = scm_cons (ly_symbol2scm ("push"),
2304 scm_cons2 (scm_car ($2),
2309 | REVERT revert_arg {
2310 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2314 // This is all quite awkward for the sake of substantial backward
2315 // compatibility while at the same time allowing a more "natural" form
2316 // of specification not separating grob specification from grob
2317 // property path. The purpose of this definition of revert_arg is to
2318 // allow the symbol list which specifies grob and property to revert
2319 // to be optionally be split into two parts after the grob (which in
2320 // this case is just the first element of the list). symbol_list_part
2321 // is only one path component, but it can be parsed without lookahead,
2322 // so we can follow it with a synthetic BACKUP token when needed. If
2323 // the first symbol_list_part already contains multiple elements (only
2324 // possible if a Scheme expression provides them), we just parse for
2325 // additional elements introduced by '.', which is what the
2326 // SYMBOL_LIST backup in connection with the immediately following
2327 // rule using symbol_list_arg does.
2329 // As long as we don't have our coffers filled with both grob and at
2330 // least one grob property specification, the rest of the required
2331 // symbol list chain may be provided either with or without a leading
2332 // dot. This is for both allowing the traditional
2333 // \revert Accidental #'color
2334 // as well as well as the "naive" form
2335 // \revert Accidental.color
2338 revert_arg_backup BACKUP symbol_list_arg
2347 if (scm_is_null ($1)
2348 || scm_is_null (scm_cdr ($1)))
2349 MYBACKUP (SCM_ARG, $1, @1);
2351 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2355 // revert_arg_part delivers results in reverse
2358 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2360 $$ = scm_append_x (scm_list_2 ($5, $3));
2362 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2364 $$ = scm_append_x (scm_list_2 ($4, $3));
2369 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2370 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2372 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2373 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2374 | DENIES { $$ = ly_symbol2scm ("denies"); }
2376 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2377 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2378 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2379 | NAME { $$ = ly_symbol2scm ("context-name"); }
2383 property_operation { $$ = $1; }
2384 | context_def_mod STRING {
2385 $$ = scm_list_2 ($1, $2);
2387 | context_def_mod embedded_scm
2389 if (!scm_is_string ($2)
2390 && ly_symbol2scm ("consists") != $1
2391 && ly_symbol2scm ("remove") != $1)
2394 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2398 $$ = scm_list_2 ($1, $2);
2403 // If defined, at least two members.
2407 SCM l = scm_reverse_x ($1, SCM_EOL);
2410 (scm_object_property (scm_car (l),
2411 ly_symbol2scm ("is-grob?"))))
2412 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2413 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2414 parser->parser_error (@1, _ ("bad grob property path"));
2421 // If defined, at least three members
2425 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2427 parser->parser_error (@1, _ ("bad grob property path"));
2431 | grob_prop_spec property_path
2433 if (!SCM_UNBNDP ($1)) {
2434 $$ = scm_append_x (scm_list_2 ($1, $2));
2435 if (scm_is_null (scm_cddr ($$))) {
2436 parser->parser_error (@$, _ ("bad grob property path"));
2444 // Exactly two elements or undefined
2448 SCM l = scm_reverse_x ($1, SCM_EOL);
2449 switch (scm_ilength (l)) {
2451 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2455 parser->parser_error (@1, _ ("bad context property path"));
2462 simple_music_property_def:
2463 OVERRIDE grob_prop_path '=' scalar {
2464 if (SCM_UNBNDP ($2))
2467 $$ = scm_list_5 (scm_car ($2),
2468 ly_symbol2scm ("OverrideProperty"),
2474 | REVERT simple_revert_context revert_arg {
2475 $$ = scm_list_4 ($2,
2476 ly_symbol2scm ("RevertProperty"),
2480 | SET context_prop_spec '=' scalar {
2481 if (SCM_UNBNDP ($2))
2484 $$ = scm_list_4 (scm_car ($2),
2485 ly_symbol2scm ("PropertySet"),
2489 | UNSET context_prop_spec {
2490 if (SCM_UNBNDP ($2))
2493 $$ = scm_list_3 (scm_car ($2),
2494 ly_symbol2scm ("PropertyUnset"),
2500 // This is all quite awkward for the sake of substantial backward
2501 // compatibility while at the same time allowing a more "natural" form
2502 // of specification not separating grob specification from grob
2503 // property path. The purpose of this definition of
2504 // simple_revert_context is to allow the symbol list which specifies
2505 // grob and property to revert to be optionally be split into two
2506 // parts after the grob (which may be preceded by a context
2507 // specification, a case which we distinguish by checking whether the
2508 // first symbol is a valid grob symbol instead).
2510 // See revert_arg above for the main work horse of this arrangement.
2511 // simple_revert_context just caters for the context and delegates the
2512 // rest of the job to revert_arg.
2514 simple_revert_context:
2517 $1 = scm_reverse_x ($1, SCM_EOL);
2518 if (scm_is_null ($1)
2520 (scm_object_property (scm_car ($1),
2521 ly_symbol2scm ("is-grob?")))) {
2522 $$ = ly_symbol2scm ("Bottom");
2523 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2526 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2533 simple_music_property_def {
2534 if (SCM_UNBNDP ($1))
2535 $$ = MAKE_SYNTAX ("void-music", @1);
2537 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2548 simple_string: STRING {
2553 if (scm_is_string ($1)) {
2556 parser->parser_error (@1, (_ ("simple string expected")));
2557 $$ = scm_string (SCM_EOL);
2564 $$ = scm_string_to_symbol ($1);
2568 // This is a bit of overkill but makes the same
2569 // routine responsible for all symbol interpretations.
2570 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2572 if (SCM_UNBNDP ($$))
2574 parser->parser_error (@1, (_ ("symbol expected")));
2575 // Generate a unique symbol in case it is used
2576 // for an assignment or similar
2577 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2586 // The following is a rather defensive variant of admitting
2587 // negative numbers: the grammar would permit number_factor or
2588 // even number_expression. However, function arguments allow
2589 // only this simple kind of negative number, so to have things
2590 // like \tweak and \override behave reasonably similar, it
2591 // makes sense to rule out things like -- which are rather an
2592 // accent in function argument contexts.
2595 $$ = scm_difference ($2, SCM_UNDEFINED);
2602 simple_element post_events {
2603 // Let the rhythmic music iterator sort this mess out.
2604 if (scm_is_pair ($2)) {
2605 $$ = make_music_from_simple (parser, @1, $1);
2606 if (unsmob_music ($$))
2607 unsmob_music ($$)->set_property ("articulations",
2608 scm_reverse_x ($2, SCM_EOL));
2611 parser->parser_error (@1, _("music expected"));
2612 $$ = MAKE_SYNTAX ("void-music", @1);
2616 | simple_chord_elements post_events {
2617 if (scm_is_pair ($2)) {
2618 if (unsmob_pitch ($1))
2619 $1 = make_chord_elements (@1,
2621 parser->default_duration_.smobbed_copy (),
2624 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2626 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
2627 } else if (!unsmob_pitch ($1))
2628 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
2629 // A mere pitch drops through.
2631 | CHORD_REPETITION optional_notemode_duration post_events {
2633 i.set_location (@1, @3);
2634 $$ = MAKE_SYNTAX ("repetition-chord", i,
2635 $2, scm_reverse_x ($3, SCM_EOL));
2637 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2639 i.set_location (@1, @3);
2640 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2641 scm_reverse_x ($3, SCM_EOL));
2644 | note_chord_element
2649 chord_body optional_notemode_duration post_events
2651 Music *m = unsmob_music ($1);
2652 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2653 SCM es = m->get_property ("elements");
2654 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2656 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2657 unsmob_music (scm_car (s))->set_property ("duration", dur);
2658 es = ly_append2 (es, postevs);
2660 m-> set_property ("elements", es);
2662 $$ = m->self_scm ();
2667 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2669 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2671 | CHORD_BODY_IDENTIFIER
2674 chord_body_elements:
2675 /* empty */ { $$ = SCM_EOL; }
2676 | chord_body_elements chord_body_element {
2677 if (!SCM_UNBNDP ($2))
2678 $$ = scm_cons ($2, $1);
2683 pitch exclamations questions octave_check post_events
2685 bool q = to_boolean ($3);
2686 bool ex = to_boolean ($2);
2690 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2691 n->set_property ("pitch", $1);
2693 n->set_property ("cautionary", SCM_BOOL_T);
2695 n->set_property ("force-accidental", SCM_BOOL_T);
2697 if (scm_is_pair (post)) {
2698 SCM arts = scm_reverse_x (post, SCM_EOL);
2699 n->set_property ("articulations", arts);
2701 if (scm_is_number (check))
2703 int q = scm_to_int (check);
2704 n->set_property ("absolute-octave", scm_from_int (q-1));
2707 $$ = n->unprotect ();
2709 | DRUM_PITCH post_events {
2710 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2711 n->set_property ("drum-type", $1);
2713 if (scm_is_pair ($2)) {
2714 SCM arts = scm_reverse_x ($2, SCM_EOL);
2715 n->set_property ("articulations", arts);
2717 $$ = n->unprotect ();
2719 | music_function_chord_body
2721 Music *m = unsmob_music ($1);
2723 while (m && m->is_mus_type ("music-wrapper-music")) {
2724 $$ = m->get_property ("element");
2725 m = unsmob_music ($$);
2728 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2729 parser->parser_error (@$, _ ("not a rhythmic event"));
2735 music_function_chord_body:
2740 // Event functions may only take closed arglists, otherwise it would
2741 // not be clear whether a following postevent should be associated
2742 // with the last argument of the event function or with the expression
2743 // for which the function call acts itself as event.
2745 music_function_call_closed:
2746 MUSIC_FUNCTION function_arglist_closed {
2747 $$ = MAKE_SYNTAX ("music-function", @$,
2752 event_function_event:
2753 EVENT_FUNCTION function_arglist_closed {
2754 $$ = MAKE_SYNTAX ("music-function", @$,
2776 | post_events post_event {
2778 if (Music *m = unsmob_music ($2))
2780 if (m->is_mus_type ("post-event-wrapper"))
2782 for (SCM p = m->get_property ("elements");
2786 $$ = scm_cons (scm_car (p), $$);
2790 $$ = scm_cons ($2, $$);
2796 post_event_nofinger:
2797 direction_less_event {
2800 | script_dir music_function_call_closed {
2802 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2803 parser->parser_error (@2, _ ("post-event expected"));
2804 $$ = SCM_UNSPECIFIED;
2805 } else if (!SCM_UNBNDP ($1))
2807 unsmob_music ($$)->set_property ("direction", $1);
2811 if (!parser->lexer_->is_lyric_state ())
2812 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2813 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2816 if (!parser->lexer_->is_lyric_state ())
2817 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2818 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2820 | script_dir direction_reqd_event {
2821 if (!SCM_UNBNDP ($1))
2823 Music *m = unsmob_music ($2);
2824 m->set_property ("direction", $1);
2828 | script_dir direction_less_event {
2829 if (!SCM_UNBNDP ($1))
2831 Music *m = unsmob_music ($2);
2832 m->set_property ("direction", $1);
2839 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2844 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2855 string_number_event:
2857 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2858 s->set_property ("string-number", $1);
2859 $$ = s->unprotect ();
2863 direction_less_event:
2865 | EVENT_IDENTIFIER {
2869 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2870 a->set_property ("tremolo-type", $1);
2871 $$ = a->unprotect ();
2873 | event_function_event
2876 direction_reqd_event:
2880 | script_abbreviation {
2881 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2882 if (scm_is_string (s)) {
2883 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2884 a->set_property ("articulation-type", s);
2885 $$ = a->unprotect ();
2887 Music *original = unsmob_music (s);
2888 if (original && original->is_mus_type ("post-event")) {
2889 Music *a = original->clone ();
2890 a->set_spot (parser->lexer_->override_input (@$));
2891 $$ = a->unprotect ();
2893 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2894 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2901 /**/ { $$ = SCM_EOL; }
2902 | '=' quotes { $$ = $2; }
2916 $$ = scm_from_int (1);
2919 $$ = scm_oneplus ($1);
2925 $$ = scm_from_int (-1);
2928 $$ = scm_oneminus ($1);
2933 NOTENAME_PITCH quotes {
2934 if (!scm_is_eq (SCM_INUM0, $2))
2936 Pitch p = *unsmob_pitch ($1);
2937 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2938 $$ = p.smobbed_copy ();
2948 TONICNAME_PITCH quotes {
2949 if (!scm_is_eq (SCM_INUM0, $2))
2951 Pitch p = *unsmob_pitch ($1);
2952 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2953 $$ = p.smobbed_copy ();
2960 | PITCH_IDENTIFIER quotes {
2961 if (!scm_is_eq (SCM_INUM0, $2))
2963 Pitch p = *unsmob_pitch ($1);
2964 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2965 $$ = p.smobbed_copy ();
2972 if (!scm_is_eq (SCM_INUM0, $2))
2974 Pitch p = *unsmob_pitch ($1);
2975 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2976 $$ = p.smobbed_copy ();
2983 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2984 t->set_property ("text", $1);
2985 $$ = t->unprotect ();
2988 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2989 t->set_property ("text",
2990 make_simple_markup ($1));
2991 $$ = t->unprotect ();
2993 | embedded_scm_closed
2995 Music *m = unsmob_music ($1);
2996 if (m && m->is_mus_type ("post-event"))
2998 else if (Text_interface::is_markup ($1)) {
2999 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3000 t->set_property ("text", $1);
3001 $$ = t->unprotect ();
3003 parser->parser_error (@1, _ ("not an articulation"));
3009 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3010 t->set_property ("digit", $1);
3011 $$ = t->unprotect ();
3015 script_abbreviation:
3017 $$ = scm_from_locale_string ("Hat");
3020 $$ = scm_from_locale_string ("Plus");
3023 $$ = scm_from_locale_string ("Dash");
3026 $$ = scm_from_locale_string ("Bang");
3029 $$ = scm_from_locale_string ("Larger");
3032 $$ = scm_from_locale_string ("Dot");
3035 $$ = scm_from_locale_string ("Underscore");
3040 '_' { $$ = scm_from_int (DOWN); }
3041 | '^' { $$ = scm_from_int (UP); }
3042 | '-' { $$ = SCM_UNDEFINED; }
3046 multiplied_duration {
3051 maybe_notemode_duration:
3055 | multiplied_duration {
3057 parser->default_duration_ = *unsmob_duration ($$);
3062 optional_notemode_duration:
3063 maybe_notemode_duration
3065 if (SCM_UNBNDP ($$))
3066 $$ = parser->default_duration_.smobbed_copy ();
3072 $$ = make_duration ($1, scm_to_int ($2));
3073 if (SCM_UNBNDP ($$))
3075 parser->parser_error (@1, _ ("not a duration"));
3076 $$ = Duration ().smobbed_copy ();
3079 | DURATION_IDENTIFIER dots {
3080 Duration *d = unsmob_duration ($1);
3081 Duration k (d->duration_log (),
3082 d->dot_count () + scm_to_int ($2));
3083 k = k.compressed (d->factor ());
3084 scm_remember_upto_here_1 ($1);
3085 $$ = k.smobbed_copy ();
3089 multiplied_duration:
3093 | multiplied_duration '*' UNSIGNED {
3094 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
3096 | multiplied_duration '*' FRACTION {
3097 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
3099 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
3108 $$ = scm_oneplus ($1);
3117 if (SCM_UNBNDP (make_duration ($2)))
3118 parser->parser_error (@2, _ ("not a duration"));
3124 UNSIGNED { $$ = $1; }
3125 | STRING { $$ = $1; }
3126 | full_markup { $$ = $1; }
3129 // as an integer, it needs to be non-negative, and otherwise
3130 // it needs to be suitable as a markup.
3131 if (scm_is_integer ($1)
3132 ? scm_is_true (scm_negative_p ($1))
3133 : !Text_interface::is_markup ($1))
3135 parser->parser_error (@1, _ ("bass number expected"));
3141 figured_bass_alteration:
3142 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3143 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3144 | '!' { $$ = scm_from_int (0); }
3149 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3150 $$ = bfr->unprotect ();
3153 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3154 $$ = bfr->self_scm ();
3156 if (scm_is_number ($1))
3157 bfr->set_property ("figure", $1);
3158 else if (Text_interface::is_markup ($1))
3159 bfr->set_property ("text", $1);
3165 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3167 | bass_figure figured_bass_alteration {
3168 Music *m = unsmob_music ($1);
3169 if (scm_to_double ($2)) {
3170 SCM salter = m->get_property ("alteration");
3171 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3172 m->set_property ("alteration",
3173 scm_sum (alter, $2));
3175 m->set_property ("alteration", scm_from_int (0));
3178 | bass_figure figured_bass_modification {
3179 Music *m = unsmob_music ($1);
3180 m->set_property ($2, SCM_BOOL_T);
3185 figured_bass_modification:
3187 $$ = ly_symbol2scm ("augmented");
3190 $$ = ly_symbol2scm ("no-continuation");
3193 $$ = ly_symbol2scm ("diminished");
3196 $$ = ly_symbol2scm ("augmented-slash");
3206 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3214 | figure_list br_bass_figure {
3215 $$ = scm_cons ($2, $1);
3220 FIGURE_OPEN figure_list FIGURE_CLOSE {
3221 $$ = scm_reverse_x ($2, SCM_EOL);
3227 /**/ { $$ = SCM_BOOL_F; }
3228 | REST { $$ = SCM_BOOL_T; }
3232 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3233 if (!parser->lexer_->is_note_state ())
3234 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3235 if (!SCM_UNBNDP ($2)
3237 || scm_is_number ($4)
3239 || scm_is_true ($6))
3242 if (scm_is_true ($6))
3243 n = MY_MAKE_MUSIC ("RestEvent", @$);
3245 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3247 n->set_property ("pitch", $1);
3248 if (SCM_UNBNDP ($5))
3249 n->set_property ("duration",
3250 parser->default_duration_.smobbed_copy ());
3252 n->set_property ("duration", $5);
3254 if (scm_is_number ($4))
3256 int q = scm_to_int ($4);
3257 n->set_property ("absolute-octave", scm_from_int (q-1));
3260 if (to_boolean ($3))
3261 n->set_property ("cautionary", SCM_BOOL_T);
3262 if (to_boolean ($2) || to_boolean ($3))
3263 n->set_property ("force-accidental", SCM_BOOL_T);
3265 $$ = n->unprotect ();
3268 | DRUM_PITCH optional_notemode_duration {
3269 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3270 n->set_property ("duration", $2);
3271 n->set_property ("drum-type", $1);
3273 $$ = n->unprotect ();
3275 | RESTNAME optional_notemode_duration {
3277 if (ly_scm2string ($1) == "s") {
3279 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3282 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3285 ev->set_property ("duration", $2);
3286 $$ = ev->unprotect ();
3290 // Can return a single pitch rather than a list.
3291 simple_chord_elements:
3293 if (!parser->lexer_->is_chord_state ())
3294 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3297 | figure_spec optional_notemode_duration {
3298 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3300 unsmob_music (scm_car (s))->set_property ("duration", $2);
3308 if (!parser->lexer_->is_lyric_state ())
3309 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3313 if (!parser->lexer_->is_lyric_state ())
3314 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3320 lyric_element_music:
3321 lyric_element optional_notemode_duration post_events {
3322 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3323 if (scm_is_pair ($3))
3324 unsmob_music ($$)->set_property
3325 ("articulations", scm_reverse_x ($3, SCM_EOL));
3329 // Can return a single pitch rather than a list.
3331 steno_tonic_pitch maybe_notemode_duration {
3332 if (SCM_UNBNDP ($2))
3335 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3337 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3338 SCM its = scm_reverse_x ($4, SCM_EOL);
3339 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3347 | chord_items chord_item {
3348 $$ = scm_cons ($2, $$);
3354 $$ = ly_symbol2scm ("chord-colon");
3357 $$ = ly_symbol2scm ("chord-caret");
3359 | CHORD_SLASH steno_tonic_pitch {
3360 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3362 | CHORD_BASS steno_tonic_pitch {
3363 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3372 $$ = scm_reverse_x ($1, SCM_EOL);
3380 step_number { $$ = scm_cons ($1, SCM_EOL); }
3381 | step_numbers '.' step_number {
3382 $$ = scm_cons ($3, $$);
3388 $$ = make_chord_step ($1, 0);
3391 $$ = make_chord_step ($1, SHARP_ALTERATION);
3393 | UNSIGNED CHORD_MINUS {
3394 $$ = make_chord_step ($1, FLAT_ALTERATION);
3402 | unsigned_number '-' unsigned_number {
3403 $$ = scm_cons ($1, $3);
3410 TODO: should deprecate in favor of Scheme?
3414 number_expression '+' number_term {
3415 $$ = scm_sum ($1, $3);
3417 | number_expression '-' number_term {
3418 $$ = scm_difference ($1, $3);
3427 | number_factor '*' number_factor {
3428 $$ = scm_product ($1, $3);
3430 | number_factor '/' number_factor {
3431 $$ = scm_divide ($1, $3);
3436 '-' number_factor { /* %prec UNARY_MINUS */
3437 $$ = scm_difference ($2, SCM_UNDEFINED);
3443 bare_number_common_closed
3444 | REAL NUMBER_IDENTIFIER
3446 $$ = scm_product ($1, $2);
3450 bare_number_common_closed:
3458 | UNSIGNED NUMBER_IDENTIFIER {
3459 $$ = scm_product ($1, $2);
3465 | bare_number_common_closed
3472 if (!scm_is_integer ($1)
3473 || scm_is_true (scm_negative_p ($1)))
3475 parser->parser_error (@1, _("not an unsigned integer"));
3481 if (!scm_is_integer ($1)
3482 || scm_is_true (scm_negative_p ($1)))
3484 parser->parser_error (@1, _("not an unsigned integer"));
3491 { $$ = SCM_UNDEFINED; }
3494 if (SCM_UNBNDP ($1))
3502 { $$ = SCM_UNDEFINED; }
3505 if (SCM_UNBNDP ($1))
3514 { parser->lexer_->push_markup_state (); }
3517 parser->lexer_->pop_state ();
3523 { parser->lexer_->push_markup_state (); }
3526 parser->lexer_->pop_state ();
3532 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3534 | markup_head_1_list simple_markup
3536 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3537 @2, $1, scm_list_1 ($2)));
3547 if (Text_interface::is_markup ($1))
3548 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3549 else if (Text_interface::is_markup_list ($1))
3550 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3552 parser->parser_error (@1, _ ("not a markup"));
3553 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3560 markup_composed_list {
3563 | markup_uncomposed_list
3566 markup_uncomposed_list:
3567 markup_braced_list {
3570 | markup_command_list {
3571 $$ = scm_list_1 ($1);
3573 | markup_scm MARKUPLIST_IDENTIFIER
3578 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3579 parser->lexer_->push_note_state (nn);
3580 } '{' score_body '}' {
3581 unsmob_score ($4)->origin ()->set_spot (@$);
3582 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3583 parser->lexer_->pop_state ();
3587 markup_composed_list:
3588 markup_head_1_list markup_uncomposed_list {
3589 $$ = MAKE_SYNTAX ("composed-markup-list",
3595 '{' markup_braced_list_body '}' {
3596 $$ = scm_reverse_x ($2, SCM_EOL);
3600 markup_braced_list_body:
3601 /* empty */ { $$ = SCM_EOL; }
3602 | markup_braced_list_body markup {
3603 $$ = scm_cons ($2, $1);
3605 | markup_braced_list_body markup_list {
3606 $$ = scm_reverse_x ($2, $1);
3610 markup_command_list:
3611 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3612 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3616 markup_command_basic_arguments:
3617 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3618 $$ = scm_cons ($3, $2);
3620 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3621 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3623 | EXPECT_NO_MORE_ARGS {
3628 markup_command_list_arguments:
3629 markup_command_basic_arguments { $$ = $1; }
3630 | EXPECT_MARKUP markup_command_list_arguments markup {
3631 $$ = scm_cons ($3, $2);
3636 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3637 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3642 markup_head_1_item {
3643 $$ = scm_list_1 ($1);
3645 | markup_head_1_list markup_head_1_item {
3646 $$ = scm_cons ($2, $1);
3652 $$ = make_simple_markup ($1);
3655 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3656 parser->lexer_->push_note_state (nn);
3657 } '{' score_body '}' {
3658 unsmob_score ($4)->origin ()->set_spot (@$);
3659 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3660 parser->lexer_->pop_state ();
3662 | MARKUP_FUNCTION markup_command_basic_arguments {
3663 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3665 | markup_scm MARKUP_IDENTIFIER
3672 markup_head_1_list simple_markup
3674 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3675 @2, $1, scm_list_1 ($2)));
3685 Lily_parser::set_yydebug (bool x)
3691 Lily_parser::do_yyparse ()
3693 SCM retval = SCM_UNDEFINED;
3694 yyparse (this, &retval);
3704 It is a little strange to have this function in this file, but
3705 otherwise, we have to import music classes into the lexer.
3709 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3711 if (unsmob_book (sid)) {
3712 Book *book = unsmob_book (sid)->clone ();
3713 *destination = book->self_scm ();
3716 return BOOK_IDENTIFIER;
3717 } else if (scm_is_number (sid)) {
3719 return NUMBER_IDENTIFIER;
3720 } else if (unsmob_context_def (sid)) {
3721 Context_def *def= unsmob_context_def (sid)->clone ();
3723 *destination = def->self_scm ();
3726 return CONTEXT_DEF_IDENTIFIER;
3727 } else if (unsmob_context_mod (sid)) {
3728 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3730 return CONTEXT_MOD_IDENTIFIER;
3731 } else if (Music *mus = unsmob_music (sid)) {
3732 mus = mus->clone ();
3733 *destination = mus->self_scm ();
3734 bool is_event = mus->is_mus_type ("post-event");
3736 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3737 } else if (unsmob_pitch (sid)) {
3738 *destination = unsmob_pitch (sid)->smobbed_copy ();
3739 return PITCH_IDENTIFIER;
3740 } else if (unsmob_duration (sid)) {
3741 *destination = unsmob_duration (sid)->smobbed_copy ();
3742 return DURATION_IDENTIFIER;
3743 } else if (unsmob_output_def (sid)) {
3744 Output_def *p = unsmob_output_def (sid);
3747 *destination = p->self_scm ();
3749 return OUTPUT_DEF_IDENTIFIER;
3750 } else if (unsmob_score (sid)) {
3751 *destination = unsmob_score (sid)->clone ()->unprotect ();
3752 return SCM_IDENTIFIER;
3759 get_next_unique_context_id ()
3761 return scm_from_locale_string ("$uniqueContextId");
3766 get_next_unique_lyrics_context_id ()
3768 static int new_context_count;
3770 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3771 return scm_from_locale_string (s);
3774 // check_scheme_arg checks one argument with a given predicate for use
3775 // in an argument list and throws a syntax error if it is unusable.
3776 // The argument is prepended to the argument list in any case. After
3777 // throwing a syntax error, the argument list is terminated with #f as
3778 // its last cdr in order to mark it as uncallable while not losing
3779 // track of its total length.
3781 // There are a few special considerations: if optional argument disp
3782 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3783 // instead of arg in a prospective error message. This is useful if
3784 // arg is not the actual argument but rather a transformation of it.
3786 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3787 // and an error message using disp is produced unconditionally.
3789 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3790 SCM arg, SCM args, SCM pred, SCM disp)
3792 if (SCM_UNBNDP (arg))
3793 args = scm_cons (disp, args);
3795 args = scm_cons (arg, args);
3796 if (scm_is_true (scm_call_1 (pred, arg)))
3799 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3800 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3801 SCM_UNBNDP (disp) ? arg : disp);
3802 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3806 SCM loc_on_music (Input loc, SCM arg)
3808 if (Music *m = unsmob_music (arg))
3812 return m->unprotect ();
3818 try_string_variants (SCM pred, SCM str)
3820 // a matching predicate is always ok
3821 if (scm_is_true (scm_call_1 (pred, str)))
3823 // a symbol may be interpreted as a list of symbols if it helps
3824 if (scm_is_symbol (str)) {
3825 str = scm_list_1 (str);
3826 if (scm_is_true (scm_call_1 (pred, str)))
3828 return SCM_UNDEFINED;
3831 // If this cannot be a string representation of a symbol list,
3834 if (!is_regular_identifier (str, true))
3835 return SCM_UNDEFINED;
3837 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3838 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3839 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3841 // Let's attempt the symbol list interpretation first.
3843 if (scm_is_true (scm_call_1 (pred, str)))
3846 // If there is just one symbol in the list, we might interpret
3847 // it as a single symbol
3849 if (scm_is_null (scm_cdr (str)))
3851 str = scm_car (str);
3852 if (scm_is_true (scm_call_1 (pred, str)))
3856 return SCM_UNDEFINED;
3860 is_regular_identifier (SCM id, bool multiple)
3862 if (!scm_is_string (id))
3865 string str = ly_scm2string (id);
3867 bool middle = false;
3869 for (string::iterator it=str.begin(); it != str.end (); it++)
3872 if ((c >= 'a' && c <= 'z')
3873 || (c >= 'A' && c <= 'Z')
3876 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3885 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3887 if (unsmob_music (simple))
3889 if (parser->lexer_->is_note_state ()) {
3890 if (scm_is_symbol (simple)) {
3891 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3892 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3893 n->set_property ("drum-type", simple);
3894 return n->unprotect ();
3896 if (unsmob_pitch (simple)) {
3897 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3898 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3899 n->set_property ("pitch", simple);
3900 return n->unprotect ();
3903 } else if (parser->lexer_->is_lyric_state ()) {
3904 if (Text_interface::is_markup (simple))
3905 return MAKE_SYNTAX ("lyric-event", loc, simple,
3906 parser->default_duration_.smobbed_copy ());
3907 } else if (parser->lexer_->is_chord_state ()) {
3908 if (unsmob_pitch (simple))
3912 make_chord_elements (loc, simple,
3913 parser->default_duration_.smobbed_copy (),
3920 make_music_with_input (SCM name, Input where)
3922 Music *m = make_music_by_name (name);
3923 m->set_spot (where);
3928 make_simple_markup (SCM a)
3934 make_duration (SCM d, int dots)
3936 int t = scm_to_int (d);
3937 if (t > 0 && (t & (t-1)) == 0)
3938 return Duration (intlog2 (t), dots).smobbed_copy ();
3940 return SCM_UNDEFINED;
3944 make_chord_step (SCM step_scm, Rational alter)
3946 int step = scm_to_int (step_scm);
3949 alter += FLAT_ALTERATION;
3953 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3954 return m.smobbed_copy ();
3959 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3961 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3962 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3963 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3965 unsmob_music (scm_car (s))->set_spot (loc);
3971 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3973 Lily_lexer *lex = parser->lexer_;
3977 int tok = lex->pop_extra_token ();
3980 lex->prepare_for_next_token ();
3981 return lex->yylex ();