1 /* -*- mode: c++; c-file-style: "linux"; indent-tabs-mode: t -*- */
3 This file is part of LilyPond, the GNU music typesetter.
5 Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 Jan Nieuwenhuizen <janneke@gnu.org>
8 LilyPond is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 /* Mode and indentation are at best a rough approximation based on TAB
23 * formatting (reasonable for compatibility with unspecific editor
24 * modes as Bison modes are hard to find) and need manual correction
25 * frequently. Without a reasonably dependable way of formatting a
26 * Bison file sensibly, there is little point in trying to fix the
27 * inconsistent state of indentation.
32 #define yyerror Lily_parser::parser_error
34 /* We use custom location type: Input objects */
37 #define YYLLOC_DEFAULT(Current,Rhs,N) \
38 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
40 #define YYPRINT(file, type, value) \
42 if (scm_is_eq (value, SCM_UNSPECIFIED)) \
44 char *p = scm_to_locale_string \
45 (scm_simple_format (SCM_BOOL_F, \
46 scm_from_locale_string ("~S"), \
47 scm_list_1 (value))); \
54 %parse-param {Lily_parser *parser}
55 %parse-param {SCM *retval}
56 %lex-param {Lily_parser *parser}
60 /* We use SCMs to do strings, because it saves us the trouble of
61 deleting them. Let's hope that a stack overflow doesn't trigger a move
62 of the parse stack onto the heap. */
65 %nonassoc REPEAT REPEAT_IDENTIFIER
68 /* The above precedences tackle the shift/reduce problem
71 \repeat .. \alternative
73 \repeat { \repeat .. \alternative }
77 \repeat { \repeat } \alternative
83 %right ':' UNSIGNED REAL E_UNSIGNED EVENT_IDENTIFIER EVENT_FUNCTION '^' '_'
84 HYPHEN EXTENDER DURATION_IDENTIFIER
86 /* The above are needed for collecting tremoli and other items (that
87 could otherwise be interpreted as belonging to the next function
88 argument) greedily, and together with the next rule will serve to
89 join numbers and units greedily instead of allowing them into
90 separate function arguments
93 %nonassoc NUMBER_IDENTIFIER
105 %{ // -*-Fundamental-*-
110 * The rules for who is protecting what are very shady. Uniformise
113 * There are too many lexical modes?
124 #include "context-def.hh"
125 #include "context-mod.hh"
126 #include "dimensions.hh"
127 #include "file-path.hh"
129 #include "international.hh"
130 #include "lily-guile.hh"
131 #include "lily-lexer.hh"
132 #include "lily-parser.hh"
136 #include "output-def.hh"
137 #include "paper-book.hh"
138 #include "scm-hash.hh"
140 #include "text-interface.hh"
144 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
146 parser->parser_error (*i, s);
149 #define MYBACKUP(Token, Value, Location) \
151 if (yychar == YYEMPTY) \
154 parser->lexer_->push_extra_token (Token, Value); \
155 parser->lexer_->push_extra_token (BACKUP); \
157 parser->parser_error \
158 (Location, _("Too much lookahead")); \
163 #define MYREPARSE(Location, Pred, Token, Value) \
165 if (yychar == YYEMPTY) \
167 parser->lexer_->push_extra_token (Token, Value); \
168 parser->lexer_->push_extra_token (REPARSE, \
171 parser->parser_error \
172 (Location, _("Too much lookahead")); \
181 #define MY_MAKE_MUSIC(x, spot) \
182 make_music_with_input (ly_symbol2scm (x), \
183 parser->lexer_->override_input (spot))
186 - Don't use lily module, create a new module instead.
187 - delay application of the function
189 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
190 scm_apply_0 (proc, args)
191 /* Syntactic Sugar. */
192 #define MAKE_SYNTAX(name, location, ...) \
193 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (parser->lexer_->override_input (location)), ##__VA_ARGS__, SCM_UNDEFINED))
194 #define START_MAKE_SYNTAX(name, ...) \
195 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
196 #define FINISH_MAKE_SYNTAX(start, location, ...) \
197 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (parser->lexer_->override_input (location)), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
199 SCM get_next_unique_context_id ();
200 SCM get_next_unique_lyrics_context_id ();
207 #define _(x) gettext (x)
211 static Music *make_music_with_input (SCM name, Input where);
212 SCM check_scheme_arg (Lily_parser *parser, Input loc,
213 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
214 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
215 SCM loc_on_music (Input loc, SCM arg);
216 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
217 SCM make_chord_step (SCM step, Rational alter);
218 SCM make_simple_markup (SCM a);
219 SCM make_duration (SCM t, int dots = 0);
220 bool is_regular_identifier (SCM id, bool multiple=false);
221 SCM try_string_variants (SCM pred, SCM str);
222 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
226 /* The third option is an alias that will be used to display the
227 syntax error. Bison CVS now correctly handles backslash escapes.
229 FIXME: Bison needs to translate some of these, eg, STRING.
233 /* Keyword tokens with plain escaped name. */
234 %token END_OF_FILE 0 "end of input"
235 %token ACCEPTS "\\accepts"
236 %token ADDLYRICS "\\addlyrics"
237 %token ALIAS "\\alias"
238 %token ALTERNATIVE "\\alternative"
240 %token BOOKPART "\\bookpart"
241 %token CHANGE "\\change"
242 %token CHORDMODE "\\chordmode"
243 %token CHORDS "\\chords"
244 %token CONSISTS "\\consists"
245 %token CONTEXT "\\context"
246 %token DEFAULT "\\default"
247 %token DEFAULTCHILD "\\defaultchild"
248 %token DENIES "\\denies"
249 %token DESCRIPTION "\\description"
250 %token DRUMMODE "\\drummode"
251 %token DRUMS "\\drums"
252 %token FIGUREMODE "\\figuremode"
253 %token FIGURES "\\figures"
254 %token HEADER "\\header"
255 %token INVALID "\\version-error"
256 %token LAYOUT "\\layout"
257 %token LYRICMODE "\\lyricmode"
258 %token LYRICS "\\lyrics"
259 %token LYRICSTO "\\lyricsto"
260 %token MARKUP "\\markup"
261 %token MARKUPLIST "\\markuplist"
264 %token NOTEMODE "\\notemode"
265 %token OVERRIDE "\\override"
266 %token PAPER "\\paper"
267 %token REMOVE "\\remove"
268 %token REPEAT "\\repeat"
270 %token REVERT "\\revert"
271 %token SCORE "\\score"
272 %token 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 ("toplevel-score-handler");
411 scm_call_2 (proc, parser->self_scm (), $1);
414 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
415 scm_call_2 (proc, parser->self_scm (), $1);
418 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
419 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
422 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
423 scm_call_2 (proc, parser->self_scm (), $1);
426 // Evaluate and ignore #xxx, as opposed to \xxx
427 parser->lexer_->eval_scm_token ($1);
429 | embedded_scm_active
431 SCM out = SCM_UNDEFINED;
432 if (Text_interface::is_markup ($1))
433 out = scm_list_1 ($1);
434 else if (Text_interface::is_markup_list ($1))
436 if (scm_is_pair (out))
438 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
439 scm_call_2 (proc, parser->self_scm (), out);
440 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
441 parser->parser_error (@1, _("bad expression type"));
445 Output_def * od = unsmob_output_def ($1);
447 if (od->c_variable ("is-paper") == SCM_BOOL_T)
448 id = ly_symbol2scm ("$defaultpaper");
449 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
450 id = ly_symbol2scm ("$defaultmidi");
451 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
452 id = ly_symbol2scm ("$defaultlayout");
454 parser->lexer_->set_identifier (id, $1);
461 $$ = parser->lexer_->eval_scm_token ($1);
471 embedded_scm_bare_arg:
475 $$ = parser->lexer_->eval_scm_token ($1);
479 | context_modification
481 | context_def_spec_block
487 /* The generic version may end in music, or not */
494 /* embedded_scm_arg is _not_ casting pitches to music by default, this
495 * has to be done by the function itself. Note that this may cause
496 * the results of scm_function_call or embedded_scm_bare_arg to be
497 * turned into music from pitches as well. Note that this creates a
498 * distinctly awkward situation for calculated drum pitches. Those
499 * are at the current point of time rejected as music constituents as
500 * they can't be distinguished from "proper" symbols.
504 embedded_scm_bare_arg
510 SCM_FUNCTION function_arglist {
511 $$ = MAKE_SYNTAX ("music-function", @$,
519 // FIXME: @$ does not contain a useful source location
520 // for empty rules, and the only token in the whole
521 // production, EMBEDDED_LILY, is synthetic and also
522 // contains no source location.
523 $$ = MAKE_SYNTAX ("void-music", @$);
526 | music_embedded music_embedded music_list {
527 $3 = scm_reverse_x ($3, SCM_EOL);
528 if (unsmob_music ($2))
529 $3 = scm_cons ($2, $3);
530 if (unsmob_music ($1))
531 $3 = scm_cons ($1, $3);
532 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
535 parser->error_level_ = 1;
536 $$ = SCM_UNSPECIFIED;
538 | INVALID embedded_lilypond {
539 parser->error_level_ = 1;
545 lilypond_header_body:
546 /* empty */ { $$ = SCM_UNSPECIFIED; }
547 | lilypond_header_body assignment {
550 | lilypond_header_body embedded_scm {
556 HEADER '{' lilypond_header_body '}' {
557 $$ = parser->lexer_->remove_scope ();
569 assignment_id '=' identifier_init {
570 parser->lexer_->set_identifier ($1, $3);
571 $$ = SCM_UNSPECIFIED;
573 | assignment_id property_path '=' identifier_init {
574 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
575 parser->lexer_->set_identifier (path, $4);
576 $$ = SCM_UNSPECIFIED;
578 | assignment_id '.' property_path '=' identifier_init {
579 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
580 parser->lexer_->set_identifier (path, $5);
581 $$ = SCM_UNSPECIFIED;
591 | context_def_spec_block
593 | post_event_nofinger post_events
595 $$ = scm_reverse_x ($2, SCM_EOL);
596 if (Music *m = unsmob_music ($1))
598 if (m->is_mus_type ("post-event-wrapper"))
600 (scm_list_2 (m->get_property ("elements"),
603 $$ = scm_cons ($1, $$);
606 && scm_is_null (scm_cdr ($$)))
610 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
611 m->set_property ("elements", $$);
612 $$ = m->unprotect ();
620 | context_modification
623 context_def_spec_block:
624 CONTEXT '{' context_def_spec_body '}'
627 unsmob_context_def ($$)->origin ()->set_spot (@$);
635 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
636 parser->lexer_->push_note_state (nn);
640 parser->lexer_->pop_state ();
645 context_mod_embedded:
648 if (unsmob_music ($1)) {
649 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
650 $1 = scm_call_2 (proc, parser->self_scm (), $1);
652 if (unsmob_context_mod ($1))
655 parser->parser_error (@1, _ ("not a context mod"));
656 $$ = Context_mod ().smobbed_copy ();
662 context_def_spec_body:
664 $$ = Context_def::make_scm ();
666 | CONTEXT_DEF_IDENTIFIER {
669 | context_def_spec_body context_mod {
670 if (!SCM_UNBNDP ($2))
671 unsmob_context_def ($$)->add_context_mod ($2);
673 | context_def_spec_body context_modification {
674 Context_def *td = unsmob_context_def ($$);
675 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
676 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
677 td->add_context_mod (scm_car (m));
680 | context_def_spec_body context_mod_embedded {
681 Context_def *td = unsmob_context_def ($$);
682 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
683 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
684 td->add_context_mod (scm_car (m));
692 BOOK '{' book_body '}' {
694 unsmob_book ($$)->origin ()->set_spot (@$);
696 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
701 * Use 'handlers' like for toplevel-* stuff?
702 * grok \layout and \midi? */
705 Book *book = new Book;
706 init_papers (parser);
707 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
708 book->paper_->unprotect ();
709 push_paper (parser, book->paper_);
710 book->header_ = get_header (parser);
711 $$ = book->unprotect ();
712 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
715 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
717 | book_body paper_block {
718 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
719 set_paper (parser, unsmob_output_def ($2));
721 | book_body bookpart_block {
722 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
723 scm_call_2 (proc, $1, $2);
725 | book_body score_block {
726 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
727 scm_call_2 (proc, $1, $2);
729 | book_body composite_music {
730 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
731 scm_call_3 (proc, parser->self_scm (), $1, $2);
733 | book_body full_markup {
734 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
735 scm_call_2 (proc, $1, scm_list_1 ($2));
737 | book_body full_markup_list {
738 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
739 scm_call_2 (proc, $1, $2);
741 | book_body SCM_TOKEN {
742 // Evaluate and ignore #xxx, as opposed to \xxx
743 parser->lexer_->eval_scm_token ($2);
745 | book_body embedded_scm_active
747 SCM out = SCM_UNDEFINED;
748 if (Text_interface::is_markup ($2))
749 out = scm_list_1 ($2);
750 else if (Text_interface::is_markup_list ($2))
752 if (scm_is_pair (out))
754 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
755 scm_call_2 (proc, $1, out);
756 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
757 parser->parser_error (@2, _("bad expression type"));
761 parser->lexer_->add_scope (unsmob_book ($1)->header_);
764 Book *book = unsmob_book ($1);
766 book->scores_ = SCM_EOL;
767 book->bookparts_ = SCM_EOL;
772 BOOKPART '{' bookpart_body '}' {
774 unsmob_book ($$)->origin ()->set_spot (@$);
775 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
781 Book *book = new Book;
782 $$ = book->unprotect ();
783 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
786 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
788 | bookpart_body paper_block {
789 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
791 | bookpart_body score_block {
792 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
793 scm_call_2 (proc, $1, $2);
795 | bookpart_body composite_music {
796 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
797 scm_call_3 (proc, parser->self_scm (), $1, $2);
799 | bookpart_body full_markup {
800 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
801 scm_call_2 (proc, $1, scm_list_1 ($2));
803 | bookpart_body full_markup_list {
804 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
805 scm_call_2 (proc, $1, $2);
807 | bookpart_body SCM_TOKEN {
808 // Evaluate and ignore #xxx, as opposed to \xxx
809 parser->lexer_->eval_scm_token ($2);
811 | bookpart_body embedded_scm_active
813 SCM out = SCM_UNDEFINED;
814 if (Text_interface::is_markup ($2))
815 out = scm_list_1 ($2);
816 else if (Text_interface::is_markup_list ($2))
818 if (scm_is_pair (out))
820 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
821 scm_call_2 (proc, $1, out);
822 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
823 parser->parser_error (@2, _("bad expression type"));
827 Book *book = unsmob_book ($1);
828 if (!ly_is_module (book->header_))
829 book->header_ = ly_make_module (false);
830 parser->lexer_->add_scope (book->header_);
832 | bookpart_body error {
833 Book *book = unsmob_book ($1);
835 book->scores_ = SCM_EOL;
840 SCORE '{' score_body '}' {
841 unsmob_score ($3)->origin ()->set_spot (@$);
853 if (!scm_is_pair ($1)
854 || !ly_is_module (scm_car ($1)))
855 $1 = scm_cons (ly_make_module (false), $1);
856 parser->lexer_->add_scope (scm_car ($1));
861 | score_headers output_def
863 Output_def *od = unsmob_output_def ($2);
864 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
866 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
871 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
872 scm_set_cdr_x ($1, scm_cons ($2, scm_cdr ($1)));
874 $$ = scm_cons ($2, $1);
882 score_headers music {
883 SCM scorify = ly_lily_module_constant ("scorify-music");
884 $$ = scm_call_2 (scorify, $2, parser->self_scm ());
886 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
888 unsmob_score ($$)->set_header (scm_car ($1));
891 for (SCM p = scm_reverse_x ($1, SCM_EOL);
892 scm_is_pair (p); p = scm_cdr (p))
895 add_output_def (unsmob_output_def (scm_car (p)));
898 | embedded_scm_active {
899 if (!unsmob_score ($1))
901 $$ = (new Score)->unprotect ();
902 parser->parser_error (@1, _("score expected"));
907 Score *score = unsmob_score ($1);
908 if (!ly_is_module (score->get_header ()))
909 score->set_header (ly_make_module (false));
910 parser->lexer_->add_scope (score->get_header ());
912 | score_body output_def {
913 Output_def *od = unsmob_output_def ($2);
914 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
916 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
921 unsmob_score ($1)->add_output_def (od);
925 unsmob_score ($$)->error_found_ = true;
936 Output_def *od = unsmob_output_def ($1);
938 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
940 parser->parser_error (@1, _ ("need \\paper for paper block"));
941 $$ = get_paper (parser)->unprotect ();
948 output_def_body '}' {
951 parser->lexer_->remove_scope ();
952 parser->lexer_->pop_state ();
958 Output_def *p = get_paper (parser);
959 p->input_origin_ = @$;
960 parser->lexer_->add_scope (p->scope_);
961 $$ = p->unprotect ();
964 Output_def *p = get_midi (parser);
965 $$ = p->unprotect ();
966 parser->lexer_->add_scope (p->scope_);
969 Output_def *p = get_layout (parser);
971 parser->lexer_->add_scope (p->scope_);
972 $$ = p->unprotect ();
976 output_def_head_with_mode_switch:
978 parser->lexer_->push_initial_state ();
983 // We need this weird nonterminal because both music as well as a
984 // context definition can start with \context and the difference is
985 // only apparent after looking at the next token. If it is '{', there
986 // is still time to escape from notes mode.
988 music_or_context_def:
990 | context_def_spec_block
994 output_def_head_with_mode_switch '{' {
996 unsmob_output_def ($$)->input_origin_.set_spot (@$);
998 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
999 Output_def *o = unsmob_output_def ($3);
1000 o->input_origin_.set_spot (@$);
1001 $$ = o->self_scm ();
1002 parser->lexer_->remove_scope ();
1003 parser->lexer_->add_scope (o->scope_);
1005 | output_def_body assignment {
1008 | output_def_body embedded_scm {
1013 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1014 parser->lexer_->push_note_state (nn);
1015 } music_or_context_def
1017 parser->lexer_->pop_state ();
1018 if (unsmob_context_def ($3))
1019 assign_context_def (unsmob_output_def ($1), $3);
1022 SCM proc = parser->lexer_->lookup_identifier
1023 ("output-def-music-handler");
1024 scm_call_3 (proc, parser->self_scm (),
1028 | output_def_body error {
1034 TEMPO steno_duration '=' tempo_range {
1035 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1037 | TEMPO scalar steno_duration '=' tempo_range {
1038 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1041 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1046 The representation of a list is reversed to have efficient append. */
1052 | music_list music_embedded {
1053 if (unsmob_music ($2))
1054 $$ = scm_cons ($2, $1);
1056 | music_list error {
1057 Music *m = MY_MAKE_MUSIC("Music", @$);
1059 m->set_property ("error-found", SCM_BOOL_T);
1060 $$ = scm_cons (m->self_scm (), $1);
1061 m->unprotect (); /* UGH */
1068 $$ = scm_reverse_x ($2, SCM_EOL);
1073 | lyric_element_music
1079 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1080 parser->parser_error (@1, _ ("unexpected post-event"));
1081 $$ = SCM_UNSPECIFIED;
1084 | music_embedded_backup
1088 | music_embedded_backup BACKUP lyric_element_music
1094 music_embedded_backup:
1097 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1099 else if (Music *m = unsmob_music ($1)) {
1100 if (m->is_mus_type ("post-event")) {
1101 parser->parser_error
1102 (@1, _ ("unexpected post-event"));
1103 $$ = SCM_UNSPECIFIED;
1106 } else if (parser->lexer_->is_lyric_state ()
1107 && Text_interface::is_markup ($1))
1108 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1110 @$.warning (_ ("Ignoring non-music expression"));
1119 $$ = make_music_from_simple (parser, @1, $1);
1120 if (!unsmob_music ($$))
1122 parser->parser_error (@1, _ ("music expected"));
1123 $$ = MAKE_SYNTAX ("void-music", @$);
1126 | composite_music %prec COMPOSITE
1131 | composite_music %prec COMPOSITE
1135 REPEAT simple_string unsigned_number music
1137 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1139 | REPEAT_IDENTIFIER music
1141 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1144 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1146 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1148 | REPEAT_IDENTIFIER music ALTERNATIVE braced_music_list
1150 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1156 SEQUENTIAL braced_music_list {
1157 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1159 | braced_music_list {
1160 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1165 SIMULTANEOUS braced_music_list {
1166 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1168 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1169 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1175 | music_property_def
1179 context_modification:
1182 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1183 parser->lexer_->push_note_state (nn);
1184 } '{' context_mod_list '}'
1186 parser->lexer_->pop_state ();
1189 | WITH CONTEXT_MOD_IDENTIFIER
1193 | CONTEXT_MOD_IDENTIFIER
1197 | WITH context_modification_arg
1199 if (unsmob_music ($2)) {
1200 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1201 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1203 if (unsmob_context_mod ($2))
1206 parser->parser_error (@2, _ ("not a context mod"));
1207 $$ = Context_mod ().smobbed_copy ();
1212 context_modification_arg:
1217 optional_context_mod:
1221 | context_modification
1229 $$ = Context_mod ().smobbed_copy ();
1231 | context_mod_list context_mod {
1232 if (!SCM_UNBNDP ($2))
1233 unsmob_context_mod ($1)->add_context_mod ($2);
1235 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1236 Context_mod *md = unsmob_context_mod ($2);
1238 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1240 | context_mod_list context_mod_embedded {
1241 unsmob_context_mod ($1)->add_context_mods
1242 (unsmob_context_mod ($2)->get_mods ());
1251 /* Music that can be parsed without lookahead */
1254 | complex_music_prefix closed_music
1256 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1258 | music_function_call_closed
1264 | grouped_music_list
1268 simultaneous_music { $$ = $1; }
1269 | sequential_music { $$ = $1; }
1272 /* Function argument lists are arguably the most complex part in the
1273 * parser. They are pretty tricky to understand because of the way
1274 * they are processed, and because of optional arguments that can be
1275 * omitted. When there are several optional arguments in a row,
1276 * omitting one automatically omits all following arguments. Optional
1277 * arguments can only be omitted when either
1279 * a) the omission is explicitly started with \default
1280 * b) the omission is implicitly started by an argument not matching
1281 * its predicate, and there is a mandatory argument later that can
1282 * "catch" the argument that does not fit.
1284 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1285 * (corresponding to mandatory arguments and having a predicate
1286 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1287 * the semantic value of the EXPECT_OPTIONAL token is the default to
1288 * use when the optional argument is omitted, and EXPECT_SCM again has
1289 * the argument predicate as semantic value) in reverse order to the
1290 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1291 * processed inside-out while actual tokens are consumed.
1293 * This means that the argument list tokens determine the actions
1294 * taken as they arrive. The structure of the argument list is known
1295 * to the parser and stored in its parse stack when the first argument
1296 * is being parsed. What the parser does not know is which predicates
1297 * will match and whether or not \default will be appearing in the
1298 * argument list, and where.
1300 * Many of the basic nonterminals used for argument list scanning come
1301 * in a "normal" and a "closed" flavor. A closed expression is one
1302 * that can be parsed without a lookahead token. That makes it
1303 * feasible for an optional argument that may need to be skipped:
1304 * skipping can only be accomplished by pushing back the token into
1305 * the lexer, and that only works when there is no lookahead token.
1307 * Sequences of 0 or more optional arguments are scanned using either
1308 * function_arglist_backup or function_arglist_nonbackup. The first
1309 * is used when optional arguments are followed by at least one
1310 * mandatory argument: in that case optional arguments may be skipped
1311 * by either a false predicate (in which case the expression will be
1312 * pushed back as one or more tokens, preceded by a BACKUP token) or
1313 * by using \default.
1315 * If optional arguments are at the end of the argument list, they are
1316 * instead scanned using function_arglist_nonbackup: here the only
1317 * manner to enter into skipping of optional arguments is the use of
1320 * The argument list of a normal function call is parsed using
1321 * function_arglist. The part of an argument list before a mandatory
1322 * argument is parsed using function_arglist_optional.
1324 * The difference is that leading optional arguments are scanned using
1325 * function_arglist_nonbackup and function_arglist_backup,
1328 * Most other details are obvious in the rules themselves.
1332 function_arglist_nonbackup_common:
1333 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1335 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1337 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1339 SCM n = scm_difference ($5, SCM_UNDEFINED);
1340 if (scm_is_true (scm_call_1 ($2, n)))
1341 $$ = scm_cons (n, $3);
1343 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1344 t->set_property ("digit", $5);
1345 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1350 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1352 $$ = check_scheme_arg (parser, @4,
1353 scm_difference ($5, SCM_UNDEFINED),
1356 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1358 $$ = check_scheme_arg (parser, @4,
1359 scm_difference ($5, SCM_UNDEFINED),
1364 function_arglist_closed_nonbackup:
1365 function_arglist_nonbackup_common
1366 | function_arglist_closed_common
1367 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg_closed
1369 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1371 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_closed
1373 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1375 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1377 $$ = check_scheme_arg (parser, @4,
1378 try_string_variants ($2, $4),
1381 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1383 $$ = check_scheme_arg (parser, @4,
1384 try_string_variants ($2, $4),
1387 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1389 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1395 | SYMBOL_LIST '.' symbol_list_rev
1397 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1403 | symbol_list_rev '.' symbol_list_part
1405 $$ = scm_append_x (scm_list_2 ($3, $1));
1409 // symbol_list_part delivers elements in reverse copy.
1414 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1415 $$ = try_string_variants (sym_l_p, $1);
1416 if (SCM_UNBNDP ($$)) {
1417 parser->parser_error (@1, _("not a symbol"));
1420 $$ = scm_reverse ($$);
1425 symbol_list_element:
1431 function_arglist_nonbackup:
1432 function_arglist_nonbackup_common
1433 | function_arglist_common
1434 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1436 if (scm_is_true (scm_call_1 ($2, $4)))
1437 $$ = scm_cons ($4, $3);
1439 $$ = check_scheme_arg (parser, @4,
1440 make_music_from_simple
1444 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1446 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1448 | function_arglist_nonbackup_reparse REPARSE duration_length
1450 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1452 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1454 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1456 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1458 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1460 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1462 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1464 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1466 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1470 function_arglist_nonbackup_reparse:
1471 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1474 SCM res = try_string_variants ($2, $4);
1475 if (!SCM_UNBNDP (res))
1476 if (scm_is_pair (res))
1477 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1479 MYREPARSE (@4, $2, SCM_ARG, res);
1480 else if (scm_is_true
1482 ($2, make_music_from_simple
1484 MYREPARSE (@4, $2, STRING, $4);
1486 MYREPARSE (@4, $2, SCM_ARG, $4);
1488 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1491 SCM res = try_string_variants ($2, $4);
1492 if (!SCM_UNBNDP (res))
1493 if (scm_is_pair (res))
1494 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1496 MYREPARSE (@4, $2, SCM_ARG, res);
1497 else if (scm_is_true
1499 ($2, make_music_from_simple
1501 MYREPARSE (@4, $2, STRING, $4);
1503 MYREPARSE (@4, $2, SCM_ARG, $4);
1505 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1508 if (scm_is_true (scm_call_1 ($2, $4)))
1509 MYREPARSE (@4, $2, SCM_ARG, $4);
1510 else if (scm_is_true
1512 ($2, make_music_from_simple
1514 MYREPARSE (@4, $2, STRING, $4);
1516 MYREPARSE (@4, $2, SCM_ARG, $4);
1518 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1521 if (scm_is_true (scm_call_1 ($2, $4)))
1522 MYREPARSE (@4, $2, REAL, $4);
1524 SCM d = make_duration ($4);
1525 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1526 MYREPARSE (@4, $2, REAL, $4); // trigger error
1528 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1531 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1533 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1538 // function_arglist_backup can't occur at the end of an argument
1539 // list. It needs to be careful about avoiding lookahead only until
1540 // it has made a decision whether or not to accept the parsed entity.
1541 // At that point of time, music requiring lookahead to parse becomes
1543 function_arglist_backup:
1544 function_arglist_common
1545 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg_closed
1547 if (scm_is_true (scm_call_1 ($2, $4)))
1549 $$ = scm_cons ($4, $3);
1551 $$ = scm_cons (loc_on_music (@3, $1), $3);
1552 MYBACKUP (SCM_ARG, $4, @4);
1555 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REPEAT simple_string unsigned_number
1557 $4 = MAKE_SYNTAX ("repeat", @4, $5, $6,
1558 MY_MAKE_MUSIC ("Music", @4)->unprotect (),
1560 if (scm_is_true (scm_call_1 ($2, $4)))
1563 MYREPARSE (@4, $2, REPEAT_IDENTIFIER, scm_cons ($5, $6));
1565 $$ = scm_cons (loc_on_music (@3, $1), $3);
1566 MYBACKUP (REPEAT_IDENTIFIER, scm_cons ($5, $6), @4);
1569 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup chord_body
1571 if (scm_is_true (scm_call_1 ($2, $4)))
1574 MYREPARSE (@4, $2, CHORD_BODY_IDENTIFIER, $4);
1576 $$ = scm_cons (loc_on_music (@3, $1), $3);
1577 MYBACKUP (CHORD_BODY_IDENTIFIER, $4, @4);
1580 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1582 if (scm_is_true (scm_call_1 ($2, $4)))
1584 $$ = scm_cons ($4, $3);
1586 $$ = scm_cons (loc_on_music (@3, $1), $3);
1587 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1590 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1592 if (scm_is_true (scm_call_1 ($2, $4)))
1593 $$ = scm_cons ($4, $3);
1595 $$ = scm_cons (loc_on_music (@3, $1), $3);
1596 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1599 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1601 if (scm_is_true (scm_call_1 ($2, $4)))
1603 MYREPARSE (@4, $2, REAL, $4);
1606 SCM d = make_duration ($4);
1607 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1609 $$ = scm_cons (loc_on_music (@3, $1), $3);
1610 MYBACKUP (UNSIGNED, $4, @4);
1612 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1617 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1619 if (scm_is_true (scm_call_1 ($2, $4)))
1622 MYREPARSE (@4, $2, REAL, $4);
1624 $$ = scm_cons (loc_on_music (@3, $1), $3);
1625 MYBACKUP (REAL, $4, @4);
1628 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1630 if (scm_is_true (scm_call_1 ($2, $4)))
1632 $$ = scm_cons ($4, $3);
1634 $$ = scm_cons (loc_on_music (@3, $1), $3);
1635 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1638 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1640 SCM n = scm_difference ($5, SCM_UNDEFINED);
1641 if (scm_is_true (scm_call_1 ($2, n))) {
1643 MYREPARSE (@5, $2, REAL, n);
1645 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1646 t->set_property ("digit", $5);
1647 $$ = t->unprotect ();
1648 if (scm_is_true (scm_call_1 ($2, $$)))
1649 $$ = scm_cons ($$, $3);
1651 $$ = scm_cons (loc_on_music (@3, $1), $3);
1652 MYBACKUP (UNSIGNED, $5, @5);
1653 parser->lexer_->push_extra_token ('-');
1658 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1660 SCM n = scm_difference ($5, SCM_UNDEFINED);
1661 if (scm_is_true (scm_call_1 ($2, n))) {
1662 MYREPARSE (@5, $2, REAL, n);
1665 $$ = scm_cons (loc_on_music (@3, $1), $3);
1666 MYBACKUP (REAL, n, @5);
1669 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1671 SCM n = scm_difference ($5, SCM_UNDEFINED);
1672 if (scm_is_true (scm_call_1 ($2, n))) {
1673 $$ = scm_cons (n, $3);
1675 $$ = scm_cons (loc_on_music (@3, $1), $3);
1676 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1679 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup PITCH_IDENTIFIER
1681 SCM m = make_music_from_simple (parser, @4, $4);
1682 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1684 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1686 } else if (scm_is_true (scm_call_1 ($2, $4)))
1688 MYREPARSE (@4, $2, PITCH_ARG, $4);
1691 $$ = scm_cons (loc_on_music (@3, $1), $3);
1692 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1695 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NOTENAME_PITCH
1697 SCM m = make_music_from_simple (parser, @4, $4);
1698 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1700 MYREPARSE (@4, $2, NOTENAME_PITCH, $4);
1702 } else if (scm_is_true (scm_call_1 ($2, $4)))
1704 MYREPARSE (@4, $2, PITCH_ARG, $4);
1707 $$ = scm_cons (loc_on_music (@3, $1), $3);
1708 MYBACKUP (NOTENAME_PITCH, $4, @4);
1711 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup TONICNAME_PITCH
1713 SCM m = make_music_from_simple (parser, @4, $4);
1714 if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m)))
1716 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1718 } else if (scm_is_true (scm_call_1 ($2, $4)))
1720 MYREPARSE (@4, $2, PITCH_ARG, $4);
1723 $$ = scm_cons (loc_on_music (@3, $1), $3);
1724 MYBACKUP (TONICNAME_PITCH, $4, @4);
1727 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1729 if (scm_is_true (scm_call_1 ($2, $4)))
1731 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1734 $$ = scm_cons (loc_on_music (@3, $1), $3);
1735 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1738 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1740 SCM res = try_string_variants ($2, $4);
1741 if (!SCM_UNBNDP (res))
1742 if (scm_is_pair (res)) {
1744 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1747 $$ = scm_cons (res, $3);
1749 $$ = scm_cons (loc_on_music (@3, $1), $3);
1750 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1753 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1755 SCM res = try_string_variants ($2, $4);
1756 if (!SCM_UNBNDP (res))
1757 if (scm_is_pair (res)) {
1759 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1762 $$ = scm_cons (res, $3);
1764 $$ = scm_cons (loc_on_music (@3, $1), $3);
1765 MYBACKUP (STRING, $4, @4);
1768 | function_arglist_backup REPARSE music_assign
1770 if (scm_is_true (scm_call_1 ($2, $3)))
1771 $$ = scm_cons ($3, $1);
1773 $$ = check_scheme_arg (parser, @3,
1774 make_music_from_simple
1778 | function_arglist_backup REPARSE pitch_arg
1780 $$ = check_scheme_arg (parser, @3,
1783 | function_arglist_backup REPARSE bare_number_common
1785 $$ = check_scheme_arg (parser, @3,
1788 | function_arglist_backup REPARSE duration_length
1790 $$ = check_scheme_arg (parser, @3,
1793 | function_arglist_backup REPARSE symbol_list_arg
1795 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1800 function_arglist_nonbackup
1801 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1803 $$ = scm_cons (loc_on_music (@4, $1), $3);
1807 function_arglist_skip_nonbackup:
1808 function_arglist_nonbackup
1809 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1811 $$ = scm_cons (loc_on_music (@3, $1), $3);
1815 function_arglist_common:
1816 EXPECT_NO_MORE_ARGS {
1819 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1821 if (scm_is_true (scm_call_1 ($1, $3)))
1822 $$ = scm_cons ($3, $2);
1824 $$ = check_scheme_arg (parser, @3,
1825 make_music_from_simple
1829 | EXPECT_SCM function_arglist_optional bare_number_common
1831 $$ = check_scheme_arg (parser, @3,
1834 | EXPECT_SCM function_arglist_optional post_event_nofinger
1836 $$ = check_scheme_arg (parser, @3,
1839 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1841 SCM n = scm_difference ($4, SCM_UNDEFINED);
1842 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1844 | function_arglist_common_reparse REPARSE SCM_ARG
1846 $$ = check_scheme_arg (parser, @3,
1849 | function_arglist_common_reparse REPARSE lyric_element_music
1851 $$ = check_scheme_arg (parser, @3,
1854 | function_arglist_common_reparse REPARSE bare_number_common
1856 $$ = check_scheme_arg (parser, @3,
1859 | function_arglist_common_reparse REPARSE duration_length
1861 $$ = check_scheme_arg (parser, @3,
1864 | function_arglist_common_reparse REPARSE symbol_list_arg
1866 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1870 function_arglist_common_reparse:
1871 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1874 SCM res = try_string_variants ($1, $3);
1875 if (!SCM_UNBNDP (res))
1876 if (scm_is_pair (res))
1877 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1879 MYREPARSE (@3, $1, SCM_ARG, res);
1880 else if (scm_is_true
1882 ($1, make_music_from_simple (parser, @3, $3))))
1883 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1885 // This is going to flag a syntax error, we
1886 // know the predicate to be false.
1887 MYREPARSE (@3, $1, SCM_ARG, $3);
1889 | EXPECT_SCM function_arglist_optional STRING
1892 SCM res = try_string_variants ($1, $3);
1893 if (!SCM_UNBNDP (res))
1894 if (scm_is_pair (res))
1895 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1897 MYREPARSE (@3, $1, SCM_ARG, res);
1898 else if (scm_is_true
1900 ($1, make_music_from_simple (parser, @3, $3))))
1901 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1903 // This is going to flag a syntax error, we
1904 // know the predicate to be false.
1905 MYREPARSE (@3, $1, SCM_ARG, $3);
1907 | EXPECT_SCM function_arglist_optional full_markup
1910 if (scm_is_true (scm_call_1 ($1, $3)))
1911 MYREPARSE (@3, $1, SCM_ARG, $3);
1912 else if (scm_is_true
1914 ($1, make_music_from_simple (parser, @3, $3))))
1915 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1917 // This is going to flag a syntax error, we
1918 // know the predicate to be false.
1919 MYREPARSE (@3, $1, SCM_ARG, $3);
1921 | EXPECT_SCM function_arglist_optional UNSIGNED
1924 if (scm_is_true (scm_call_1 ($1, $3)))
1925 MYREPARSE (@3, $1, REAL, $3);
1927 SCM d = make_duration ($3);
1928 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
1929 MYREPARSE (@3, $1, REAL, $3);
1931 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
1934 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
1937 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
1939 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
1942 SCM n = scm_difference ($4, SCM_UNDEFINED);
1943 if (scm_is_true (scm_call_1 ($1, n)))
1944 MYREPARSE (@4, $1, REAL, n);
1946 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1947 t->set_property ("digit", $4);
1948 SCM m = t->unprotect ();
1949 if (scm_is_true (scm_call_1 ($1, m)))
1950 MYREPARSE (@4, $1, SCM_ARG, m);
1952 MYREPARSE (@4, $1, SCM_ARG, $4);
1956 | EXPECT_SCM function_arglist_optional '-' REAL
1959 SCM n = scm_difference ($4, SCM_UNDEFINED);
1960 MYREPARSE (@4, $1, REAL, n);
1964 function_arglist_closed:
1965 function_arglist_closed_nonbackup
1966 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1968 $$ = scm_cons (loc_on_music (@4, $1), $3);
1972 function_arglist_closed_common:
1973 EXPECT_NO_MORE_ARGS {
1976 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1978 $$ = check_scheme_arg (parser, @3,
1981 | EXPECT_SCM function_arglist_optional bare_number_common_closed
1983 $$ = check_scheme_arg (parser, @3,
1986 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1988 $$ = check_scheme_arg (parser, @3,
1989 scm_difference ($4, SCM_UNDEFINED),
1992 | EXPECT_SCM function_arglist_optional post_event_nofinger
1994 $$ = check_scheme_arg (parser, @3,
1997 | function_arglist_common_reparse REPARSE SCM_ARG
1999 $$ = check_scheme_arg (parser, @3,
2002 | function_arglist_common_reparse REPARSE bare_number_common_closed
2004 $$ = check_scheme_arg (parser, @3,
2007 | function_arglist_common_reparse REPARSE symbol_list_arg
2009 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2013 function_arglist_optional:
2014 function_arglist_backup
2015 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2017 $$ = scm_cons (loc_on_music (@4, $1), $3);
2019 | function_arglist_skip_backup BACKUP
2022 function_arglist_skip_backup:
2023 function_arglist_backup
2024 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2026 $$ = scm_cons (loc_on_music (@3, $1), $3);
2030 embedded_scm_closed:
2032 | scm_function_call_closed
2035 embedded_scm_arg_closed:
2036 embedded_scm_bare_arg
2037 | scm_function_call_closed
2041 scm_function_call_closed:
2042 SCM_FUNCTION function_arglist_closed {
2043 $$ = MAKE_SYNTAX ("music-function", @$,
2048 music_function_call:
2049 MUSIC_FUNCTION function_arglist {
2050 $$ = MAKE_SYNTAX ("music-function", @$,
2057 /**/ { $$ = SCM_EOL; }
2058 | '=' simple_string {
2065 | repeated_music { $$ = $1; }
2066 | re_rhythmed_music { $$ = $1; }
2067 | complex_music_prefix music
2069 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2073 complex_music_prefix:
2074 CONTEXT symbol optional_id optional_context_mod {
2075 Context_mod *ctxmod = unsmob_context_mod ($4);
2078 mods = ctxmod->get_mods ();
2079 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2081 | NEWCONTEXT symbol optional_id optional_context_mod {
2082 Context_mod *ctxmod = unsmob_context_mod ($4);
2085 mods = ctxmod->get_mods ();
2086 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2091 mode_changing_head grouped_music_list {
2092 if ($1 == ly_symbol2scm ("chords"))
2094 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2100 parser->lexer_->pop_state ();
2102 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2103 Context_mod *ctxmod = unsmob_context_mod ($2);
2106 mods = ctxmod->get_mods ();
2107 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2108 if ($1 == ly_symbol2scm ("ChordNames"))
2110 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2112 parser->lexer_->pop_state ();
2118 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2119 parser->lexer_->push_note_state (nn);
2121 $$ = ly_symbol2scm ("notes");
2125 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2126 parser->lexer_->push_note_state (nn);
2128 $$ = ly_symbol2scm ("drums");
2131 parser->lexer_->push_figuredbass_state ();
2133 $$ = ly_symbol2scm ("figures");
2136 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2137 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2138 nn = parser->lexer_->lookup_identifier ("pitchnames");
2139 parser->lexer_->push_chord_state (nn);
2140 $$ = ly_symbol2scm ("chords");
2144 { parser->lexer_->push_lyric_state ();
2145 $$ = ly_symbol2scm ("lyrics");
2149 mode_changing_head_with_context:
2151 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2152 parser->lexer_->push_note_state (nn);
2154 $$ = ly_symbol2scm ("DrumStaff");
2157 parser->lexer_->push_figuredbass_state ();
2159 $$ = ly_symbol2scm ("FiguredBass");
2162 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2163 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2164 nn = parser->lexer_->lookup_identifier ("pitchnames");
2165 parser->lexer_->push_chord_state (nn);
2166 $$ = ly_symbol2scm ("ChordNames");
2169 { parser->lexer_->push_lyric_state ();
2170 $$ = ly_symbol2scm ("Lyrics");
2175 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2178 /* Can also use music at the expensive of two S/Rs similar to
2179 \repeat \alternative */
2180 parser->lexer_->pop_state ();
2182 $$ = scm_cons ($3, SCM_EOL);
2184 | new_lyrics ADDLYRICS {
2185 parser->lexer_->push_lyric_state ();
2187 parser->lexer_->pop_state ();
2188 $$ = scm_cons ($4, $1);
2193 composite_music new_lyrics {
2194 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2196 | LYRICSTO simple_string {
2197 parser->lexer_->push_lyric_state ();
2199 parser->lexer_->pop_state ();
2200 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2205 CHANGE symbol '=' simple_string {
2206 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2213 $$ = scm_reverse_x ($1, SCM_EOL);
2215 | symbol_list_rev property_path {
2216 $$ = scm_reverse_x ($1, $2);
2222 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2225 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2227 | OVERRIDE property_path '=' scalar {
2228 if (scm_ilength ($2) < 2) {
2229 parser->parser_error (@2, _("bad grob property path"));
2232 $$ = scm_cons (ly_symbol2scm ("push"),
2233 scm_cons2 (scm_car ($2),
2238 | REVERT revert_arg {
2239 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2243 // This is all quite awkward for the sake of substantial backward
2244 // compatibility while at the same time allowing a more "natural" form
2245 // of specification not separating grob specification from grob
2246 // property path. The purpose of this definition of revert_arg is to
2247 // allow the symbol list which specifies grob and property to revert
2248 // to be optionally be split into two parts after the grob (which in
2249 // this case is just the first element of the list). symbol_list_part
2250 // is only one path component, but it can be parsed without lookahead,
2251 // so we can follow it with a synthetic BACKUP token when needed. If
2252 // the first symbol_list_part already contains multiple elements (only
2253 // possible if a Scheme expression provides them), we just parse for
2254 // additional elements introduced by '.', which is what the
2255 // SYMBOL_LIST backup in connection with the immediately following
2256 // rule using symbol_list_arg does.
2258 // As long as we don't have our coffers filled with both grob and at
2259 // least one grob property specification, the rest of the required
2260 // symbol list chain may be provided either with or without a leading
2261 // dot. This is for both allowing the traditional
2262 // \revert Accidental #'color
2263 // as well as well as the "naive" form
2264 // \revert Accidental.color
2267 revert_arg_backup BACKUP symbol_list_arg
2276 if (scm_is_null ($1)
2277 || scm_is_null (scm_cdr ($1)))
2278 MYBACKUP (SCM_ARG, $1, @1);
2280 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2284 // revert_arg_part delivers results in reverse
2287 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2289 $$ = scm_append_x (scm_list_2 ($5, $3));
2291 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2293 $$ = scm_append_x (scm_list_2 ($4, $3));
2298 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2299 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2301 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2302 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2303 | DENIES { $$ = ly_symbol2scm ("denies"); }
2305 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2306 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2307 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2308 | NAME { $$ = ly_symbol2scm ("context-name"); }
2312 property_operation { $$ = $1; }
2313 | context_def_mod STRING {
2314 $$ = scm_list_2 ($1, $2);
2316 | context_def_mod embedded_scm
2318 if (!scm_is_string ($2)
2319 && ly_symbol2scm ("consists") != $1
2320 && ly_symbol2scm ("remove") != $1)
2323 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2327 $$ = scm_list_2 ($1, $2);
2332 // If defined, at least two members.
2336 SCM l = scm_reverse_x ($1, SCM_EOL);
2339 (scm_object_property (scm_car (l),
2340 ly_symbol2scm ("is-grob?"))))
2341 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2342 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2343 parser->parser_error (@1, _ ("bad grob property path"));
2350 // If defined, at least three members
2354 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2356 parser->parser_error (@1, _ ("bad grob property path"));
2360 | grob_prop_spec property_path
2362 if (!SCM_UNBNDP ($1)) {
2363 $$ = scm_append_x (scm_list_2 ($1, $2));
2364 if (scm_is_null (scm_cddr ($$))) {
2365 parser->parser_error (@$, _ ("bad grob property path"));
2373 // Exactly two elements or undefined
2377 SCM l = scm_reverse_x ($1, SCM_EOL);
2378 switch (scm_ilength (l)) {
2380 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2384 parser->parser_error (@1, _ ("bad context property path"));
2391 simple_music_property_def:
2392 OVERRIDE grob_prop_path '=' scalar {
2393 if (SCM_UNBNDP ($2))
2396 $$ = scm_list_5 (scm_car ($2),
2397 ly_symbol2scm ("OverrideProperty"),
2403 | REVERT simple_revert_context revert_arg {
2404 $$ = scm_list_4 ($2,
2405 ly_symbol2scm ("RevertProperty"),
2409 | SET context_prop_spec '=' scalar {
2410 if (SCM_UNBNDP ($2))
2413 $$ = scm_list_4 (scm_car ($2),
2414 ly_symbol2scm ("PropertySet"),
2418 | UNSET context_prop_spec {
2419 if (SCM_UNBNDP ($2))
2422 $$ = scm_list_3 (scm_car ($2),
2423 ly_symbol2scm ("PropertyUnset"),
2429 // This is all quite awkward for the sake of substantial backward
2430 // compatibility while at the same time allowing a more "natural" form
2431 // of specification not separating grob specification from grob
2432 // property path. The purpose of this definition of
2433 // simple_revert_context is to allow the symbol list which specifies
2434 // grob and property to revert to be optionally be split into two
2435 // parts after the grob (which may be preceded by a context
2436 // specification, a case which we distinguish by checking whether the
2437 // first symbol is a valid grob symbol instead).
2439 // See revert_arg above for the main work horse of this arrangement.
2440 // simple_revert_context just caters for the context and delegates the
2441 // rest of the job to revert_arg.
2443 simple_revert_context:
2446 $1 = scm_reverse_x ($1, SCM_EOL);
2447 if (scm_is_null ($1)
2449 (scm_object_property (scm_car ($1),
2450 ly_symbol2scm ("is-grob?")))) {
2451 $$ = ly_symbol2scm ("Bottom");
2452 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2455 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2462 simple_music_property_def {
2463 if (SCM_UNBNDP ($1))
2464 $$ = MAKE_SYNTAX ("void-music", @1);
2466 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2477 simple_string: STRING {
2482 if (scm_is_string ($1)) {
2485 parser->parser_error (@1, (_ ("simple string expected")));
2486 $$ = scm_string (SCM_EOL);
2493 $$ = scm_string_to_symbol ($1);
2497 // This is a bit of overkill but makes the same
2498 // routine responsible for all symbol interpretations.
2499 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2501 if (SCM_UNBNDP ($$))
2503 parser->parser_error (@1, (_ ("symbol expected")));
2504 // Generate a unique symbol in case it is used
2505 // for an assignment or similar
2506 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2515 // The following is a rather defensive variant of admitting
2516 // negative numbers: the grammar would permit number_factor or
2517 // even number_expression. However, function arguments allow
2518 // only this simple kind of negative number, so to have things
2519 // like \tweak and \override behave reasonably similar, it
2520 // makes sense to rule out things like -- which are rather an
2521 // accent in function argument contexts.
2524 $$ = scm_difference ($2, SCM_UNDEFINED);
2531 simple_element post_events {
2532 // Let the rhythmic music iterator sort this mess out.
2533 if (scm_is_pair ($2)) {
2534 $$ = make_music_from_simple (parser, @1, $1);
2535 if (unsmob_music ($$))
2536 unsmob_music ($$)->set_property ("articulations",
2537 scm_reverse_x ($2, SCM_EOL));
2540 parser->parser_error (@1, _("music expected"));
2541 $$ = MAKE_SYNTAX ("void-music", @1);
2545 | simple_chord_elements post_events {
2546 if (scm_is_pair ($2)) {
2547 if (unsmob_pitch ($1))
2548 $1 = make_chord_elements (@1,
2550 parser->default_duration_.smobbed_copy (),
2553 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2555 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
2556 } else if (!unsmob_pitch ($1))
2557 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
2558 // A mere pitch drops through.
2560 | CHORD_REPETITION optional_notemode_duration post_events {
2562 i.set_location (@1, @3);
2563 $$ = MAKE_SYNTAX ("repetition-chord", i,
2564 $2, scm_reverse_x ($3, SCM_EOL));
2566 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2568 i.set_location (@1, @3);
2569 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2570 scm_reverse_x ($3, SCM_EOL));
2573 | note_chord_element
2578 chord_body optional_notemode_duration post_events
2580 Music *m = unsmob_music ($1);
2581 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2582 SCM es = m->get_property ("elements");
2583 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2585 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2586 unsmob_music (scm_car (s))->set_property ("duration", dur);
2587 es = ly_append2 (es, postevs);
2589 m-> set_property ("elements", es);
2591 $$ = m->self_scm ();
2596 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2598 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2600 | CHORD_BODY_IDENTIFIER
2603 chord_body_elements:
2604 /* empty */ { $$ = SCM_EOL; }
2605 | chord_body_elements chord_body_element {
2606 if (!SCM_UNBNDP ($2))
2607 $$ = scm_cons ($2, $1);
2612 pitch exclamations questions octave_check post_events
2614 bool q = to_boolean ($3);
2615 bool ex = to_boolean ($2);
2619 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2620 n->set_property ("pitch", $1);
2622 n->set_property ("cautionary", SCM_BOOL_T);
2624 n->set_property ("force-accidental", SCM_BOOL_T);
2626 if (scm_is_pair (post)) {
2627 SCM arts = scm_reverse_x (post, SCM_EOL);
2628 n->set_property ("articulations", arts);
2630 if (scm_is_number (check))
2632 int q = scm_to_int (check);
2633 n->set_property ("absolute-octave", scm_from_int (q-1));
2636 $$ = n->unprotect ();
2638 | DRUM_PITCH post_events {
2639 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2640 n->set_property ("drum-type", $1);
2642 if (scm_is_pair ($2)) {
2643 SCM arts = scm_reverse_x ($2, SCM_EOL);
2644 n->set_property ("articulations", arts);
2646 $$ = n->unprotect ();
2648 | music_function_chord_body
2650 Music *m = unsmob_music ($1);
2652 while (m && m->is_mus_type ("music-wrapper-music")) {
2653 $$ = m->get_property ("element");
2654 m = unsmob_music ($$);
2657 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2658 parser->parser_error (@$, _ ("not a rhythmic event"));
2664 music_function_chord_body:
2669 // Event functions may only take closed arglists, otherwise it would
2670 // not be clear whether a following postevent should be associated
2671 // with the last argument of the event function or with the expression
2672 // for which the function call acts itself as event.
2674 music_function_call_closed:
2675 MUSIC_FUNCTION function_arglist_closed {
2676 $$ = MAKE_SYNTAX ("music-function", @$,
2681 event_function_event:
2682 EVENT_FUNCTION function_arglist_closed {
2683 $$ = MAKE_SYNTAX ("music-function", @$,
2705 | post_events post_event {
2707 if (Music *m = unsmob_music ($2))
2709 if (m->is_mus_type ("post-event-wrapper"))
2711 for (SCM p = m->get_property ("elements");
2715 $$ = scm_cons (scm_car (p), $$);
2719 $$ = scm_cons ($2, $$);
2725 post_event_nofinger:
2726 direction_less_event {
2729 | script_dir music_function_call_closed {
2731 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2732 parser->parser_error (@2, _ ("post-event expected"));
2733 $$ = SCM_UNSPECIFIED;
2734 } else if (!SCM_UNBNDP ($1))
2736 unsmob_music ($$)->set_property ("direction", $1);
2740 if (!parser->lexer_->is_lyric_state ())
2741 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2742 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2745 if (!parser->lexer_->is_lyric_state ())
2746 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2747 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2749 | script_dir direction_reqd_event {
2750 if (!SCM_UNBNDP ($1))
2752 Music *m = unsmob_music ($2);
2753 m->set_property ("direction", $1);
2757 | script_dir direction_less_event {
2758 if (!SCM_UNBNDP ($1))
2760 Music *m = unsmob_music ($2);
2761 m->set_property ("direction", $1);
2768 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2773 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2784 string_number_event:
2786 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2787 s->set_property ("string-number", $1);
2788 $$ = s->unprotect ();
2792 direction_less_event:
2794 | EVENT_IDENTIFIER {
2798 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2799 a->set_property ("tremolo-type", $1);
2800 $$ = a->unprotect ();
2802 | event_function_event
2805 direction_reqd_event:
2809 | script_abbreviation {
2810 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2811 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2812 if (scm_is_string (s))
2813 a->set_property ("articulation-type", s);
2814 else parser->parser_error (@1, _ ("expecting string as script definition"));
2815 $$ = a->unprotect ();
2820 /**/ { $$ = SCM_EOL; }
2821 | '=' quotes { $$ = $2; }
2835 $$ = scm_from_int (1);
2838 $$ = scm_oneplus ($1);
2844 $$ = scm_from_int (-1);
2847 $$ = scm_oneminus ($1);
2852 NOTENAME_PITCH quotes {
2853 if (!scm_is_eq (SCM_INUM0, $2))
2855 Pitch p = *unsmob_pitch ($1);
2856 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2857 $$ = p.smobbed_copy ();
2867 TONICNAME_PITCH quotes {
2868 if (!scm_is_eq (SCM_INUM0, $2))
2870 Pitch p = *unsmob_pitch ($1);
2871 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2872 $$ = p.smobbed_copy ();
2879 | PITCH_IDENTIFIER quotes {
2880 if (!scm_is_eq (SCM_INUM0, $2))
2882 Pitch p = *unsmob_pitch ($1);
2883 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2884 $$ = p.smobbed_copy ();
2891 if (!scm_is_eq (SCM_INUM0, $2))
2893 Pitch p = *unsmob_pitch ($1);
2894 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2895 $$ = p.smobbed_copy ();
2902 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2903 t->set_property ("text", $1);
2904 $$ = t->unprotect ();
2907 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2908 t->set_property ("text",
2909 make_simple_markup ($1));
2910 $$ = t->unprotect ();
2912 | embedded_scm_closed
2914 Music *m = unsmob_music ($1);
2915 if (m && m->is_mus_type ("post-event"))
2917 else if (Text_interface::is_markup ($1)) {
2918 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2919 t->set_property ("text", $1);
2920 $$ = t->unprotect ();
2922 parser->parser_error (@1, _ ("not an articulation"));
2928 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2929 t->set_property ("digit", $1);
2930 $$ = t->unprotect ();
2934 script_abbreviation:
2936 $$ = scm_from_locale_string ("Hat");
2939 $$ = scm_from_locale_string ("Plus");
2942 $$ = scm_from_locale_string ("Dash");
2945 $$ = scm_from_locale_string ("Bang");
2948 $$ = scm_from_locale_string ("Larger");
2951 $$ = scm_from_locale_string ("Dot");
2954 $$ = scm_from_locale_string ("Underscore");
2959 '_' { $$ = scm_from_int (DOWN); }
2960 | '^' { $$ = scm_from_int (UP); }
2961 | '-' { $$ = SCM_UNDEFINED; }
2965 multiplied_duration {
2970 maybe_notemode_duration:
2974 | multiplied_duration {
2976 parser->default_duration_ = *unsmob_duration ($$);
2981 optional_notemode_duration:
2982 maybe_notemode_duration
2984 if (SCM_UNBNDP ($$))
2985 $$ = parser->default_duration_.smobbed_copy ();
2991 $$ = make_duration ($1, scm_to_int ($2));
2992 if (SCM_UNBNDP ($$))
2994 parser->parser_error (@1, _ ("not a duration"));
2995 $$ = Duration ().smobbed_copy ();
2998 | DURATION_IDENTIFIER dots {
2999 Duration *d = unsmob_duration ($1);
3000 Duration k (d->duration_log (),
3001 d->dot_count () + scm_to_int ($2));
3002 k = k.compressed (d->factor ());
3003 scm_remember_upto_here_1 ($1);
3004 $$ = k.smobbed_copy ();
3008 multiplied_duration:
3012 | multiplied_duration '*' UNSIGNED {
3013 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
3015 | multiplied_duration '*' FRACTION {
3016 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
3018 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
3027 $$ = scm_oneplus ($1);
3036 if (SCM_UNBNDP (make_duration ($2)))
3037 parser->parser_error (@2, _ ("not a duration"));
3043 UNSIGNED { $$ = $1; }
3044 | STRING { $$ = $1; }
3045 | full_markup { $$ = $1; }
3048 // as an integer, it needs to be non-negative, and otherwise
3049 // it needs to be suitable as a markup.
3050 if (scm_is_integer ($1)
3051 ? scm_is_true (scm_negative_p ($1))
3052 : !Text_interface::is_markup ($1))
3054 parser->parser_error (@1, _ ("bass number expected"));
3060 figured_bass_alteration:
3061 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3062 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3063 | '!' { $$ = scm_from_int (0); }
3068 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3069 $$ = bfr->unprotect ();
3072 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3073 $$ = bfr->self_scm ();
3075 if (scm_is_number ($1))
3076 bfr->set_property ("figure", $1);
3077 else if (Text_interface::is_markup ($1))
3078 bfr->set_property ("text", $1);
3084 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3086 | bass_figure figured_bass_alteration {
3087 Music *m = unsmob_music ($1);
3088 if (scm_to_double ($2)) {
3089 SCM salter = m->get_property ("alteration");
3090 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3091 m->set_property ("alteration",
3092 scm_sum (alter, $2));
3094 m->set_property ("alteration", scm_from_int (0));
3097 | bass_figure figured_bass_modification {
3098 Music *m = unsmob_music ($1);
3099 m->set_property ($2, SCM_BOOL_T);
3104 figured_bass_modification:
3106 $$ = ly_symbol2scm ("augmented");
3109 $$ = ly_symbol2scm ("no-continuation");
3112 $$ = ly_symbol2scm ("diminished");
3115 $$ = ly_symbol2scm ("augmented-slash");
3125 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3133 | figure_list br_bass_figure {
3134 $$ = scm_cons ($2, $1);
3139 FIGURE_OPEN figure_list FIGURE_CLOSE {
3140 $$ = scm_reverse_x ($2, SCM_EOL);
3146 /**/ { $$ = SCM_BOOL_F; }
3147 | REST { $$ = SCM_BOOL_T; }
3151 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3152 if (!parser->lexer_->is_note_state ())
3153 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3154 if (!SCM_UNBNDP ($2)
3156 || scm_is_number ($4)
3158 || scm_is_true ($6))
3161 if (scm_is_true ($6))
3162 n = MY_MAKE_MUSIC ("RestEvent", @$);
3164 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3166 n->set_property ("pitch", $1);
3167 if (SCM_UNBNDP ($5))
3168 n->set_property ("duration",
3169 parser->default_duration_.smobbed_copy ());
3171 n->set_property ("duration", $5);
3173 if (scm_is_number ($4))
3175 int q = scm_to_int ($4);
3176 n->set_property ("absolute-octave", scm_from_int (q-1));
3179 if (to_boolean ($3))
3180 n->set_property ("cautionary", SCM_BOOL_T);
3181 if (to_boolean ($2) || to_boolean ($3))
3182 n->set_property ("force-accidental", SCM_BOOL_T);
3184 $$ = n->unprotect ();
3187 | DRUM_PITCH optional_notemode_duration {
3188 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3189 n->set_property ("duration", $2);
3190 n->set_property ("drum-type", $1);
3192 $$ = n->unprotect ();
3194 | RESTNAME optional_notemode_duration {
3196 if (ly_scm2string ($1) == "s") {
3198 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3201 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3204 ev->set_property ("duration", $2);
3205 $$ = ev->unprotect ();
3209 // Can return a single pitch rather than a list.
3210 simple_chord_elements:
3212 if (!parser->lexer_->is_chord_state ())
3213 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3216 | figure_spec optional_notemode_duration {
3217 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3219 unsmob_music (scm_car (s))->set_property ("duration", $2);
3227 if (!parser->lexer_->is_lyric_state ())
3228 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3232 if (!parser->lexer_->is_lyric_state ())
3233 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3239 lyric_element_music:
3240 lyric_element optional_notemode_duration post_events {
3241 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3242 if (scm_is_pair ($3))
3243 unsmob_music ($$)->set_property
3244 ("articulations", scm_reverse_x ($3, SCM_EOL));
3248 // Can return a single pitch rather than a list.
3250 steno_tonic_pitch maybe_notemode_duration {
3251 if (SCM_UNBNDP ($2))
3254 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3256 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3257 SCM its = scm_reverse_x ($4, SCM_EOL);
3258 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3266 | chord_items chord_item {
3267 $$ = scm_cons ($2, $$);
3273 $$ = ly_symbol2scm ("chord-colon");
3276 $$ = ly_symbol2scm ("chord-caret");
3278 | CHORD_SLASH steno_tonic_pitch {
3279 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3281 | CHORD_BASS steno_tonic_pitch {
3282 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3291 $$ = scm_reverse_x ($1, SCM_EOL);
3299 step_number { $$ = scm_cons ($1, SCM_EOL); }
3300 | step_numbers '.' step_number {
3301 $$ = scm_cons ($3, $$);
3307 $$ = make_chord_step ($1, 0);
3310 $$ = make_chord_step ($1, SHARP_ALTERATION);
3312 | UNSIGNED CHORD_MINUS {
3313 $$ = make_chord_step ($1, FLAT_ALTERATION);
3321 | unsigned_number '-' unsigned_number {
3322 $$ = scm_cons ($1, $3);
3329 TODO: should deprecate in favor of Scheme?
3333 number_expression '+' number_term {
3334 $$ = scm_sum ($1, $3);
3336 | number_expression '-' number_term {
3337 $$ = scm_difference ($1, $3);
3346 | number_factor '*' number_factor {
3347 $$ = scm_product ($1, $3);
3349 | number_factor '/' number_factor {
3350 $$ = scm_divide ($1, $3);
3355 '-' number_factor { /* %prec UNARY_MINUS */
3356 $$ = scm_difference ($2, SCM_UNDEFINED);
3362 bare_number_common_closed
3363 | REAL NUMBER_IDENTIFIER
3365 $$ = scm_product ($1, $2);
3369 bare_number_common_closed:
3377 | UNSIGNED NUMBER_IDENTIFIER {
3378 $$ = scm_product ($1, $2);
3384 | bare_number_common_closed
3391 if (!scm_is_integer ($1)
3392 || scm_is_true (scm_negative_p ($1)))
3394 parser->parser_error (@1, _("not an unsigned integer"));
3400 if (!scm_is_integer ($1)
3401 || scm_is_true (scm_negative_p ($1)))
3403 parser->parser_error (@1, _("not an unsigned integer"));
3410 { $$ = SCM_UNDEFINED; }
3413 if (SCM_UNBNDP ($1))
3421 { $$ = SCM_UNDEFINED; }
3424 if (SCM_UNBNDP ($1))
3433 { parser->lexer_->push_markup_state (); }
3436 parser->lexer_->pop_state ();
3442 { parser->lexer_->push_markup_state (); }
3445 parser->lexer_->pop_state ();
3451 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3453 | markup_head_1_list simple_markup
3455 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3456 @2, $1, scm_list_1 ($2)));
3466 if (Text_interface::is_markup ($1))
3467 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3468 else if (Text_interface::is_markup_list ($1))
3469 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3471 parser->parser_error (@1, _ ("not a markup"));
3472 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3479 markup_composed_list {
3482 | markup_uncomposed_list
3485 markup_uncomposed_list:
3486 markup_braced_list {
3489 | markup_command_list {
3490 $$ = scm_list_1 ($1);
3492 | markup_scm MARKUPLIST_IDENTIFIER
3498 markup_composed_list:
3499 markup_head_1_list markup_uncomposed_list {
3500 $$ = MAKE_SYNTAX ("composed-markup-list",
3506 '{' markup_braced_list_body '}' {
3507 $$ = scm_reverse_x ($2, SCM_EOL);
3511 markup_braced_list_body:
3512 /* empty */ { $$ = SCM_EOL; }
3513 | markup_braced_list_body markup {
3514 $$ = scm_cons ($2, $1);
3516 | markup_braced_list_body markup_list {
3517 $$ = scm_reverse_x ($2, $1);
3521 markup_command_list:
3522 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3523 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3527 markup_command_basic_arguments:
3528 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3529 $$ = scm_cons ($3, $2);
3531 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3532 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3534 | EXPECT_NO_MORE_ARGS {
3539 markup_command_list_arguments:
3540 markup_command_basic_arguments { $$ = $1; }
3541 | EXPECT_MARKUP markup_command_list_arguments markup {
3542 $$ = scm_cons ($3, $2);
3547 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3548 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3553 markup_head_1_item {
3554 $$ = scm_list_1 ($1);
3556 | markup_head_1_list markup_head_1_item {
3557 $$ = scm_cons ($2, $1);
3563 $$ = make_simple_markup ($1);
3566 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3567 parser->lexer_->push_note_state (nn);
3568 } '{' score_body '}' {
3569 unsmob_score ($4)->origin ()->set_spot (@$);
3570 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3571 parser->lexer_->pop_state ();
3573 | MARKUP_FUNCTION markup_command_basic_arguments {
3574 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3576 | markup_scm MARKUP_IDENTIFIER
3583 markup_head_1_list simple_markup
3585 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3586 @2, $1, scm_list_1 ($2)));
3596 Lily_parser::set_yydebug (bool x)
3602 Lily_parser::do_yyparse ()
3604 SCM retval = SCM_UNDEFINED;
3605 yyparse (this, &retval);
3615 It is a little strange to have this function in this file, but
3616 otherwise, we have to import music classes into the lexer.
3620 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3622 if (unsmob_book (sid)) {
3623 Book *book = unsmob_book (sid)->clone ();
3624 *destination = book->self_scm ();
3627 return BOOK_IDENTIFIER;
3628 } else if (scm_is_number (sid)) {
3630 return NUMBER_IDENTIFIER;
3631 } else if (unsmob_context_def (sid)) {
3632 Context_def *def= unsmob_context_def (sid)->clone ();
3634 *destination = def->self_scm ();
3637 return CONTEXT_DEF_IDENTIFIER;
3638 } else if (unsmob_context_mod (sid)) {
3639 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3641 return CONTEXT_MOD_IDENTIFIER;
3642 } else if (Music *mus = unsmob_music (sid)) {
3643 mus = mus->clone ();
3644 *destination = mus->self_scm ();
3645 bool is_event = mus->is_mus_type ("post-event");
3647 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3648 } else if (unsmob_pitch (sid)) {
3649 *destination = unsmob_pitch (sid)->smobbed_copy ();
3650 return PITCH_IDENTIFIER;
3651 } else if (unsmob_duration (sid)) {
3652 *destination = unsmob_duration (sid)->smobbed_copy ();
3653 return DURATION_IDENTIFIER;
3654 } else if (unsmob_output_def (sid)) {
3655 Output_def *p = unsmob_output_def (sid);
3658 *destination = p->self_scm ();
3660 return OUTPUT_DEF_IDENTIFIER;
3661 } else if (unsmob_score (sid)) {
3662 *destination = unsmob_score (sid)->clone ()->unprotect ();
3663 return SCM_IDENTIFIER;
3670 get_next_unique_context_id ()
3672 return scm_from_locale_string ("$uniqueContextId");
3677 get_next_unique_lyrics_context_id ()
3679 static int new_context_count;
3681 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3682 return scm_from_locale_string (s);
3685 // check_scheme_arg checks one argument with a given predicate for use
3686 // in an argument list and throws a syntax error if it is unusable.
3687 // The argument is prepended to the argument list in any case. After
3688 // throwing a syntax error, the argument list is terminated with #f as
3689 // its last cdr in order to mark it as uncallable while not losing
3690 // track of its total length.
3692 // There are a few special considerations: if optional argument disp
3693 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3694 // instead of arg in a prospective error message. This is useful if
3695 // arg is not the actual argument but rather a transformation of it.
3697 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3698 // and an error message using disp is produced unconditionally.
3700 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3701 SCM arg, SCM args, SCM pred, SCM disp)
3703 if (SCM_UNBNDP (arg))
3704 args = scm_cons (disp, args);
3706 args = scm_cons (arg, args);
3707 if (scm_is_true (scm_call_1 (pred, arg)))
3710 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3711 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3712 SCM_UNBNDP (disp) ? arg : disp);
3713 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3717 SCM loc_on_music (Input loc, SCM arg)
3719 if (Music *m = unsmob_music (arg))
3723 return m->unprotect ();
3729 try_string_variants (SCM pred, SCM str)
3731 // a matching predicate is always ok
3732 if (scm_is_true (scm_call_1 (pred, str)))
3734 // a symbol may be interpreted as a list of symbols if it helps
3735 if (scm_is_symbol (str)) {
3736 str = scm_list_1 (str);
3737 if (scm_is_true (scm_call_1 (pred, str)))
3739 return SCM_UNDEFINED;
3742 // If this cannot be a string representation of a symbol list,
3745 if (!is_regular_identifier (str, true))
3746 return SCM_UNDEFINED;
3748 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3749 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3750 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3752 // Let's attempt the symbol list interpretation first.
3754 if (scm_is_true (scm_call_1 (pred, str)))
3757 // If there is just one symbol in the list, we might interpret
3758 // it as a single symbol
3760 if (scm_is_null (scm_cdr (str)))
3762 str = scm_car (str);
3763 if (scm_is_true (scm_call_1 (pred, str)))
3767 return SCM_UNDEFINED;
3771 is_regular_identifier (SCM id, bool multiple)
3773 if (!scm_is_string (id))
3776 string str = ly_scm2string (id);
3778 bool middle = false;
3780 for (string::iterator it=str.begin(); it != str.end (); it++)
3783 if ((c >= 'a' && c <= 'z')
3784 || (c >= 'A' && c <= 'Z')
3787 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3796 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3798 if (unsmob_music (simple))
3800 if (parser->lexer_->is_note_state ()) {
3801 if (scm_is_symbol (simple)) {
3802 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3803 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3804 n->set_property ("drum-type", simple);
3805 return n->unprotect ();
3807 if (unsmob_pitch (simple)) {
3808 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3809 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3810 n->set_property ("pitch", simple);
3811 return n->unprotect ();
3814 } else if (parser->lexer_->is_lyric_state ()) {
3815 if (Text_interface::is_markup (simple))
3816 return MAKE_SYNTAX ("lyric-event", loc, simple,
3817 parser->default_duration_.smobbed_copy ());
3818 } else if (parser->lexer_->is_chord_state ()) {
3819 if (unsmob_pitch (simple))
3823 make_chord_elements (loc, simple,
3824 parser->default_duration_.smobbed_copy (),
3831 make_music_with_input (SCM name, Input where)
3833 Music *m = make_music_by_name (name);
3834 m->set_spot (where);
3839 make_simple_markup (SCM a)
3845 make_duration (SCM d, int dots)
3847 int t = scm_to_int (d);
3848 if (t > 0 && (t & (t-1)) == 0)
3849 return Duration (intlog2 (t), dots).smobbed_copy ();
3851 return SCM_UNDEFINED;
3855 make_chord_step (SCM step_scm, Rational alter)
3857 int step = scm_to_int (step_scm);
3860 alter += FLAT_ALTERATION;
3864 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3865 return m.smobbed_copy ();
3870 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3872 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3873 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3874 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3876 unsmob_music (scm_car (s))->set_spot (loc);
3882 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3884 Lily_lexer *lex = parser->lexer_;
3888 lex->prepare_for_next_token ();
3889 return lex->yylex ();