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 (yychar, yylval); \
160 parser->lexer_->push_extra_token (Token, Value); \
161 parser->lexer_->push_extra_token (BACKUP); \
166 #define MYREPARSE(Location, Pred, Token, Value) \
168 if (yychar != YYEMPTY) \
169 parser->lexer_->push_extra_token (yychar, yylval); \
170 parser->lexer_->push_extra_token (Token, Value); \
171 parser->lexer_->push_extra_token (REPARSE, Pred); \
180 #define MY_MAKE_MUSIC(x, spot) \
181 make_music_with_input (ly_symbol2scm (x), \
182 parser->lexer_->override_input (spot))
185 - Don't use lily module, create a new module instead.
186 - delay application of the function
188 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
189 scm_apply_0 (proc, args)
190 /* Syntactic Sugar. */
191 #define MAKE_SYNTAX(name, location, ...) \
192 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))
193 #define START_MAKE_SYNTAX(name, ...) \
194 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
195 #define FINISH_MAKE_SYNTAX(start, location, ...) \
196 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)))))
198 SCM get_next_unique_context_id ();
199 SCM get_next_unique_lyrics_context_id ();
206 #define _(x) gettext (x)
210 static Music *make_music_with_input (SCM name, Input where);
211 SCM check_scheme_arg (Lily_parser *parser, Input loc,
212 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
213 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
214 SCM loc_on_music (Input loc, SCM arg);
215 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
216 SCM make_chord_step (SCM step, Rational alter);
217 SCM make_simple_markup (SCM a);
218 SCM make_duration (SCM t, int dots = 0);
219 bool is_regular_identifier (SCM id, bool multiple=false);
220 SCM try_string_variants (SCM pred, SCM str);
221 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
225 /* The third option is an alias that will be used to display the
226 syntax error. Bison CVS now correctly handles backslash escapes.
228 FIXME: Bison needs to translate some of these, eg, STRING.
232 /* Keyword tokens with plain escaped name. */
233 %token END_OF_FILE 0 "end of input"
234 %token ACCEPTS "\\accepts"
235 %token ADDLYRICS "\\addlyrics"
236 %token ALIAS "\\alias"
237 %token ALTERNATIVE "\\alternative"
239 %token BOOKPART "\\bookpart"
240 %token CHANGE "\\change"
241 %token CHORDMODE "\\chordmode"
242 %token CHORDS "\\chords"
243 %token CONSISTS "\\consists"
244 %token CONTEXT "\\context"
245 %token DEFAULT "\\default"
246 %token DEFAULTCHILD "\\defaultchild"
247 %token DENIES "\\denies"
248 %token DESCRIPTION "\\description"
249 %token DRUMMODE "\\drummode"
250 %token DRUMS "\\drums"
251 %token FIGUREMODE "\\figuremode"
252 %token FIGURES "\\figures"
253 %token HEADER "\\header"
254 %token INVALID "\\version-error"
255 %token LAYOUT "\\layout"
256 %token LYRICMODE "\\lyricmode"
257 %token LYRICS "\\lyrics"
258 %token LYRICSTO "\\lyricsto"
259 %token MARKUP "\\markup"
260 %token MARKUPLIST "\\markuplist"
263 %token NOTEMODE "\\notemode"
264 %token OVERRIDE "\\override"
265 %token PAPER "\\paper"
266 %token REMOVE "\\remove"
267 %token REPEAT "\\repeat"
269 %token REVERT "\\revert"
270 %token SCORE "\\score"
271 %token SCORELINES "\\score-lines"
272 %token SEQUENTIAL "\\sequential"
274 %token SIMULTANEOUS "\\simultaneous"
275 %token TEMPO "\\tempo"
277 %token UNSET "\\unset"
280 /* Keyword token exceptions. */
281 %token NEWCONTEXT "\\new"
284 /* Other string tokens. */
286 %token CHORD_BASS "/+"
287 %token CHORD_CARET "^"
288 %token CHORD_COLON ":"
289 %token CHORD_MINUS "-"
290 %token CHORD_SLASH "/"
291 %token ANGLE_OPEN "<"
292 %token ANGLE_CLOSE ">"
293 %token DOUBLE_ANGLE_OPEN "<<"
294 %token DOUBLE_ANGLE_CLOSE ">>"
295 %token E_BACKSLASH "\\"
296 %token E_EXCLAMATION "\\!"
301 If we give names, Bison complains.
303 %token FIGURE_CLOSE /* "\\>" */
304 %token FIGURE_OPEN /* "\\<" */
305 %token FIGURE_SPACE "_"
308 %token MULTI_MEASURE_REST
314 /* Artificial tokens, for more generic function syntax */
315 %token EXPECT_MARKUP "markup?"
316 %token EXPECT_SCM "scheme?"
317 %token BACKUP "(backed-up?)"
318 %token REPARSE "(reparsed?)"
319 %token EXPECT_MARKUP_LIST "markup-list?"
320 %token EXPECT_OPTIONAL "optional?"
321 /* After the last argument. */
322 %token EXPECT_NO_MORE_ARGS;
324 /* An artificial token for parsing embedded Lilypond */
325 %token EMBEDDED_LILY "#{"
327 %token BOOK_IDENTIFIER
328 %token CHORD_BODY_IDENTIFIER
329 %token CHORD_MODIFIER
330 %token CHORD_REPETITION
331 %token CONTEXT_DEF_IDENTIFIER
332 %token CONTEXT_MOD_IDENTIFIER
334 %token PITCH_IDENTIFIER
336 %token DURATION_IDENTIFIER
337 %token EVENT_IDENTIFIER
338 %token EVENT_FUNCTION
341 %token MARKUP_FUNCTION
342 %token MARKUP_LIST_FUNCTION
343 %token MARKUP_IDENTIFIER
344 %token MARKUPLIST_IDENTIFIER
345 %token MUSIC_FUNCTION
346 %token MUSIC_IDENTIFIER
347 %token NOTENAME_PITCH
348 %token NUMBER_IDENTIFIER
349 %token OUTPUT_DEF_IDENTIFIER
351 %token REPEAT_IDENTIFIER
355 %token SCM_IDENTIFIER
359 %token TONICNAME_PITCH
363 /* We don't assign precedence to / and *, because we might need varied
364 prec levels in different prods */
373 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
374 parser->lexer_->push_note_state (nn);
375 } embedded_lilypond {
376 parser->lexer_->pop_state ();
381 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
382 | lilypond toplevel_expression {
384 | lilypond assignment {
387 parser->error_level_ = 1;
390 parser->error_level_ = 1;
397 parser->lexer_->add_scope (get_header (parser));
399 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
402 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
403 scm_call_2 (proc, parser->self_scm (), $1);
406 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
407 scm_call_2 (proc, parser->self_scm (), $1);
410 SCM proc = parser->lexer_->lookup_identifier
411 (unsmob_book($1)->paper_
412 ? "toplevel-book-handler"
413 : "toplevel-bookpart-handler");
414 scm_call_2 (proc, parser->self_scm (), $1);
417 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
418 scm_call_2 (proc, parser->self_scm (), $1);
421 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
422 scm_call_2 (proc, parser->self_scm (), $1);
425 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
426 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
429 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
430 scm_call_2 (proc, parser->self_scm (), $1);
433 // Evaluate and ignore #xxx, as opposed to \xxx
434 parser->lexer_->eval_scm_token ($1);
436 | embedded_scm_active
438 SCM out = SCM_UNDEFINED;
439 if (Text_interface::is_markup ($1))
440 out = scm_list_1 ($1);
441 else if (Text_interface::is_markup_list ($1))
443 if (scm_is_pair (out))
445 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
446 scm_call_2 (proc, parser->self_scm (), out);
447 } else if (unsmob_score ($1))
449 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
450 scm_call_2 (proc, parser->self_scm (), $1);
451 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
452 parser->parser_error (@1, _("bad expression type"));
456 Output_def * od = unsmob_output_def ($1);
458 if (od->c_variable ("is-paper") == SCM_BOOL_T)
459 id = ly_symbol2scm ("$defaultpaper");
460 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
461 id = ly_symbol2scm ("$defaultmidi");
462 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
463 id = ly_symbol2scm ("$defaultlayout");
465 parser->lexer_->set_identifier (id, $1);
472 $$ = parser->lexer_->eval_scm_token ($1);
482 embedded_scm_bare_arg:
486 $$ = parser->lexer_->eval_scm_token ($1);
490 | context_modification
492 | context_def_spec_block
498 /* The generic version may end in music, or not */
505 /* embedded_scm_arg is _not_ casting pitches to music by default, this
506 * has to be done by the function itself. Note that this may cause
507 * the results of scm_function_call or embedded_scm_bare_arg to be
508 * turned into music from pitches as well. Note that this creates a
509 * distinctly awkward situation for calculated drum pitches. Those
510 * are at the current point of time rejected as music constituents as
511 * they can't be distinguished from "proper" symbols.
515 embedded_scm_bare_arg
521 SCM_FUNCTION function_arglist {
522 $$ = MAKE_SYNTAX ("music-function", @$,
527 embedded_lilypond_number:
528 '-' embedded_lilypond_number
530 $$ = scm_difference ($2, SCM_UNDEFINED);
533 | UNSIGNED NUMBER_IDENTIFIER
535 $$ = scm_product ($1, $2);
542 // FIXME: @$ does not contain a useful source location
543 // for empty rules, and the only token in the whole
544 // production, EMBEDDED_LILY, is synthetic and also
545 // contains no source location.
546 $$ = MAKE_SYNTAX ("void-music", @$);
548 | identifier_init_nonumber
549 | embedded_lilypond_number
550 | post_event post_events
552 $$ = scm_reverse_x ($2, SCM_EOL);
553 if (Music *m = unsmob_music ($1))
555 if (m->is_mus_type ("post-event-wrapper"))
557 (scm_list_2 (m->get_property ("elements"),
560 $$ = scm_cons ($1, $$);
563 && scm_is_null (scm_cdr ($$)))
567 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
568 m->set_property ("elements", $$);
569 $$ = m->unprotect ();
572 | multiplied_duration
573 | music_embedded music_embedded music_list {
574 $3 = scm_reverse_x ($3, SCM_EOL);
575 if (unsmob_music ($2))
576 $3 = scm_cons ($2, $3);
577 if (unsmob_music ($1))
578 $3 = scm_cons ($1, $3);
579 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
582 parser->error_level_ = 1;
583 $$ = SCM_UNSPECIFIED;
585 | INVALID embedded_lilypond {
586 parser->error_level_ = 1;
592 lilypond_header_body:
593 /* empty */ { $$ = SCM_UNSPECIFIED; }
594 | lilypond_header_body assignment {
597 | lilypond_header_body embedded_scm {
603 HEADER '{' lilypond_header_body '}' {
604 $$ = parser->lexer_->remove_scope ();
616 assignment_id '=' identifier_init {
617 parser->lexer_->set_identifier ($1, $3);
618 $$ = SCM_UNSPECIFIED;
620 | assignment_id property_path '=' identifier_init {
621 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
622 parser->lexer_->set_identifier (path, $4);
623 $$ = SCM_UNSPECIFIED;
629 identifier_init_nonumber
631 | post_event_nofinger post_events
633 $$ = scm_reverse_x ($2, SCM_EOL);
634 if (Music *m = unsmob_music ($1))
636 if (m->is_mus_type ("post-event-wrapper"))
638 (scm_list_2 (m->get_property ("elements"),
641 $$ = scm_cons ($1, $$);
644 && scm_is_null (scm_cdr ($$)))
648 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
649 m->set_property ("elements", $$);
650 $$ = m->unprotect ();
655 identifier_init_nonumber:
660 | context_def_spec_block
666 | context_modification
669 context_def_spec_block:
670 CONTEXT '{' context_def_spec_body '}'
673 unsmob_context_def ($$)->origin ()->set_spot (@$);
681 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
682 parser->lexer_->push_note_state (nn);
686 parser->lexer_->pop_state ();
691 context_mod_embedded:
694 if (unsmob_music ($1)) {
695 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
696 $1 = scm_call_2 (proc, parser->self_scm (), $1);
698 if (unsmob_context_mod ($1))
701 parser->parser_error (@1, _ ("not a context mod"));
702 $$ = Context_mod ().smobbed_copy ();
708 context_def_spec_body:
710 $$ = Context_def::make_scm ();
712 | CONTEXT_DEF_IDENTIFIER {
715 | context_def_spec_body context_mod {
716 if (!SCM_UNBNDP ($2))
717 unsmob_context_def ($$)->add_context_mod ($2);
719 | context_def_spec_body context_modification {
720 Context_def *td = unsmob_context_def ($$);
721 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
722 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
723 td->add_context_mod (scm_car (m));
726 | context_def_spec_body context_mod_embedded {
727 Context_def *td = unsmob_context_def ($$);
728 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
729 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
730 td->add_context_mod (scm_car (m));
738 BOOK '{' book_body '}' {
740 unsmob_book ($$)->origin ()->set_spot (@$);
742 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
747 * Use 'handlers' like for toplevel-* stuff?
748 * grok \layout and \midi? */
751 Book *book = new Book;
752 init_papers (parser);
753 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
754 book->paper_->unprotect ();
755 push_paper (parser, book->paper_);
756 book->header_ = get_header (parser);
757 $$ = book->unprotect ();
758 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
761 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
763 | book_body paper_block {
764 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
765 set_paper (parser, unsmob_output_def ($2));
767 | book_body bookpart_block {
768 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
769 scm_call_2 (proc, $1, $2);
771 | book_body score_block {
772 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
773 scm_call_2 (proc, $1, $2);
775 | book_body composite_music {
776 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
777 scm_call_3 (proc, parser->self_scm (), $1, $2);
779 | book_body full_markup {
780 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
781 scm_call_2 (proc, $1, scm_list_1 ($2));
783 | book_body full_markup_list {
784 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
785 scm_call_2 (proc, $1, $2);
787 | book_body SCM_TOKEN {
788 // Evaluate and ignore #xxx, as opposed to \xxx
789 parser->lexer_->eval_scm_token ($2);
791 | book_body embedded_scm_active
793 SCM out = SCM_UNDEFINED;
794 if (Text_interface::is_markup ($2))
795 out = scm_list_1 ($2);
796 else if (Text_interface::is_markup_list ($2))
798 if (scm_is_pair (out))
800 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
801 scm_call_2 (proc, $1, out);
802 } else if (unsmob_score ($2))
804 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
805 scm_call_2 (proc, $1, $2);
806 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
807 parser->parser_error (@2, _("bad expression type"));
811 parser->lexer_->add_scope (unsmob_book ($1)->header_);
814 Book *book = unsmob_book ($1);
816 book->scores_ = SCM_EOL;
817 book->bookparts_ = SCM_EOL;
822 BOOKPART '{' bookpart_body '}' {
824 unsmob_book ($$)->origin ()->set_spot (@$);
825 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
831 Book *book = new Book;
832 $$ = book->unprotect ();
833 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
836 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
838 | bookpart_body paper_block {
839 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
841 | bookpart_body score_block {
842 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
843 scm_call_2 (proc, $1, $2);
845 | bookpart_body composite_music {
846 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
847 scm_call_3 (proc, parser->self_scm (), $1, $2);
849 | bookpart_body full_markup {
850 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
851 scm_call_2 (proc, $1, scm_list_1 ($2));
853 | bookpart_body full_markup_list {
854 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
855 scm_call_2 (proc, $1, $2);
857 | bookpart_body SCM_TOKEN {
858 // Evaluate and ignore #xxx, as opposed to \xxx
859 parser->lexer_->eval_scm_token ($2);
861 | bookpart_body embedded_scm_active
863 SCM out = SCM_UNDEFINED;
864 if (Text_interface::is_markup ($2))
865 out = scm_list_1 ($2);
866 else if (Text_interface::is_markup_list ($2))
868 if (scm_is_pair (out))
870 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
871 scm_call_2 (proc, $1, out);
872 } else if (unsmob_score ($2))
874 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
875 scm_call_2 (proc, $1, $2);
876 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
877 parser->parser_error (@2, _("bad expression type"));
881 Book *book = unsmob_book ($1);
882 if (!ly_is_module (book->header_))
883 book->header_ = ly_make_module (false);
884 parser->lexer_->add_scope (book->header_);
886 | bookpart_body error {
887 Book *book = unsmob_book ($1);
889 book->scores_ = SCM_EOL;
894 SCORE '{' score_body '}' {
895 unsmob_score ($3)->origin ()->set_spot (@$);
907 if (!scm_is_pair ($1)
908 || !ly_is_module (scm_car ($1)))
909 $1 = scm_cons (ly_make_module (false), $1);
910 parser->lexer_->add_scope (scm_car ($1));
915 | score_headers output_def
917 Output_def *od = unsmob_output_def ($2);
918 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
920 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
925 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
926 scm_set_cdr_x ($1, scm_cons ($2, scm_cdr ($1)));
928 $$ = scm_cons ($2, $1);
936 score_headers music {
937 SCM scorify = ly_lily_module_constant ("scorify-music");
938 $$ = scm_call_2 (scorify, $2, parser->self_scm ());
940 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
942 unsmob_score ($$)->set_header (scm_car ($1));
945 for (SCM p = scm_reverse_x ($1, SCM_EOL);
946 scm_is_pair (p); p = scm_cdr (p))
949 add_output_def (unsmob_output_def (scm_car (p)));
952 | embedded_scm_active {
953 if (!unsmob_score ($1))
955 $$ = (new Score)->unprotect ();
956 parser->parser_error (@1, _("score expected"));
961 Score *score = unsmob_score ($1);
962 if (!ly_is_module (score->get_header ()))
963 score->set_header (ly_make_module (false));
964 parser->lexer_->add_scope (score->get_header ());
966 | score_body output_def {
967 Output_def *od = unsmob_output_def ($2);
968 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
970 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
975 unsmob_score ($1)->add_output_def (od);
979 unsmob_score ($$)->error_found_ = true;
990 Output_def *od = unsmob_output_def ($1);
992 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
994 parser->parser_error (@1, _ ("need \\paper for paper block"));
995 $$ = get_paper (parser)->unprotect ();
1002 output_def_body '}' {
1005 parser->lexer_->remove_scope ();
1006 parser->lexer_->pop_state ();
1012 Output_def *p = get_paper (parser);
1013 p->input_origin_ = @$;
1014 parser->lexer_->add_scope (p->scope_);
1015 $$ = p->unprotect ();
1018 Output_def *p = get_midi (parser);
1019 $$ = p->unprotect ();
1020 parser->lexer_->add_scope (p->scope_);
1023 Output_def *p = get_layout (parser);
1025 parser->lexer_->add_scope (p->scope_);
1026 $$ = p->unprotect ();
1030 output_def_head_with_mode_switch:
1032 parser->lexer_->push_initial_state ();
1037 // We need this weird nonterminal because both music as well as a
1038 // context definition can start with \context and the difference is
1039 // only apparent after looking at the next token. If it is '{', there
1040 // is still time to escape from notes mode.
1042 music_or_context_def:
1044 | context_def_spec_block
1048 output_def_head_with_mode_switch '{' {
1050 unsmob_output_def ($$)->input_origin_.set_spot (@$);
1052 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1053 Output_def *o = unsmob_output_def ($3);
1054 o->input_origin_.set_spot (@$);
1055 $$ = o->self_scm ();
1056 parser->lexer_->remove_scope ();
1057 parser->lexer_->add_scope (o->scope_);
1059 | output_def_body assignment {
1062 | output_def_body embedded_scm {
1067 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1068 parser->lexer_->push_note_state (nn);
1069 } music_or_context_def
1071 parser->lexer_->pop_state ();
1072 if (unsmob_context_def ($3))
1073 assign_context_def (unsmob_output_def ($1), $3);
1076 SCM proc = parser->lexer_->lookup_identifier
1077 ("output-def-music-handler");
1078 scm_call_3 (proc, parser->self_scm (),
1082 | output_def_body error {
1088 TEMPO steno_duration '=' tempo_range {
1089 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1091 | TEMPO scalar steno_duration '=' tempo_range {
1092 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1095 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1100 The representation of a list is reversed to have efficient append. */
1106 | music_list music_embedded {
1107 if (unsmob_music ($2))
1108 $$ = scm_cons ($2, $1);
1110 | music_list error {
1111 Music *m = MY_MAKE_MUSIC("Music", @$);
1113 m->set_property ("error-found", SCM_BOOL_T);
1114 $$ = scm_cons (m->self_scm (), $1);
1115 m->unprotect (); /* UGH */
1122 $$ = scm_reverse_x ($2, SCM_EOL);
1127 | lyric_element_music
1133 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1134 parser->parser_error (@1, _ ("unexpected post-event"));
1135 $$ = SCM_UNSPECIFIED;
1138 | music_embedded_backup
1142 | music_embedded_backup BACKUP lyric_element_music
1146 | multiplied_duration post_events
1148 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1150 parser->default_duration_ = *unsmob_duration ($1);
1151 n->set_property ("duration", $1);
1153 if (scm_is_pair ($2))
1154 n->set_property ("articulations",
1155 scm_reverse_x ($2, SCM_EOL));
1156 $$ = n->unprotect ();
1160 music_embedded_backup:
1163 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1165 else if (Music *m = unsmob_music ($1)) {
1166 if (m->is_mus_type ("post-event")) {
1167 parser->parser_error
1168 (@1, _ ("unexpected post-event"));
1169 $$ = SCM_UNSPECIFIED;
1172 } else if (parser->lexer_->is_lyric_state ()
1173 && Text_interface::is_markup ($1))
1174 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1176 @$.warning (_ ("Ignoring non-music expression"));
1185 $$ = make_music_from_simple (parser, @1, $1);
1186 if (!unsmob_music ($$))
1188 parser->parser_error (@1, _ ("music expected"));
1189 $$ = MAKE_SYNTAX ("void-music", @$);
1192 | composite_music %prec COMPOSITE
1197 | composite_music %prec COMPOSITE
1201 REPEAT simple_string unsigned_number music
1203 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1205 | REPEAT_IDENTIFIER music
1207 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1210 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1212 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1214 | REPEAT_IDENTIFIER music ALTERNATIVE braced_music_list
1216 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1222 SEQUENTIAL braced_music_list {
1223 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1225 | braced_music_list {
1226 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1231 SIMULTANEOUS braced_music_list {
1232 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1234 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1235 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1241 | music_property_def
1245 context_modification:
1248 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1249 parser->lexer_->push_note_state (nn);
1250 } '{' context_mod_list '}'
1252 parser->lexer_->pop_state ();
1255 | WITH CONTEXT_MOD_IDENTIFIER
1259 | CONTEXT_MOD_IDENTIFIER
1263 | WITH context_modification_arg
1265 if (unsmob_music ($2)) {
1266 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1267 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1269 if (unsmob_context_mod ($2))
1272 parser->parser_error (@2, _ ("not a context mod"));
1273 $$ = Context_mod ().smobbed_copy ();
1278 context_modification_arg:
1283 optional_context_mod:
1287 | context_modification
1295 $$ = Context_mod ().smobbed_copy ();
1297 | context_mod_list context_mod {
1298 if (!SCM_UNBNDP ($2))
1299 unsmob_context_mod ($1)->add_context_mod ($2);
1301 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1302 Context_mod *md = unsmob_context_mod ($2);
1304 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1306 | context_mod_list context_mod_embedded {
1307 unsmob_context_mod ($1)->add_context_mods
1308 (unsmob_context_mod ($2)->get_mods ());
1317 /* Music that can be parsed without lookahead */
1320 | complex_music_prefix closed_music
1322 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1324 | music_function_call_closed
1330 | grouped_music_list
1334 simultaneous_music { $$ = $1; }
1335 | sequential_music { $$ = $1; }
1338 /* Function argument lists are arguably the most complex part in the
1339 * parser. They are pretty tricky to understand because of the way
1340 * they are processed, and because of optional arguments that can be
1341 * omitted. When there are several optional arguments in a row,
1342 * omitting one automatically omits all following arguments. Optional
1343 * arguments can only be omitted when either
1345 * a) the omission is explicitly started with \default
1346 * b) the omission is implicitly started by an argument not matching
1347 * its predicate, and there is a mandatory argument later that can
1348 * "catch" the argument that does not fit.
1350 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1351 * (corresponding to mandatory arguments and having a predicate
1352 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1353 * the semantic value of the EXPECT_OPTIONAL token is the default to
1354 * use when the optional argument is omitted, and EXPECT_SCM again has
1355 * the argument predicate as semantic value) in reverse order to the
1356 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1357 * processed inside-out while actual tokens are consumed.
1359 * This means that the argument list tokens determine the actions
1360 * taken as they arrive. The structure of the argument list is known
1361 * to the parser and stored in its parse stack when the first argument
1362 * is being parsed. What the parser does not know is which predicates
1363 * will match and whether or not \default will be appearing in the
1364 * argument list, and where.
1366 * Many of the basic nonterminals used for argument list scanning come
1367 * in a "normal" and a "closed" flavor. A closed expression is one
1368 * that can be parsed without a lookahead token. That makes it
1369 * feasible for an optional argument that may need to be skipped:
1370 * skipping can only be accomplished by pushing back the token into
1371 * the lexer, and that only works when there is no lookahead token.
1373 * Sequences of 0 or more optional arguments are scanned using either
1374 * function_arglist_backup or function_arglist_nonbackup. The first
1375 * is used when optional arguments are followed by at least one
1376 * mandatory argument: in that case optional arguments may be skipped
1377 * by either a false predicate (in which case the expression will be
1378 * pushed back as one or more tokens, preceded by a BACKUP token) or
1379 * by using \default.
1381 * If optional arguments are at the end of the argument list, they are
1382 * instead scanned using function_arglist_nonbackup: here the only
1383 * manner to enter into skipping of optional arguments is the use of
1386 * The argument list of a normal function call is parsed using
1387 * function_arglist. The part of an argument list before a mandatory
1388 * argument is parsed using function_arglist_optional.
1390 * The difference is that leading optional arguments are scanned using
1391 * function_arglist_nonbackup and function_arglist_backup,
1394 * Most other details are obvious in the rules themselves.
1398 function_arglist_nonbackup_common:
1399 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1401 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1403 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1405 SCM n = scm_difference ($5, SCM_UNDEFINED);
1406 if (scm_is_true (scm_call_1 ($2, n)))
1407 $$ = scm_cons (n, $3);
1409 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1410 t->set_property ("digit", $5);
1411 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1416 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1418 $$ = check_scheme_arg (parser, @4,
1419 scm_difference ($5, SCM_UNDEFINED),
1422 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1424 $$ = check_scheme_arg (parser, @4,
1425 scm_difference ($5, SCM_UNDEFINED),
1430 function_arglist_closed_nonbackup:
1431 function_arglist_nonbackup_common
1432 | function_arglist_closed_common
1433 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg_closed
1435 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1437 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_closed
1439 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1441 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1443 $$ = check_scheme_arg (parser, @4,
1444 try_string_variants ($2, $4),
1447 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1449 $$ = check_scheme_arg (parser, @4,
1450 try_string_variants ($2, $4),
1453 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1455 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1461 | SYMBOL_LIST '.' symbol_list_rev
1463 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1469 | symbol_list_rev '.' symbol_list_part
1471 $$ = scm_append_x (scm_list_2 ($3, $1));
1475 // symbol_list_part delivers elements in reverse copy.
1480 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1481 $$ = try_string_variants (sym_l_p, $1);
1482 if (SCM_UNBNDP ($$)) {
1483 parser->parser_error (@1, _("not a symbol"));
1486 $$ = scm_reverse ($$);
1491 symbol_list_element:
1497 function_arglist_nonbackup:
1498 function_arglist_nonbackup_common
1499 | function_arglist_common
1500 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1502 if (scm_is_true (scm_call_1 ($2, $4)))
1503 $$ = scm_cons ($4, $3);
1505 $$ = check_scheme_arg (parser, @4,
1506 make_music_from_simple
1510 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1512 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1514 | function_arglist_nonbackup_reparse REPARSE duration_length
1516 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1518 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1520 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1522 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1524 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1526 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1528 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1530 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1532 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1536 function_arglist_nonbackup_reparse:
1537 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1540 SCM res = try_string_variants ($2, $4);
1541 if (!SCM_UNBNDP (res))
1542 if (scm_is_pair (res))
1543 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1545 MYREPARSE (@4, $2, SCM_ARG, res);
1546 else if (scm_is_true
1548 ($2, make_music_from_simple
1550 MYREPARSE (@4, $2, STRING, $4);
1552 MYREPARSE (@4, $2, SCM_ARG, $4);
1554 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1557 SCM res = try_string_variants ($2, $4);
1558 if (!SCM_UNBNDP (res))
1559 if (scm_is_pair (res))
1560 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1562 MYREPARSE (@4, $2, SCM_ARG, res);
1563 else if (scm_is_true
1565 ($2, make_music_from_simple
1567 MYREPARSE (@4, $2, STRING, $4);
1569 MYREPARSE (@4, $2, SCM_ARG, $4);
1571 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1574 if (scm_is_true (scm_call_1 ($2, $4)))
1575 MYREPARSE (@4, $2, SCM_ARG, $4);
1576 else if (scm_is_true
1578 ($2, make_music_from_simple
1580 MYREPARSE (@4, $2, STRING, $4);
1582 MYREPARSE (@4, $2, SCM_ARG, $4);
1584 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1587 if (scm_is_true (scm_call_1 ($2, $4)))
1588 MYREPARSE (@4, $2, REAL, $4);
1590 SCM d = make_duration ($4);
1591 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1592 MYREPARSE (@4, $2, REAL, $4); // trigger error
1594 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1597 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1599 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1604 // function_arglist_backup can't occur at the end of an argument
1605 // list. It needs to be careful about avoiding lookahead only until
1606 // it has made a decision whether or not to accept the parsed entity.
1607 // At that point of time, music requiring lookahead to parse becomes
1609 function_arglist_backup:
1610 function_arglist_common
1611 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg_closed
1613 if (scm_is_true (scm_call_1 ($2, $4)))
1615 $$ = scm_cons ($4, $3);
1617 $$ = scm_cons (loc_on_music (@3, $1), $3);
1618 MYBACKUP (SCM_ARG, $4, @4);
1621 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REPEAT simple_string unsigned_number
1623 $4 = MAKE_SYNTAX ("repeat", @4, $5, $6,
1624 MY_MAKE_MUSIC ("Music", @4)->unprotect (),
1626 if (scm_is_true (scm_call_1 ($2, $4)))
1629 MYREPARSE (@4, $2, REPEAT_IDENTIFIER, scm_cons ($5, $6));
1631 $$ = scm_cons (loc_on_music (@3, $1), $3);
1632 MYBACKUP (REPEAT_IDENTIFIER, scm_cons ($5, $6), @4);
1635 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup chord_body
1637 if (scm_is_true (scm_call_1 ($2, $4)))
1640 MYREPARSE (@4, $2, CHORD_BODY_IDENTIFIER, $4);
1642 $$ = scm_cons (loc_on_music (@3, $1), $3);
1643 MYBACKUP (CHORD_BODY_IDENTIFIER, $4, @4);
1646 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1648 if (scm_is_true (scm_call_1 ($2, $4)))
1650 $$ = scm_cons ($4, $3);
1652 $$ = scm_cons (loc_on_music (@3, $1), $3);
1653 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1656 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1658 if (scm_is_true (scm_call_1 ($2, $4)))
1659 $$ = scm_cons ($4, $3);
1661 $$ = scm_cons (loc_on_music (@3, $1), $3);
1662 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1665 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1667 if (scm_is_true (scm_call_1 ($2, $4)))
1669 MYREPARSE (@4, $2, REAL, $4);
1672 SCM d = make_duration ($4);
1673 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1675 $$ = scm_cons (loc_on_music (@3, $1), $3);
1676 MYBACKUP (UNSIGNED, $4, @4);
1678 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1683 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1685 if (scm_is_true (scm_call_1 ($2, $4)))
1688 MYREPARSE (@4, $2, REAL, $4);
1690 $$ = scm_cons (loc_on_music (@3, $1), $3);
1691 MYBACKUP (REAL, $4, @4);
1694 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1696 if (scm_is_true (scm_call_1 ($2, $4)))
1698 $$ = scm_cons ($4, $3);
1700 $$ = scm_cons (loc_on_music (@3, $1), $3);
1701 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1704 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1706 SCM n = scm_difference ($5, SCM_UNDEFINED);
1707 if (scm_is_true (scm_call_1 ($2, n))) {
1709 MYREPARSE (@5, $2, REAL, n);
1711 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1712 t->set_property ("digit", $5);
1713 $$ = t->unprotect ();
1714 if (scm_is_true (scm_call_1 ($2, $$)))
1715 $$ = scm_cons ($$, $3);
1717 $$ = scm_cons (loc_on_music (@3, $1), $3);
1718 MYBACKUP (UNSIGNED, $5, @5);
1719 parser->lexer_->push_extra_token ('-');
1724 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1726 SCM n = scm_difference ($5, SCM_UNDEFINED);
1727 if (scm_is_true (scm_call_1 ($2, n))) {
1728 MYREPARSE (@5, $2, REAL, n);
1731 $$ = scm_cons (loc_on_music (@3, $1), $3);
1732 MYBACKUP (REAL, n, @5);
1735 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1737 SCM n = scm_difference ($5, SCM_UNDEFINED);
1738 if (scm_is_true (scm_call_1 ($2, n))) {
1739 $$ = scm_cons (n, $3);
1741 $$ = scm_cons (loc_on_music (@3, $1), $3);
1742 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1745 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup PITCH_IDENTIFIER
1747 SCM m = make_music_from_simple (parser, @4, $4);
1748 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1750 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1752 } else if (scm_is_true (scm_call_1 ($2, $4)))
1754 MYREPARSE (@4, $2, PITCH_ARG, $4);
1757 $$ = scm_cons (loc_on_music (@3, $1), $3);
1758 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1761 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NOTENAME_PITCH
1763 SCM m = make_music_from_simple (parser, @4, $4);
1764 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1766 MYREPARSE (@4, $2, NOTENAME_PITCH, $4);
1768 } else if (scm_is_true (scm_call_1 ($2, $4)))
1770 MYREPARSE (@4, $2, PITCH_ARG, $4);
1773 $$ = scm_cons (loc_on_music (@3, $1), $3);
1774 MYBACKUP (NOTENAME_PITCH, $4, @4);
1777 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup TONICNAME_PITCH
1779 SCM m = make_music_from_simple (parser, @4, $4);
1780 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1782 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1784 } else if (scm_is_true (scm_call_1 ($2, $4)))
1786 MYREPARSE (@4, $2, PITCH_ARG, $4);
1789 $$ = scm_cons (loc_on_music (@3, $1), $3);
1790 MYBACKUP (TONICNAME_PITCH, $4, @4);
1793 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1795 if (scm_is_true (scm_call_1 ($2, $4)))
1797 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1800 $$ = scm_cons (loc_on_music (@3, $1), $3);
1801 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1804 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1806 SCM res = try_string_variants ($2, $4);
1807 if (!SCM_UNBNDP (res))
1808 if (scm_is_pair (res)) {
1810 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1813 $$ = scm_cons (res, $3);
1815 $$ = scm_cons (loc_on_music (@3, $1), $3);
1816 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1819 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1821 SCM res = try_string_variants ($2, $4);
1822 if (!SCM_UNBNDP (res))
1823 if (scm_is_pair (res)) {
1825 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1828 $$ = scm_cons (res, $3);
1830 $$ = scm_cons (loc_on_music (@3, $1), $3);
1831 MYBACKUP (STRING, $4, @4);
1834 | function_arglist_backup REPARSE music_assign
1836 if (scm_is_true (scm_call_1 ($2, $3)))
1837 $$ = scm_cons ($3, $1);
1839 $$ = check_scheme_arg (parser, @3,
1840 make_music_from_simple
1844 | function_arglist_backup REPARSE pitch_arg
1846 $$ = check_scheme_arg (parser, @3,
1849 | function_arglist_backup REPARSE bare_number_common
1851 $$ = check_scheme_arg (parser, @3,
1854 | function_arglist_backup REPARSE duration_length
1856 $$ = check_scheme_arg (parser, @3,
1859 | function_arglist_backup REPARSE symbol_list_arg
1861 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1866 function_arglist_nonbackup
1867 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1869 $$ = scm_cons (loc_on_music (@4, $1), $3);
1873 function_arglist_skip_nonbackup:
1874 function_arglist_nonbackup
1875 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1877 $$ = scm_cons (loc_on_music (@3, $1), $3);
1881 function_arglist_common:
1882 EXPECT_NO_MORE_ARGS {
1885 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1887 if (scm_is_true (scm_call_1 ($1, $3)))
1888 $$ = scm_cons ($3, $2);
1890 $$ = check_scheme_arg (parser, @3,
1891 make_music_from_simple
1895 | EXPECT_SCM function_arglist_optional bare_number_common
1897 $$ = check_scheme_arg (parser, @3,
1900 | EXPECT_SCM function_arglist_optional post_event_nofinger
1902 $$ = check_scheme_arg (parser, @3,
1905 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1907 SCM n = scm_difference ($4, SCM_UNDEFINED);
1908 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1910 | function_arglist_common_reparse REPARSE SCM_ARG
1912 $$ = check_scheme_arg (parser, @3,
1915 | function_arglist_common_reparse REPARSE lyric_element_music
1917 $$ = check_scheme_arg (parser, @3,
1920 | function_arglist_common_reparse REPARSE bare_number_common
1922 $$ = check_scheme_arg (parser, @3,
1925 | function_arglist_common_reparse REPARSE duration_length
1927 $$ = check_scheme_arg (parser, @3,
1930 | function_arglist_common_reparse REPARSE symbol_list_arg
1932 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1936 function_arglist_common_reparse:
1937 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1940 SCM res = try_string_variants ($1, $3);
1941 if (!SCM_UNBNDP (res))
1942 if (scm_is_pair (res))
1943 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1945 MYREPARSE (@3, $1, SCM_ARG, res);
1946 else if (scm_is_true
1948 ($1, make_music_from_simple (parser, @3, $3))))
1949 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1951 // This is going to flag a syntax error, we
1952 // know the predicate to be false.
1953 MYREPARSE (@3, $1, SCM_ARG, $3);
1955 | EXPECT_SCM function_arglist_optional STRING
1958 SCM res = try_string_variants ($1, $3);
1959 if (!SCM_UNBNDP (res))
1960 if (scm_is_pair (res))
1961 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1963 MYREPARSE (@3, $1, SCM_ARG, res);
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 full_markup
1976 if (scm_is_true (scm_call_1 ($1, $3)))
1977 MYREPARSE (@3, $1, SCM_ARG, $3);
1978 else if (scm_is_true
1980 ($1, make_music_from_simple (parser, @3, $3))))
1981 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1983 // This is going to flag a syntax error, we
1984 // know the predicate to be false.
1985 MYREPARSE (@3, $1, SCM_ARG, $3);
1987 | EXPECT_SCM function_arglist_optional UNSIGNED
1990 if (scm_is_true (scm_call_1 ($1, $3)))
1991 MYREPARSE (@3, $1, REAL, $3);
1993 SCM d = make_duration ($3);
1994 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
1995 MYREPARSE (@3, $1, REAL, $3);
1997 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2000 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2003 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2005 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2008 SCM n = scm_difference ($4, SCM_UNDEFINED);
2009 if (scm_is_true (scm_call_1 ($1, n)))
2010 MYREPARSE (@4, $1, REAL, n);
2012 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2013 t->set_property ("digit", $4);
2014 SCM m = t->unprotect ();
2015 if (scm_is_true (scm_call_1 ($1, m)))
2016 MYREPARSE (@4, $1, SCM_ARG, m);
2018 MYREPARSE (@4, $1, SCM_ARG, $4);
2022 | EXPECT_SCM function_arglist_optional '-' REAL
2025 SCM n = scm_difference ($4, SCM_UNDEFINED);
2026 MYREPARSE (@4, $1, REAL, n);
2030 function_arglist_closed:
2031 function_arglist_closed_nonbackup
2032 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2034 $$ = scm_cons (loc_on_music (@4, $1), $3);
2038 function_arglist_closed_common:
2039 EXPECT_NO_MORE_ARGS {
2042 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
2044 $$ = check_scheme_arg (parser, @3,
2047 | EXPECT_SCM function_arglist_optional bare_number_common_closed
2049 $$ = check_scheme_arg (parser, @3,
2052 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2054 $$ = check_scheme_arg (parser, @3,
2055 scm_difference ($4, SCM_UNDEFINED),
2058 | EXPECT_SCM function_arglist_optional post_event_nofinger
2060 $$ = check_scheme_arg (parser, @3,
2063 | function_arglist_common_reparse REPARSE SCM_ARG
2065 $$ = check_scheme_arg (parser, @3,
2068 | function_arglist_common_reparse REPARSE bare_number_common_closed
2070 $$ = check_scheme_arg (parser, @3,
2073 | function_arglist_common_reparse REPARSE symbol_list_arg
2075 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2079 function_arglist_optional:
2080 function_arglist_backup
2081 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2083 $$ = scm_cons (loc_on_music (@4, $1), $3);
2085 | function_arglist_skip_backup BACKUP
2088 function_arglist_skip_backup:
2089 function_arglist_backup
2090 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2092 $$ = scm_cons (loc_on_music (@3, $1), $3);
2096 embedded_scm_closed:
2098 | scm_function_call_closed
2101 embedded_scm_arg_closed:
2102 embedded_scm_bare_arg
2103 | scm_function_call_closed
2107 scm_function_call_closed:
2108 SCM_FUNCTION function_arglist_closed {
2109 $$ = MAKE_SYNTAX ("music-function", @$,
2114 music_function_call:
2115 MUSIC_FUNCTION function_arglist {
2116 $$ = MAKE_SYNTAX ("music-function", @$,
2123 /**/ { $$ = SCM_EOL; }
2124 | '=' simple_string {
2131 | repeated_music { $$ = $1; }
2132 | re_rhythmed_music { $$ = $1; }
2133 | complex_music_prefix music
2135 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2139 complex_music_prefix:
2140 CONTEXT symbol optional_id optional_context_mod {
2141 Context_mod *ctxmod = unsmob_context_mod ($4);
2144 mods = ctxmod->get_mods ();
2145 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2147 | NEWCONTEXT symbol optional_id optional_context_mod {
2148 Context_mod *ctxmod = unsmob_context_mod ($4);
2151 mods = ctxmod->get_mods ();
2152 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2157 mode_changing_head grouped_music_list {
2158 if ($1 == ly_symbol2scm ("chords"))
2160 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2166 parser->lexer_->pop_state ();
2168 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2169 Context_mod *ctxmod = unsmob_context_mod ($2);
2172 mods = ctxmod->get_mods ();
2173 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2174 if ($1 == ly_symbol2scm ("ChordNames"))
2176 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2178 parser->lexer_->pop_state ();
2184 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2185 parser->lexer_->push_note_state (nn);
2187 $$ = ly_symbol2scm ("notes");
2191 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2192 parser->lexer_->push_note_state (nn);
2194 $$ = ly_symbol2scm ("drums");
2197 parser->lexer_->push_figuredbass_state ();
2199 $$ = ly_symbol2scm ("figures");
2202 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2203 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2204 nn = parser->lexer_->lookup_identifier ("pitchnames");
2205 parser->lexer_->push_chord_state (nn);
2206 $$ = ly_symbol2scm ("chords");
2210 { parser->lexer_->push_lyric_state ();
2211 $$ = ly_symbol2scm ("lyrics");
2215 mode_changing_head_with_context:
2217 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2218 parser->lexer_->push_note_state (nn);
2220 $$ = ly_symbol2scm ("DrumStaff");
2223 parser->lexer_->push_figuredbass_state ();
2225 $$ = ly_symbol2scm ("FiguredBass");
2228 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2229 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2230 nn = parser->lexer_->lookup_identifier ("pitchnames");
2231 parser->lexer_->push_chord_state (nn);
2232 $$ = ly_symbol2scm ("ChordNames");
2235 { parser->lexer_->push_lyric_state ();
2236 $$ = ly_symbol2scm ("Lyrics");
2241 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2244 /* Can also use music at the expensive of two S/Rs similar to
2245 \repeat \alternative */
2246 parser->lexer_->pop_state ();
2248 $$ = scm_cons ($3, SCM_EOL);
2250 | new_lyrics ADDLYRICS {
2251 parser->lexer_->push_lyric_state ();
2253 parser->lexer_->pop_state ();
2254 $$ = scm_cons ($4, $1);
2259 composite_music new_lyrics {
2260 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2262 | LYRICSTO simple_string {
2263 parser->lexer_->push_lyric_state ();
2265 parser->lexer_->pop_state ();
2266 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2271 CHANGE symbol '=' simple_string {
2272 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2279 $$ = scm_reverse_x ($1, SCM_EOL);
2281 | symbol_list_rev property_path {
2282 $$ = scm_reverse_x ($1, $2);
2288 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2291 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2293 | OVERRIDE property_path '=' scalar {
2294 if (scm_ilength ($2) < 2) {
2295 parser->parser_error (@2, _("bad grob property path"));
2298 $$ = scm_cons (ly_symbol2scm ("push"),
2299 scm_cons2 (scm_car ($2),
2304 | REVERT revert_arg {
2305 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2309 // This is all quite awkward for the sake of substantial backward
2310 // compatibility while at the same time allowing a more "natural" form
2311 // of specification not separating grob specification from grob
2312 // property path. The purpose of this definition of revert_arg is to
2313 // allow the symbol list which specifies grob and property to revert
2314 // to be optionally be split into two parts after the grob (which in
2315 // this case is just the first element of the list). symbol_list_part
2316 // is only one path component, but it can be parsed without lookahead,
2317 // so we can follow it with a synthetic BACKUP token when needed. If
2318 // the first symbol_list_part already contains multiple elements (only
2319 // possible if a Scheme expression provides them), we just parse for
2320 // additional elements introduced by '.', which is what the
2321 // SYMBOL_LIST backup in connection with the immediately following
2322 // rule using symbol_list_arg does.
2324 // As long as we don't have our coffers filled with both grob and at
2325 // least one grob property specification, the rest of the required
2326 // symbol list chain may be provided either with or without a leading
2327 // dot. This is for both allowing the traditional
2328 // \revert Accidental #'color
2329 // as well as well as the "naive" form
2330 // \revert Accidental.color
2333 revert_arg_backup BACKUP symbol_list_arg
2342 if (scm_is_null ($1)
2343 || scm_is_null (scm_cdr ($1)))
2344 MYBACKUP (SCM_ARG, $1, @1);
2346 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2350 // revert_arg_part delivers results in reverse
2353 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2355 $$ = scm_append_x (scm_list_2 ($5, $3));
2357 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2359 $$ = scm_append_x (scm_list_2 ($4, $3));
2364 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2365 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2367 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2368 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2369 | DENIES { $$ = ly_symbol2scm ("denies"); }
2371 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2372 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2373 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2374 | NAME { $$ = ly_symbol2scm ("context-name"); }
2378 property_operation { $$ = $1; }
2379 | context_def_mod STRING {
2380 $$ = scm_list_2 ($1, $2);
2382 | context_def_mod embedded_scm
2384 if (!scm_is_string ($2)
2385 && ly_symbol2scm ("consists") != $1
2386 && ly_symbol2scm ("remove") != $1)
2389 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2393 $$ = scm_list_2 ($1, $2);
2398 // If defined, at least two members.
2402 SCM l = scm_reverse_x ($1, SCM_EOL);
2405 (scm_object_property (scm_car (l),
2406 ly_symbol2scm ("is-grob?"))))
2407 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2408 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2409 parser->parser_error (@1, _ ("bad grob property path"));
2416 // If defined, at least three members
2420 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2422 parser->parser_error (@1, _ ("bad grob property path"));
2426 | grob_prop_spec property_path
2428 if (!SCM_UNBNDP ($1)) {
2429 $$ = scm_append_x (scm_list_2 ($1, $2));
2430 if (scm_is_null (scm_cddr ($$))) {
2431 parser->parser_error (@$, _ ("bad grob property path"));
2439 // Exactly two elements or undefined
2443 SCM l = scm_reverse_x ($1, SCM_EOL);
2444 switch (scm_ilength (l)) {
2446 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2450 parser->parser_error (@1, _ ("bad context property path"));
2457 simple_music_property_def:
2458 OVERRIDE grob_prop_path '=' scalar {
2459 if (SCM_UNBNDP ($2))
2462 $$ = scm_list_5 (scm_car ($2),
2463 ly_symbol2scm ("OverrideProperty"),
2469 | REVERT simple_revert_context revert_arg {
2470 $$ = scm_list_4 ($2,
2471 ly_symbol2scm ("RevertProperty"),
2475 | SET context_prop_spec '=' scalar {
2476 if (SCM_UNBNDP ($2))
2479 $$ = scm_list_4 (scm_car ($2),
2480 ly_symbol2scm ("PropertySet"),
2484 | UNSET context_prop_spec {
2485 if (SCM_UNBNDP ($2))
2488 $$ = scm_list_3 (scm_car ($2),
2489 ly_symbol2scm ("PropertyUnset"),
2495 // This is all quite awkward for the sake of substantial backward
2496 // compatibility while at the same time allowing a more "natural" form
2497 // of specification not separating grob specification from grob
2498 // property path. The purpose of this definition of
2499 // simple_revert_context is to allow the symbol list which specifies
2500 // grob and property to revert to be optionally be split into two
2501 // parts after the grob (which may be preceded by a context
2502 // specification, a case which we distinguish by checking whether the
2503 // first symbol is a valid grob symbol instead).
2505 // See revert_arg above for the main work horse of this arrangement.
2506 // simple_revert_context just caters for the context and delegates the
2507 // rest of the job to revert_arg.
2509 simple_revert_context:
2512 $1 = scm_reverse_x ($1, SCM_EOL);
2513 if (scm_is_null ($1)
2515 (scm_object_property (scm_car ($1),
2516 ly_symbol2scm ("is-grob?")))) {
2517 $$ = ly_symbol2scm ("Bottom");
2518 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2521 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2528 simple_music_property_def {
2529 if (SCM_UNBNDP ($1))
2530 $$ = MAKE_SYNTAX ("void-music", @1);
2532 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2543 simple_string: STRING {
2548 if (scm_is_string ($1)) {
2551 parser->parser_error (@1, (_ ("simple string expected")));
2552 $$ = scm_string (SCM_EOL);
2559 $$ = scm_string_to_symbol ($1);
2563 // This is a bit of overkill but makes the same
2564 // routine responsible for all symbol interpretations.
2565 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2567 if (SCM_UNBNDP ($$))
2569 parser->parser_error (@1, (_ ("symbol expected")));
2570 // Generate a unique symbol in case it is used
2571 // for an assignment or similar
2572 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2581 // The following is a rather defensive variant of admitting
2582 // negative numbers: the grammar would permit number_factor or
2583 // even number_expression. However, function arguments allow
2584 // only this simple kind of negative number, so to have things
2585 // like \tweak and \override behave reasonably similar, it
2586 // makes sense to rule out things like -- which are rather an
2587 // accent in function argument contexts.
2590 $$ = scm_difference ($2, SCM_UNDEFINED);
2597 simple_element post_events {
2598 // Let the rhythmic music iterator sort this mess out.
2599 if (scm_is_pair ($2)) {
2600 $$ = make_music_from_simple (parser, @1, $1);
2601 if (unsmob_music ($$))
2602 unsmob_music ($$)->set_property ("articulations",
2603 scm_reverse_x ($2, SCM_EOL));
2606 parser->parser_error (@1, _("music expected"));
2607 $$ = MAKE_SYNTAX ("void-music", @1);
2611 | simple_chord_elements post_events {
2612 if (scm_is_pair ($2)) {
2613 if (unsmob_pitch ($1))
2614 $1 = make_chord_elements (@1,
2616 parser->default_duration_.smobbed_copy (),
2619 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2621 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
2622 } else if (!unsmob_pitch ($1))
2623 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
2624 // A mere pitch drops through.
2626 | CHORD_REPETITION optional_notemode_duration post_events {
2628 i.set_location (@1, @3);
2629 $$ = MAKE_SYNTAX ("repetition-chord", i,
2630 $2, scm_reverse_x ($3, SCM_EOL));
2632 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2634 i.set_location (@1, @3);
2635 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2636 scm_reverse_x ($3, SCM_EOL));
2639 | note_chord_element
2644 chord_body optional_notemode_duration post_events
2646 Music *m = unsmob_music ($1);
2647 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2648 SCM es = m->get_property ("elements");
2649 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2651 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2652 unsmob_music (scm_car (s))->set_property ("duration", dur);
2653 es = ly_append2 (es, postevs);
2655 m-> set_property ("elements", es);
2657 $$ = m->self_scm ();
2662 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2664 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2666 | CHORD_BODY_IDENTIFIER
2669 chord_body_elements:
2670 /* empty */ { $$ = SCM_EOL; }
2671 | chord_body_elements chord_body_element {
2672 if (!SCM_UNBNDP ($2))
2673 $$ = scm_cons ($2, $1);
2678 pitch exclamations questions octave_check post_events
2680 bool q = to_boolean ($3);
2681 bool ex = to_boolean ($2);
2685 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2686 n->set_property ("pitch", $1);
2688 n->set_property ("cautionary", SCM_BOOL_T);
2690 n->set_property ("force-accidental", SCM_BOOL_T);
2692 if (scm_is_pair (post)) {
2693 SCM arts = scm_reverse_x (post, SCM_EOL);
2694 n->set_property ("articulations", arts);
2696 if (scm_is_number (check))
2698 int q = scm_to_int (check);
2699 n->set_property ("absolute-octave", scm_from_int (q-1));
2702 $$ = n->unprotect ();
2704 | DRUM_PITCH post_events {
2705 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2706 n->set_property ("drum-type", $1);
2708 if (scm_is_pair ($2)) {
2709 SCM arts = scm_reverse_x ($2, SCM_EOL);
2710 n->set_property ("articulations", arts);
2712 $$ = n->unprotect ();
2714 | music_function_chord_body
2716 Music *m = unsmob_music ($1);
2718 while (m && m->is_mus_type ("music-wrapper-music")) {
2719 $$ = m->get_property ("element");
2720 m = unsmob_music ($$);
2723 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2724 parser->parser_error (@$, _ ("not a rhythmic event"));
2730 music_function_chord_body:
2735 // Event functions may only take closed arglists, otherwise it would
2736 // not be clear whether a following postevent should be associated
2737 // with the last argument of the event function or with the expression
2738 // for which the function call acts itself as event.
2740 music_function_call_closed:
2741 MUSIC_FUNCTION function_arglist_closed {
2742 $$ = MAKE_SYNTAX ("music-function", @$,
2747 event_function_event:
2748 EVENT_FUNCTION function_arglist_closed {
2749 $$ = MAKE_SYNTAX ("music-function", @$,
2771 | post_events post_event {
2773 if (Music *m = unsmob_music ($2))
2775 if (m->is_mus_type ("post-event-wrapper"))
2777 for (SCM p = m->get_property ("elements");
2781 $$ = scm_cons (scm_car (p), $$);
2785 $$ = scm_cons ($2, $$);
2791 post_event_nofinger:
2792 direction_less_event {
2795 | script_dir music_function_call_closed {
2797 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2798 parser->parser_error (@2, _ ("post-event expected"));
2799 $$ = SCM_UNSPECIFIED;
2800 } else if (!SCM_UNBNDP ($1))
2802 unsmob_music ($$)->set_property ("direction", $1);
2806 if (!parser->lexer_->is_lyric_state ())
2807 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2808 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2811 if (!parser->lexer_->is_lyric_state ())
2812 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2813 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2815 | script_dir direction_reqd_event {
2816 if (!SCM_UNBNDP ($1))
2818 Music *m = unsmob_music ($2);
2819 m->set_property ("direction", $1);
2823 | script_dir direction_less_event {
2824 if (!SCM_UNBNDP ($1))
2826 Music *m = unsmob_music ($2);
2827 m->set_property ("direction", $1);
2834 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2839 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2850 string_number_event:
2852 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2853 s->set_property ("string-number", $1);
2854 $$ = s->unprotect ();
2858 direction_less_event:
2860 | EVENT_IDENTIFIER {
2864 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2865 a->set_property ("tremolo-type", $1);
2866 $$ = a->unprotect ();
2868 | event_function_event
2871 direction_reqd_event:
2875 | script_abbreviation {
2876 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2877 if (scm_is_string (s)) {
2878 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2879 a->set_property ("articulation-type", s);
2880 $$ = a->unprotect ();
2882 Music *original = unsmob_music (s);
2883 if (original && original->is_mus_type ("post-event")) {
2884 Music *a = original->clone ();
2885 a->set_spot (parser->lexer_->override_input (@$));
2886 $$ = a->unprotect ();
2888 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2889 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2896 /**/ { $$ = SCM_EOL; }
2897 | '=' quotes { $$ = $2; }
2911 $$ = scm_from_int (1);
2914 $$ = scm_oneplus ($1);
2920 $$ = scm_from_int (-1);
2923 $$ = scm_oneminus ($1);
2928 NOTENAME_PITCH quotes {
2929 if (!scm_is_eq (SCM_INUM0, $2))
2931 Pitch p = *unsmob_pitch ($1);
2932 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2933 $$ = p.smobbed_copy ();
2943 TONICNAME_PITCH quotes {
2944 if (!scm_is_eq (SCM_INUM0, $2))
2946 Pitch p = *unsmob_pitch ($1);
2947 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2948 $$ = p.smobbed_copy ();
2955 | PITCH_IDENTIFIER quotes {
2956 if (!scm_is_eq (SCM_INUM0, $2))
2958 Pitch p = *unsmob_pitch ($1);
2959 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2960 $$ = p.smobbed_copy ();
2967 if (!scm_is_eq (SCM_INUM0, $2))
2969 Pitch p = *unsmob_pitch ($1);
2970 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2971 $$ = p.smobbed_copy ();
2978 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2979 t->set_property ("text", $1);
2980 $$ = t->unprotect ();
2983 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2984 t->set_property ("text",
2985 make_simple_markup ($1));
2986 $$ = t->unprotect ();
2988 | embedded_scm_closed
2990 Music *m = unsmob_music ($1);
2991 if (m && m->is_mus_type ("post-event"))
2993 else if (Text_interface::is_markup ($1)) {
2994 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2995 t->set_property ("text", $1);
2996 $$ = t->unprotect ();
2998 parser->parser_error (@1, _ ("not an articulation"));
3004 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3005 t->set_property ("digit", $1);
3006 $$ = t->unprotect ();
3010 script_abbreviation:
3012 $$ = scm_from_locale_string ("Hat");
3015 $$ = scm_from_locale_string ("Plus");
3018 $$ = scm_from_locale_string ("Dash");
3021 $$ = scm_from_locale_string ("Bang");
3024 $$ = scm_from_locale_string ("Larger");
3027 $$ = scm_from_locale_string ("Dot");
3030 $$ = scm_from_locale_string ("Underscore");
3035 '_' { $$ = scm_from_int (DOWN); }
3036 | '^' { $$ = scm_from_int (UP); }
3037 | '-' { $$ = SCM_UNDEFINED; }
3041 multiplied_duration {
3046 maybe_notemode_duration:
3050 | multiplied_duration {
3052 parser->default_duration_ = *unsmob_duration ($$);
3057 optional_notemode_duration:
3058 maybe_notemode_duration
3060 if (SCM_UNBNDP ($$))
3061 $$ = parser->default_duration_.smobbed_copy ();
3067 $$ = make_duration ($1, scm_to_int ($2));
3068 if (SCM_UNBNDP ($$))
3070 parser->parser_error (@1, _ ("not a duration"));
3071 $$ = Duration ().smobbed_copy ();
3074 | DURATION_IDENTIFIER dots {
3075 Duration *d = unsmob_duration ($1);
3076 Duration k (d->duration_log (),
3077 d->dot_count () + scm_to_int ($2));
3078 k = k.compressed (d->factor ());
3079 scm_remember_upto_here_1 ($1);
3080 $$ = k.smobbed_copy ();
3084 multiplied_duration:
3088 | multiplied_duration '*' UNSIGNED {
3089 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
3091 | multiplied_duration '*' FRACTION {
3092 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
3094 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
3103 $$ = scm_oneplus ($1);
3112 if (SCM_UNBNDP (make_duration ($2)))
3113 parser->parser_error (@2, _ ("not a duration"));
3119 UNSIGNED { $$ = $1; }
3120 | STRING { $$ = $1; }
3121 | full_markup { $$ = $1; }
3124 // as an integer, it needs to be non-negative, and otherwise
3125 // it needs to be suitable as a markup.
3126 if (scm_is_integer ($1)
3127 ? scm_is_true (scm_negative_p ($1))
3128 : !Text_interface::is_markup ($1))
3130 parser->parser_error (@1, _ ("bass number expected"));
3136 figured_bass_alteration:
3137 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3138 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3139 | '!' { $$ = scm_from_int (0); }
3144 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3145 $$ = bfr->unprotect ();
3148 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3149 $$ = bfr->self_scm ();
3151 if (scm_is_number ($1))
3152 bfr->set_property ("figure", $1);
3153 else if (Text_interface::is_markup ($1))
3154 bfr->set_property ("text", $1);
3160 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3162 | bass_figure figured_bass_alteration {
3163 Music *m = unsmob_music ($1);
3164 if (scm_to_double ($2)) {
3165 SCM salter = m->get_property ("alteration");
3166 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3167 m->set_property ("alteration",
3168 scm_sum (alter, $2));
3170 m->set_property ("alteration", scm_from_int (0));
3173 | bass_figure figured_bass_modification {
3174 Music *m = unsmob_music ($1);
3175 m->set_property ($2, SCM_BOOL_T);
3180 figured_bass_modification:
3182 $$ = ly_symbol2scm ("augmented");
3185 $$ = ly_symbol2scm ("no-continuation");
3188 $$ = ly_symbol2scm ("diminished");
3191 $$ = ly_symbol2scm ("augmented-slash");
3201 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3209 | figure_list br_bass_figure {
3210 $$ = scm_cons ($2, $1);
3215 FIGURE_OPEN figure_list FIGURE_CLOSE {
3216 $$ = scm_reverse_x ($2, SCM_EOL);
3222 /**/ { $$ = SCM_BOOL_F; }
3223 | REST { $$ = SCM_BOOL_T; }
3227 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3228 if (!parser->lexer_->is_note_state ())
3229 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3230 if (!SCM_UNBNDP ($2)
3232 || scm_is_number ($4)
3234 || scm_is_true ($6))
3237 if (scm_is_true ($6))
3238 n = MY_MAKE_MUSIC ("RestEvent", @$);
3240 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3242 n->set_property ("pitch", $1);
3243 if (SCM_UNBNDP ($5))
3244 n->set_property ("duration",
3245 parser->default_duration_.smobbed_copy ());
3247 n->set_property ("duration", $5);
3249 if (scm_is_number ($4))
3251 int q = scm_to_int ($4);
3252 n->set_property ("absolute-octave", scm_from_int (q-1));
3255 if (to_boolean ($3))
3256 n->set_property ("cautionary", SCM_BOOL_T);
3257 if (to_boolean ($2) || to_boolean ($3))
3258 n->set_property ("force-accidental", SCM_BOOL_T);
3260 $$ = n->unprotect ();
3263 | DRUM_PITCH optional_notemode_duration {
3264 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3265 n->set_property ("duration", $2);
3266 n->set_property ("drum-type", $1);
3268 $$ = n->unprotect ();
3270 | RESTNAME optional_notemode_duration {
3272 if (ly_scm2string ($1) == "s") {
3274 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3277 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3280 ev->set_property ("duration", $2);
3281 $$ = ev->unprotect ();
3285 // Can return a single pitch rather than a list.
3286 simple_chord_elements:
3288 if (!parser->lexer_->is_chord_state ())
3289 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3292 | figure_spec optional_notemode_duration {
3293 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3295 unsmob_music (scm_car (s))->set_property ("duration", $2);
3303 if (!parser->lexer_->is_lyric_state ())
3304 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3308 if (!parser->lexer_->is_lyric_state ())
3309 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3315 lyric_element_music:
3316 lyric_element optional_notemode_duration post_events {
3317 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3318 if (scm_is_pair ($3))
3319 unsmob_music ($$)->set_property
3320 ("articulations", scm_reverse_x ($3, SCM_EOL));
3324 // Can return a single pitch rather than a list.
3326 steno_tonic_pitch maybe_notemode_duration {
3327 if (SCM_UNBNDP ($2))
3330 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3332 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3333 SCM its = scm_reverse_x ($4, SCM_EOL);
3334 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3342 | chord_items chord_item {
3343 $$ = scm_cons ($2, $$);
3349 $$ = ly_symbol2scm ("chord-colon");
3352 $$ = ly_symbol2scm ("chord-caret");
3354 | CHORD_SLASH steno_tonic_pitch {
3355 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3357 | CHORD_BASS steno_tonic_pitch {
3358 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3367 $$ = scm_reverse_x ($1, SCM_EOL);
3375 step_number { $$ = scm_cons ($1, SCM_EOL); }
3376 | step_numbers '.' step_number {
3377 $$ = scm_cons ($3, $$);
3383 $$ = make_chord_step ($1, 0);
3386 $$ = make_chord_step ($1, SHARP_ALTERATION);
3388 | UNSIGNED CHORD_MINUS {
3389 $$ = make_chord_step ($1, FLAT_ALTERATION);
3397 | unsigned_number '-' unsigned_number {
3398 $$ = scm_cons ($1, $3);
3405 TODO: should deprecate in favor of Scheme?
3409 number_expression '+' number_term {
3410 $$ = scm_sum ($1, $3);
3412 | number_expression '-' number_term {
3413 $$ = scm_difference ($1, $3);
3422 | number_factor '*' number_factor {
3423 $$ = scm_product ($1, $3);
3425 | number_factor '/' number_factor {
3426 $$ = scm_divide ($1, $3);
3431 '-' number_factor { /* %prec UNARY_MINUS */
3432 $$ = scm_difference ($2, SCM_UNDEFINED);
3438 bare_number_common_closed
3439 | REAL NUMBER_IDENTIFIER
3441 $$ = scm_product ($1, $2);
3445 bare_number_common_closed:
3453 | UNSIGNED NUMBER_IDENTIFIER {
3454 $$ = scm_product ($1, $2);
3460 | bare_number_common_closed
3467 if (!scm_is_integer ($1)
3468 || scm_is_true (scm_negative_p ($1)))
3470 parser->parser_error (@1, _("not an unsigned integer"));
3476 if (!scm_is_integer ($1)
3477 || scm_is_true (scm_negative_p ($1)))
3479 parser->parser_error (@1, _("not an unsigned integer"));
3486 { $$ = SCM_UNDEFINED; }
3489 if (SCM_UNBNDP ($1))
3497 { $$ = SCM_UNDEFINED; }
3500 if (SCM_UNBNDP ($1))
3509 { parser->lexer_->push_markup_state (); }
3512 parser->lexer_->pop_state ();
3518 { parser->lexer_->push_markup_state (); }
3521 parser->lexer_->pop_state ();
3527 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3529 | markup_head_1_list simple_markup
3531 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3532 @2, $1, scm_list_1 ($2)));
3542 if (Text_interface::is_markup ($1))
3543 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3544 else if (Text_interface::is_markup_list ($1))
3545 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3547 parser->parser_error (@1, _ ("not a markup"));
3548 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3555 markup_composed_list {
3558 | markup_uncomposed_list
3561 markup_uncomposed_list:
3562 markup_braced_list {
3565 | markup_command_list {
3566 $$ = scm_list_1 ($1);
3568 | markup_scm MARKUPLIST_IDENTIFIER
3573 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3574 parser->lexer_->push_note_state (nn);
3575 } '{' score_body '}' {
3576 unsmob_score ($4)->origin ()->set_spot (@$);
3577 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3578 parser->lexer_->pop_state ();
3582 markup_composed_list:
3583 markup_head_1_list markup_uncomposed_list {
3584 $$ = MAKE_SYNTAX ("composed-markup-list",
3590 '{' markup_braced_list_body '}' {
3591 $$ = scm_reverse_x ($2, SCM_EOL);
3595 markup_braced_list_body:
3596 /* empty */ { $$ = SCM_EOL; }
3597 | markup_braced_list_body markup {
3598 $$ = scm_cons ($2, $1);
3600 | markup_braced_list_body markup_list {
3601 $$ = scm_reverse_x ($2, $1);
3605 markup_command_list:
3606 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3607 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3611 markup_command_basic_arguments:
3612 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3613 $$ = scm_cons ($3, $2);
3615 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3616 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3618 | EXPECT_NO_MORE_ARGS {
3623 markup_command_list_arguments:
3624 markup_command_basic_arguments { $$ = $1; }
3625 | EXPECT_MARKUP markup_command_list_arguments markup {
3626 $$ = scm_cons ($3, $2);
3631 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3632 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3637 markup_head_1_item {
3638 $$ = scm_list_1 ($1);
3640 | markup_head_1_list markup_head_1_item {
3641 $$ = scm_cons ($2, $1);
3647 $$ = make_simple_markup ($1);
3650 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3651 parser->lexer_->push_note_state (nn);
3652 } '{' score_body '}' {
3653 unsmob_score ($4)->origin ()->set_spot (@$);
3654 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3655 parser->lexer_->pop_state ();
3657 | MARKUP_FUNCTION markup_command_basic_arguments {
3658 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3660 | markup_scm MARKUP_IDENTIFIER
3667 markup_head_1_list simple_markup
3669 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3670 @2, $1, scm_list_1 ($2)));
3680 Lily_parser::set_yydebug (bool x)
3686 Lily_parser::do_yyparse ()
3688 SCM retval = SCM_UNDEFINED;
3689 yyparse (this, &retval);
3699 It is a little strange to have this function in this file, but
3700 otherwise, we have to import music classes into the lexer.
3704 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3706 if (unsmob_book (sid)) {
3707 Book *book = unsmob_book (sid)->clone ();
3708 *destination = book->self_scm ();
3711 return BOOK_IDENTIFIER;
3712 } else if (scm_is_number (sid)) {
3714 return NUMBER_IDENTIFIER;
3715 } else if (unsmob_context_def (sid)) {
3716 Context_def *def= unsmob_context_def (sid)->clone ();
3718 *destination = def->self_scm ();
3721 return CONTEXT_DEF_IDENTIFIER;
3722 } else if (unsmob_context_mod (sid)) {
3723 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3725 return CONTEXT_MOD_IDENTIFIER;
3726 } else if (Music *mus = unsmob_music (sid)) {
3727 mus = mus->clone ();
3728 *destination = mus->self_scm ();
3729 bool is_event = mus->is_mus_type ("post-event");
3731 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3732 } else if (unsmob_pitch (sid)) {
3733 *destination = unsmob_pitch (sid)->smobbed_copy ();
3734 return PITCH_IDENTIFIER;
3735 } else if (unsmob_duration (sid)) {
3736 *destination = unsmob_duration (sid)->smobbed_copy ();
3737 return DURATION_IDENTIFIER;
3738 } else if (unsmob_output_def (sid)) {
3739 Output_def *p = unsmob_output_def (sid);
3742 *destination = p->self_scm ();
3744 return OUTPUT_DEF_IDENTIFIER;
3745 } else if (unsmob_score (sid)) {
3746 *destination = unsmob_score (sid)->clone ()->unprotect ();
3747 return SCM_IDENTIFIER;
3754 get_next_unique_context_id ()
3756 return scm_from_locale_string ("$uniqueContextId");
3761 get_next_unique_lyrics_context_id ()
3763 static int new_context_count;
3765 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3766 return scm_from_locale_string (s);
3769 // check_scheme_arg checks one argument with a given predicate for use
3770 // in an argument list and throws a syntax error if it is unusable.
3771 // The argument is prepended to the argument list in any case. After
3772 // throwing a syntax error, the argument list is terminated with #f as
3773 // its last cdr in order to mark it as uncallable while not losing
3774 // track of its total length.
3776 // There are a few special considerations: if optional argument disp
3777 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3778 // instead of arg in a prospective error message. This is useful if
3779 // arg is not the actual argument but rather a transformation of it.
3781 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3782 // and an error message using disp is produced unconditionally.
3784 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3785 SCM arg, SCM args, SCM pred, SCM disp)
3787 if (SCM_UNBNDP (arg))
3788 args = scm_cons (disp, args);
3790 args = scm_cons (arg, args);
3791 if (scm_is_true (scm_call_1 (pred, arg)))
3794 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3795 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3796 SCM_UNBNDP (disp) ? arg : disp);
3797 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3801 SCM loc_on_music (Input loc, SCM arg)
3803 if (Music *m = unsmob_music (arg))
3807 return m->unprotect ();
3813 try_string_variants (SCM pred, SCM str)
3815 // a matching predicate is always ok
3816 if (scm_is_true (scm_call_1 (pred, str)))
3818 // a symbol may be interpreted as a list of symbols if it helps
3819 if (scm_is_symbol (str)) {
3820 str = scm_list_1 (str);
3821 if (scm_is_true (scm_call_1 (pred, str)))
3823 return SCM_UNDEFINED;
3826 // If this cannot be a string representation of a symbol list,
3829 if (!is_regular_identifier (str, true))
3830 return SCM_UNDEFINED;
3832 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3833 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3834 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3836 // Let's attempt the symbol list interpretation first.
3838 if (scm_is_true (scm_call_1 (pred, str)))
3841 // If there is just one symbol in the list, we might interpret
3842 // it as a single symbol
3844 if (scm_is_null (scm_cdr (str)))
3846 str = scm_car (str);
3847 if (scm_is_true (scm_call_1 (pred, str)))
3851 return SCM_UNDEFINED;
3855 is_regular_identifier (SCM id, bool multiple)
3857 if (!scm_is_string (id))
3860 string str = ly_scm2string (id);
3862 bool middle = false;
3864 for (string::iterator it=str.begin(); it != str.end (); it++)
3867 if ((c >= 'a' && c <= 'z')
3868 || (c >= 'A' && c <= 'Z')
3871 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3880 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3882 if (unsmob_music (simple))
3884 if (parser->lexer_->is_note_state ()) {
3885 if (scm_is_symbol (simple)) {
3886 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3887 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3888 n->set_property ("drum-type", simple);
3889 return n->unprotect ();
3891 if (unsmob_pitch (simple)) {
3892 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3893 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3894 n->set_property ("pitch", simple);
3895 return n->unprotect ();
3898 } else if (parser->lexer_->is_lyric_state ()) {
3899 if (Text_interface::is_markup (simple))
3900 return MAKE_SYNTAX ("lyric-event", loc, simple,
3901 parser->default_duration_.smobbed_copy ());
3902 } else if (parser->lexer_->is_chord_state ()) {
3903 if (unsmob_pitch (simple))
3907 make_chord_elements (loc, simple,
3908 parser->default_duration_.smobbed_copy (),
3915 make_music_with_input (SCM name, Input where)
3917 Music *m = make_music_by_name (name);
3918 m->set_spot (where);
3923 make_simple_markup (SCM a)
3929 make_duration (SCM d, int dots)
3931 int t = scm_to_int (d);
3932 if (t > 0 && (t & (t-1)) == 0)
3933 return Duration (intlog2 (t), dots).smobbed_copy ();
3935 return SCM_UNDEFINED;
3939 make_chord_step (SCM step_scm, Rational alter)
3941 int step = scm_to_int (step_scm);
3944 alter += FLAT_ALTERATION;
3948 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3949 return m.smobbed_copy ();
3954 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3956 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3957 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3958 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3960 unsmob_music (scm_car (s))->set_spot (loc);
3966 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3968 Lily_lexer *lex = parser->lexer_;
3972 int tok = lex->pop_extra_token ();
3975 lex->prepare_for_next_token ();
3976 return lex->yylex ();