1 /* -*- mode: c++; c-file-style: "linux"; indent-tabs-mode: t -*- */
3 This file is part of LilyPond, the GNU music typesetter.
5 Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 Jan Nieuwenhuizen <janneke@gnu.org>
8 LilyPond is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 /* Mode and indentation are at best a rough approximation based on TAB
23 * formatting (reasonable for compatibility with unspecific editor
24 * modes as Bison modes are hard to find) and need manual correction
25 * frequently. Without a reasonably dependable way of formatting a
26 * Bison file sensibly, there is little point in trying to fix the
27 * inconsistent state of indentation.
32 #define yyerror Lily_parser::parser_error
34 /* We use custom location type: Input objects */
37 #define YYLLOC_DEFAULT(Current,Rhs,N) \
38 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
40 #define YYPRINT(file, type, value) \
42 if (scm_is_eq (value, SCM_UNSPECIFIED)) \
44 char *p = scm_to_locale_string \
45 (scm_simple_format (SCM_BOOL_F, \
46 scm_from_locale_string ("~S"), \
47 scm_list_1 (value))); \
54 %parse-param {Lily_parser *parser}
55 %parse-param {SCM *retval}
56 %lex-param {Lily_parser *parser}
60 /* We use SCMs to do strings, because it saves us the trouble of
61 deleting them. Let's hope that a stack overflow doesn't trigger a move
62 of the parse stack onto the heap. */
65 %nonassoc REPEAT REPEAT_IDENTIFIER
68 /* The above precedences tackle the shift/reduce problem
71 \repeat .. \alternative
73 \repeat { \repeat .. \alternative }
77 \repeat { \repeat } \alternative
83 %right ':' UNSIGNED REAL E_UNSIGNED EVENT_IDENTIFIER EVENT_FUNCTION '^' '_'
84 HYPHEN EXTENDER DURATION_IDENTIFIER
86 /* The above are needed for collecting tremoli and other items (that
87 could otherwise be interpreted as belonging to the next function
88 argument) greedily, and together with the next rule will serve to
89 join numbers and units greedily instead of allowing them into
90 separate function arguments
93 %nonassoc NUMBER_IDENTIFIER
105 %{ // -*-Fundamental-*-
110 * The rules for who is protecting what are very shady. Uniformise
113 * There are too many lexical modes?
124 #include "context-def.hh"
125 #include "context-mod.hh"
126 #include "dimensions.hh"
127 #include "file-path.hh"
129 #include "international.hh"
130 #include "lily-guile.hh"
131 #include "lily-lexer.hh"
132 #include "lily-parser.hh"
136 #include "output-def.hh"
137 #include "paper-book.hh"
138 #include "scm-hash.hh"
140 #include "text-interface.hh"
144 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
146 parser->parser_error (*i, s);
149 #define MYBACKUP(Token, Value, Location) \
151 if (yychar == YYEMPTY) \
154 parser->lexer_->push_extra_token (Token, Value); \
155 parser->lexer_->push_extra_token (BACKUP); \
157 parser->parser_error \
158 (Location, _("Too much lookahead")); \
163 #define MYREPARSE(Location, Pred, Token, Value) \
165 if (yychar == YYEMPTY) \
167 parser->lexer_->push_extra_token (Token, Value); \
168 parser->lexer_->push_extra_token (REPARSE, \
171 parser->parser_error \
172 (Location, _("Too much lookahead")); \
181 #define MY_MAKE_MUSIC(x, spot) \
182 make_music_with_input (ly_symbol2scm (x), \
183 parser->lexer_->override_input (spot))
186 - Don't use lily module, create a new module instead.
187 - delay application of the function
189 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
190 scm_apply_0 (proc, args)
191 /* Syntactic Sugar. */
192 #define MAKE_SYNTAX(name, location, ...) \
193 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (parser->lexer_->override_input (location)), ##__VA_ARGS__, SCM_UNDEFINED))
194 #define START_MAKE_SYNTAX(name, ...) \
195 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
196 #define FINISH_MAKE_SYNTAX(start, location, ...) \
197 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (parser->lexer_->override_input (location)), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
199 SCM get_next_unique_context_id ();
200 SCM get_next_unique_lyrics_context_id ();
207 #define _(x) gettext (x)
211 static Music *make_music_with_input (SCM name, Input where);
212 SCM check_scheme_arg (Lily_parser *parser, Input loc,
213 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
214 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
215 SCM loc_on_music (Input loc, SCM arg);
216 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
217 SCM make_chord_step (SCM step, Rational alter);
218 SCM make_simple_markup (SCM a);
219 SCM make_duration (SCM t, int dots = 0);
220 bool is_regular_identifier (SCM id, bool multiple=false);
221 SCM try_string_variants (SCM pred, SCM str);
222 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
226 /* The third option is an alias that will be used to display the
227 syntax error. Bison CVS now correctly handles backslash escapes.
229 FIXME: Bison needs to translate some of these, eg, STRING.
233 /* Keyword tokens with plain escaped name. */
234 %token END_OF_FILE 0 "end of input"
235 %token ACCEPTS "\\accepts"
236 %token ADDLYRICS "\\addlyrics"
237 %token ALIAS "\\alias"
238 %token ALTERNATIVE "\\alternative"
240 %token BOOKPART "\\bookpart"
241 %token CHANGE "\\change"
242 %token CHORDMODE "\\chordmode"
243 %token CHORDS "\\chords"
244 %token CONSISTS "\\consists"
245 %token CONTEXT "\\context"
246 %token DEFAULT "\\default"
247 %token DEFAULTCHILD "\\defaultchild"
248 %token DENIES "\\denies"
249 %token DESCRIPTION "\\description"
250 %token DRUMMODE "\\drummode"
251 %token DRUMS "\\drums"
252 %token FIGUREMODE "\\figuremode"
253 %token FIGURES "\\figures"
254 %token HEADER "\\header"
255 %token INVALID "\\version-error"
256 %token LAYOUT "\\layout"
257 %token LYRICMODE "\\lyricmode"
258 %token LYRICS "\\lyrics"
259 %token LYRICSTO "\\lyricsto"
260 %token MARKUP "\\markup"
261 %token MARKUPLIST "\\markuplist"
264 %token NOTEMODE "\\notemode"
265 %token OVERRIDE "\\override"
266 %token PAPER "\\paper"
267 %token REMOVE "\\remove"
268 %token REPEAT "\\repeat"
270 %token REVERT "\\revert"
271 %token SCORE "\\score"
272 %token SCORELINES "\\score-lines"
273 %token SEQUENTIAL "\\sequential"
275 %token SIMULTANEOUS "\\simultaneous"
276 %token TEMPO "\\tempo"
278 %token UNSET "\\unset"
281 /* Keyword token exceptions. */
282 %token NEWCONTEXT "\\new"
285 /* Other string tokens. */
287 %token CHORD_BASS "/+"
288 %token CHORD_CARET "^"
289 %token CHORD_COLON ":"
290 %token CHORD_MINUS "-"
291 %token CHORD_SLASH "/"
292 %token ANGLE_OPEN "<"
293 %token ANGLE_CLOSE ">"
294 %token DOUBLE_ANGLE_OPEN "<<"
295 %token DOUBLE_ANGLE_CLOSE ">>"
296 %token E_BACKSLASH "\\"
297 %token E_EXCLAMATION "\\!"
302 If we give names, Bison complains.
304 %token FIGURE_CLOSE /* "\\>" */
305 %token FIGURE_OPEN /* "\\<" */
306 %token FIGURE_SPACE "_"
309 %token MULTI_MEASURE_REST
315 /* Artificial tokens, for more generic function syntax */
316 %token EXPECT_MARKUP "markup?"
317 %token EXPECT_SCM "scheme?"
318 %token BACKUP "(backed-up?)"
319 %token REPARSE "(reparsed?)"
320 %token EXPECT_MARKUP_LIST "markup-list?"
321 %token EXPECT_OPTIONAL "optional?"
322 /* After the last argument. */
323 %token EXPECT_NO_MORE_ARGS;
325 /* An artificial token for parsing embedded Lilypond */
326 %token EMBEDDED_LILY "#{"
328 %token BOOK_IDENTIFIER
329 %token CHORD_BODY_IDENTIFIER
330 %token CHORD_MODIFIER
331 %token CHORD_REPETITION
332 %token CONTEXT_DEF_IDENTIFIER
333 %token CONTEXT_MOD_IDENTIFIER
335 %token PITCH_IDENTIFIER
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", @$,
516 embedded_lilypond_number:
517 '-' embedded_lilypond_number
519 $$ = scm_difference ($2, SCM_UNDEFINED);
522 | UNSIGNED NUMBER_IDENTIFIER
524 $$ = scm_product ($1, $2);
531 // FIXME: @$ does not contain a useful source location
532 // for empty rules, and the only token in the whole
533 // production, EMBEDDED_LILY, is synthetic and also
534 // contains no source location.
535 $$ = MAKE_SYNTAX ("void-music", @$);
537 | identifier_init_nonumber
538 | embedded_lilypond_number
539 | post_event post_events
541 $$ = scm_reverse_x ($2, SCM_EOL);
542 if (Music *m = unsmob_music ($1))
544 if (m->is_mus_type ("post-event-wrapper"))
546 (scm_list_2 (m->get_property ("elements"),
549 $$ = scm_cons ($1, $$);
552 && scm_is_null (scm_cdr ($$)))
556 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
557 m->set_property ("elements", $$);
558 $$ = m->unprotect ();
561 | multiplied_duration
562 | music_embedded music_embedded music_list {
563 $3 = scm_reverse_x ($3, SCM_EOL);
564 if (unsmob_music ($2))
565 $3 = scm_cons ($2, $3);
566 if (unsmob_music ($1))
567 $3 = scm_cons ($1, $3);
568 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
571 parser->error_level_ = 1;
572 $$ = SCM_UNSPECIFIED;
574 | INVALID embedded_lilypond {
575 parser->error_level_ = 1;
581 lilypond_header_body:
582 /* empty */ { $$ = SCM_UNSPECIFIED; }
583 | lilypond_header_body assignment {
586 | lilypond_header_body embedded_scm {
592 HEADER '{' lilypond_header_body '}' {
593 $$ = parser->lexer_->remove_scope ();
605 assignment_id '=' identifier_init {
606 parser->lexer_->set_identifier ($1, $3);
607 $$ = SCM_UNSPECIFIED;
609 | assignment_id property_path '=' identifier_init {
610 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
611 parser->lexer_->set_identifier (path, $4);
612 $$ = SCM_UNSPECIFIED;
618 identifier_init_nonumber
620 | post_event_nofinger post_events
622 $$ = scm_reverse_x ($2, SCM_EOL);
623 if (Music *m = unsmob_music ($1))
625 if (m->is_mus_type ("post-event-wrapper"))
627 (scm_list_2 (m->get_property ("elements"),
630 $$ = scm_cons ($1, $$);
633 && scm_is_null (scm_cdr ($$)))
637 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
638 m->set_property ("elements", $$);
639 $$ = m->unprotect ();
644 identifier_init_nonumber:
649 | context_def_spec_block
655 | context_modification
658 context_def_spec_block:
659 CONTEXT '{' context_def_spec_body '}'
662 unsmob_context_def ($$)->origin ()->set_spot (@$);
670 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
671 parser->lexer_->push_note_state (nn);
675 parser->lexer_->pop_state ();
680 context_mod_embedded:
683 if (unsmob_music ($1)) {
684 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
685 $1 = scm_call_2 (proc, parser->self_scm (), $1);
687 if (unsmob_context_mod ($1))
690 parser->parser_error (@1, _ ("not a context mod"));
691 $$ = Context_mod ().smobbed_copy ();
697 context_def_spec_body:
699 $$ = Context_def::make_scm ();
701 | CONTEXT_DEF_IDENTIFIER {
704 | context_def_spec_body context_mod {
705 if (!SCM_UNBNDP ($2))
706 unsmob_context_def ($$)->add_context_mod ($2);
708 | context_def_spec_body context_modification {
709 Context_def *td = unsmob_context_def ($$);
710 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
711 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
712 td->add_context_mod (scm_car (m));
715 | context_def_spec_body context_mod_embedded {
716 Context_def *td = unsmob_context_def ($$);
717 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
718 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
719 td->add_context_mod (scm_car (m));
727 BOOK '{' book_body '}' {
729 unsmob_book ($$)->origin ()->set_spot (@$);
731 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
736 * Use 'handlers' like for toplevel-* stuff?
737 * grok \layout and \midi? */
740 Book *book = new Book;
741 init_papers (parser);
742 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
743 book->paper_->unprotect ();
744 push_paper (parser, book->paper_);
745 book->header_ = get_header (parser);
746 $$ = book->unprotect ();
747 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
750 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
752 | book_body paper_block {
753 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
754 set_paper (parser, unsmob_output_def ($2));
756 | book_body bookpart_block {
757 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
758 scm_call_2 (proc, $1, $2);
760 | book_body score_block {
761 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
762 scm_call_2 (proc, $1, $2);
764 | book_body composite_music {
765 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
766 scm_call_3 (proc, parser->self_scm (), $1, $2);
768 | book_body full_markup {
769 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
770 scm_call_2 (proc, $1, scm_list_1 ($2));
772 | book_body full_markup_list {
773 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
774 scm_call_2 (proc, $1, $2);
776 | book_body SCM_TOKEN {
777 // Evaluate and ignore #xxx, as opposed to \xxx
778 parser->lexer_->eval_scm_token ($2);
780 | book_body embedded_scm_active
782 SCM out = SCM_UNDEFINED;
783 if (Text_interface::is_markup ($2))
784 out = scm_list_1 ($2);
785 else if (Text_interface::is_markup_list ($2))
787 if (scm_is_pair (out))
789 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
790 scm_call_2 (proc, $1, out);
791 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
792 parser->parser_error (@2, _("bad expression type"));
796 parser->lexer_->add_scope (unsmob_book ($1)->header_);
799 Book *book = unsmob_book ($1);
801 book->scores_ = SCM_EOL;
802 book->bookparts_ = SCM_EOL;
807 BOOKPART '{' bookpart_body '}' {
809 unsmob_book ($$)->origin ()->set_spot (@$);
810 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
816 Book *book = new Book;
817 $$ = book->unprotect ();
818 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
821 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
823 | bookpart_body paper_block {
824 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
826 | bookpart_body score_block {
827 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
828 scm_call_2 (proc, $1, $2);
830 | bookpart_body composite_music {
831 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
832 scm_call_3 (proc, parser->self_scm (), $1, $2);
834 | bookpart_body full_markup {
835 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
836 scm_call_2 (proc, $1, scm_list_1 ($2));
838 | bookpart_body full_markup_list {
839 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
840 scm_call_2 (proc, $1, $2);
842 | bookpart_body SCM_TOKEN {
843 // Evaluate and ignore #xxx, as opposed to \xxx
844 parser->lexer_->eval_scm_token ($2);
846 | bookpart_body embedded_scm_active
848 SCM out = SCM_UNDEFINED;
849 if (Text_interface::is_markup ($2))
850 out = scm_list_1 ($2);
851 else if (Text_interface::is_markup_list ($2))
853 if (scm_is_pair (out))
855 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
856 scm_call_2 (proc, $1, out);
857 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
858 parser->parser_error (@2, _("bad expression type"));
862 Book *book = unsmob_book ($1);
863 if (!ly_is_module (book->header_))
864 book->header_ = ly_make_module (false);
865 parser->lexer_->add_scope (book->header_);
867 | bookpart_body error {
868 Book *book = unsmob_book ($1);
870 book->scores_ = SCM_EOL;
875 SCORE '{' score_body '}' {
882 SCM scorify = ly_lily_module_constant ("scorify-music");
883 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
885 unsmob_score ($$)->origin ()->set_spot (@$);
887 | embedded_scm_active {
889 if (unsmob_score ($1))
890 score = new Score (*unsmob_score ($1));
893 parser->parser_error (@1, _("score expected"));
895 unsmob_score ($$)->origin ()->set_spot (@$);
896 $$ = score->unprotect ();
900 Score *score = unsmob_score ($1);
901 if (!ly_is_module (score->get_header ()))
902 score->set_header (ly_make_module (false));
903 parser->lexer_->add_scope (score->get_header ());
905 | score_body output_def {
906 Output_def *od = unsmob_output_def ($2);
907 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
909 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
914 unsmob_score ($1)->add_output_def (od);
918 unsmob_score ($$)->error_found_ = true;
929 Output_def *od = unsmob_output_def ($1);
931 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
933 parser->parser_error (@1, _ ("need \\paper for paper block"));
934 $$ = get_paper (parser)->unprotect ();
941 output_def_body '}' {
944 parser->lexer_->remove_scope ();
945 parser->lexer_->pop_state ();
951 Output_def *p = get_paper (parser);
952 p->input_origin_ = @$;
953 parser->lexer_->add_scope (p->scope_);
954 $$ = p->unprotect ();
957 Output_def *p = get_midi (parser);
958 $$ = p->unprotect ();
959 parser->lexer_->add_scope (p->scope_);
962 Output_def *p = get_layout (parser);
964 parser->lexer_->add_scope (p->scope_);
965 $$ = p->unprotect ();
969 output_def_head_with_mode_switch:
971 parser->lexer_->push_initial_state ();
976 // We need this weird nonterminal because both music as well as a
977 // context definition can start with \context and the difference is
978 // only apparent after looking at the next token. If it is '{', there
979 // is still time to escape from notes mode.
981 music_or_context_def:
983 | context_def_spec_block
987 output_def_head_with_mode_switch '{' {
989 unsmob_output_def ($$)->input_origin_.set_spot (@$);
991 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
992 Output_def *o = unsmob_output_def ($3);
993 o->input_origin_.set_spot (@$);
995 parser->lexer_->remove_scope ();
996 parser->lexer_->add_scope (o->scope_);
998 | output_def_body assignment {
1001 | output_def_body embedded_scm {
1006 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1007 parser->lexer_->push_note_state (nn);
1008 } music_or_context_def
1010 parser->lexer_->pop_state ();
1011 if (unsmob_context_def ($3))
1012 assign_context_def (unsmob_output_def ($1), $3);
1015 SCM proc = parser->lexer_->lookup_identifier
1016 ("output-def-music-handler");
1017 scm_call_3 (proc, parser->self_scm (),
1021 | output_def_body error {
1027 TEMPO steno_duration '=' tempo_range {
1028 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1030 | TEMPO scalar steno_duration '=' tempo_range {
1031 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1034 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1039 The representation of a list is reversed to have efficient append. */
1045 | music_list music_embedded {
1046 if (unsmob_music ($2))
1047 $$ = scm_cons ($2, $1);
1049 | music_list error {
1050 Music *m = MY_MAKE_MUSIC("Music", @$);
1052 m->set_property ("error-found", SCM_BOOL_T);
1053 $$ = scm_cons (m->self_scm (), $1);
1054 m->unprotect (); /* UGH */
1061 $$ = scm_reverse_x ($2, SCM_EOL);
1066 | lyric_element_music
1072 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1073 parser->parser_error (@1, _ ("unexpected post-event"));
1074 $$ = SCM_UNSPECIFIED;
1077 | music_embedded_backup
1081 | music_embedded_backup BACKUP lyric_element_music
1085 | multiplied_duration post_events
1087 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1089 parser->default_duration_ = *unsmob_duration ($1);
1090 n->set_property ("duration", $1);
1092 if (scm_is_pair ($2))
1093 n->set_property ("articulations",
1094 scm_reverse_x ($2, SCM_EOL));
1095 $$ = n->unprotect ();
1099 music_embedded_backup:
1102 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1104 else if (Music *m = unsmob_music ($1)) {
1105 if (m->is_mus_type ("post-event")) {
1106 parser->parser_error
1107 (@1, _ ("unexpected post-event"));
1108 $$ = SCM_UNSPECIFIED;
1111 } else if (parser->lexer_->is_lyric_state ()
1112 && Text_interface::is_markup ($1))
1113 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1115 @$.warning (_ ("Ignoring non-music expression"));
1124 $$ = make_music_from_simple (parser, @1, $1);
1125 if (!unsmob_music ($$))
1127 parser->parser_error (@1, _ ("music expected"));
1128 $$ = MAKE_SYNTAX ("void-music", @$);
1131 | composite_music %prec COMPOSITE
1136 | composite_music %prec COMPOSITE
1140 REPEAT simple_string unsigned_number music
1142 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1144 | REPEAT_IDENTIFIER music
1146 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1149 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1151 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1153 | REPEAT_IDENTIFIER music ALTERNATIVE braced_music_list
1155 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1161 SEQUENTIAL braced_music_list {
1162 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1164 | braced_music_list {
1165 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1170 SIMULTANEOUS braced_music_list {
1171 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1173 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1174 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1180 | music_property_def
1184 context_modification:
1187 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1188 parser->lexer_->push_note_state (nn);
1189 } '{' context_mod_list '}'
1191 parser->lexer_->pop_state ();
1194 | WITH CONTEXT_MOD_IDENTIFIER
1198 | CONTEXT_MOD_IDENTIFIER
1202 | WITH context_modification_arg
1204 if (unsmob_music ($2)) {
1205 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1206 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1208 if (unsmob_context_mod ($2))
1211 parser->parser_error (@2, _ ("not a context mod"));
1212 $$ = Context_mod ().smobbed_copy ();
1217 context_modification_arg:
1222 optional_context_mod:
1226 | context_modification
1234 $$ = Context_mod ().smobbed_copy ();
1236 | context_mod_list context_mod {
1237 if (!SCM_UNBNDP ($2))
1238 unsmob_context_mod ($1)->add_context_mod ($2);
1240 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1241 Context_mod *md = unsmob_context_mod ($2);
1243 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1245 | context_mod_list context_mod_embedded {
1246 unsmob_context_mod ($1)->add_context_mods
1247 (unsmob_context_mod ($2)->get_mods ());
1256 /* Music that can be parsed without lookahead */
1259 | complex_music_prefix closed_music
1261 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1263 | music_function_call_closed
1269 | grouped_music_list
1273 simultaneous_music { $$ = $1; }
1274 | sequential_music { $$ = $1; }
1277 /* Function argument lists are arguably the most complex part in the
1278 * parser. They are pretty tricky to understand because of the way
1279 * they are processed, and because of optional arguments that can be
1280 * omitted. When there are several optional arguments in a row,
1281 * omitting one automatically omits all following arguments. Optional
1282 * arguments can only be omitted when either
1284 * a) the omission is explicitly started with \default
1285 * b) the omission is implicitly started by an argument not matching
1286 * its predicate, and there is a mandatory argument later that can
1287 * "catch" the argument that does not fit.
1289 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1290 * (corresponding to mandatory arguments and having a predicate
1291 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1292 * the semantic value of the EXPECT_OPTIONAL token is the default to
1293 * use when the optional argument is omitted, and EXPECT_SCM again has
1294 * the argument predicate as semantic value) in reverse order to the
1295 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1296 * processed inside-out while actual tokens are consumed.
1298 * This means that the argument list tokens determine the actions
1299 * taken as they arrive. The structure of the argument list is known
1300 * to the parser and stored in its parse stack when the first argument
1301 * is being parsed. What the parser does not know is which predicates
1302 * will match and whether or not \default will be appearing in the
1303 * argument list, and where.
1305 * Many of the basic nonterminals used for argument list scanning come
1306 * in a "normal" and a "closed" flavor. A closed expression is one
1307 * that can be parsed without a lookahead token. That makes it
1308 * feasible for an optional argument that may need to be skipped:
1309 * skipping can only be accomplished by pushing back the token into
1310 * the lexer, and that only works when there is no lookahead token.
1312 * Sequences of 0 or more optional arguments are scanned using either
1313 * function_arglist_backup or function_arglist_nonbackup. The first
1314 * is used when optional arguments are followed by at least one
1315 * mandatory argument: in that case optional arguments may be skipped
1316 * by either a false predicate (in which case the expression will be
1317 * pushed back as one or more tokens, preceded by a BACKUP token) or
1318 * by using \default.
1320 * If optional arguments are at the end of the argument list, they are
1321 * instead scanned using function_arglist_nonbackup: here the only
1322 * manner to enter into skipping of optional arguments is the use of
1325 * The argument list of a normal function call is parsed using
1326 * function_arglist. The part of an argument list before a mandatory
1327 * argument is parsed using function_arglist_optional.
1329 * The difference is that leading optional arguments are scanned using
1330 * function_arglist_nonbackup and function_arglist_backup,
1333 * Most other details are obvious in the rules themselves.
1337 function_arglist_nonbackup_common:
1338 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1340 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1342 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1344 SCM n = scm_difference ($5, SCM_UNDEFINED);
1345 if (scm_is_true (scm_call_1 ($2, n)))
1346 $$ = scm_cons (n, $3);
1348 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1349 t->set_property ("digit", $5);
1350 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1355 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1357 $$ = check_scheme_arg (parser, @4,
1358 scm_difference ($5, SCM_UNDEFINED),
1361 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1363 $$ = check_scheme_arg (parser, @4,
1364 scm_difference ($5, SCM_UNDEFINED),
1369 function_arglist_closed_nonbackup:
1370 function_arglist_nonbackup_common
1371 | function_arglist_closed_common
1372 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg_closed
1374 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1376 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_closed
1378 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1380 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1382 $$ = check_scheme_arg (parser, @4,
1383 try_string_variants ($2, $4),
1386 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1388 $$ = check_scheme_arg (parser, @4,
1389 try_string_variants ($2, $4),
1392 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1394 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1400 | SYMBOL_LIST '.' symbol_list_rev
1402 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1408 | symbol_list_rev '.' symbol_list_part
1410 $$ = scm_append_x (scm_list_2 ($3, $1));
1414 // symbol_list_part delivers elements in reverse copy.
1419 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1420 $$ = try_string_variants (sym_l_p, $1);
1421 if (SCM_UNBNDP ($$)) {
1422 parser->parser_error (@1, _("not a symbol"));
1425 $$ = scm_reverse ($$);
1430 symbol_list_element:
1436 function_arglist_nonbackup:
1437 function_arglist_nonbackup_common
1438 | function_arglist_common
1439 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1441 if (scm_is_true (scm_call_1 ($2, $4)))
1442 $$ = scm_cons ($4, $3);
1444 $$ = check_scheme_arg (parser, @4,
1445 make_music_from_simple
1449 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1451 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1453 | function_arglist_nonbackup_reparse REPARSE duration_length
1455 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1457 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1459 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1461 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1463 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1465 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1467 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1469 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1471 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1475 function_arglist_nonbackup_reparse:
1476 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1479 SCM res = try_string_variants ($2, $4);
1480 if (!SCM_UNBNDP (res))
1481 if (scm_is_pair (res))
1482 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1484 MYREPARSE (@4, $2, SCM_ARG, res);
1485 else if (scm_is_true
1487 ($2, make_music_from_simple
1489 MYREPARSE (@4, $2, STRING, $4);
1491 MYREPARSE (@4, $2, SCM_ARG, $4);
1493 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1496 SCM res = try_string_variants ($2, $4);
1497 if (!SCM_UNBNDP (res))
1498 if (scm_is_pair (res))
1499 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1501 MYREPARSE (@4, $2, SCM_ARG, res);
1502 else if (scm_is_true
1504 ($2, make_music_from_simple
1506 MYREPARSE (@4, $2, STRING, $4);
1508 MYREPARSE (@4, $2, SCM_ARG, $4);
1510 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1513 if (scm_is_true (scm_call_1 ($2, $4)))
1514 MYREPARSE (@4, $2, SCM_ARG, $4);
1515 else if (scm_is_true
1517 ($2, make_music_from_simple
1519 MYREPARSE (@4, $2, STRING, $4);
1521 MYREPARSE (@4, $2, SCM_ARG, $4);
1523 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1526 if (scm_is_true (scm_call_1 ($2, $4)))
1527 MYREPARSE (@4, $2, REAL, $4);
1529 SCM d = make_duration ($4);
1530 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1531 MYREPARSE (@4, $2, REAL, $4); // trigger error
1533 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1536 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1538 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
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 if (scm_is_true (scm_call_1 ($2, $4)))
1683 $$ = scm_cons ($4, $3);
1685 $$ = scm_cons (loc_on_music (@3, $1), $3);
1686 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1689 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NOTENAME_PITCH
1691 if (scm_is_true (scm_call_1 ($2, $4)))
1693 MYREPARSE (@4, $2, NOTENAME_PITCH, $4);
1696 $$ = scm_cons (loc_on_music (@3, $1), $3);
1697 MYBACKUP (NOTENAME_PITCH, $4, @4);
1700 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup TONICNAME_PITCH
1702 if (scm_is_true (scm_call_1 ($2, $4)))
1704 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1707 $$ = scm_cons (loc_on_music (@3, $1), $3);
1708 MYBACKUP (TONICNAME_PITCH, $4, @4);
1711 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1713 if (scm_is_true (scm_call_1 ($2, $4)))
1715 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1718 $$ = scm_cons (loc_on_music (@3, $1), $3);
1719 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1722 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1724 SCM res = try_string_variants ($2, $4);
1725 if (!SCM_UNBNDP (res))
1726 if (scm_is_pair (res)) {
1728 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1731 $$ = scm_cons (res, $3);
1733 $$ = scm_cons (loc_on_music (@3, $1), $3);
1734 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1737 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1739 SCM res = try_string_variants ($2, $4);
1740 if (!SCM_UNBNDP (res))
1741 if (scm_is_pair (res)) {
1743 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1746 $$ = scm_cons (res, $3);
1748 $$ = scm_cons (loc_on_music (@3, $1), $3);
1749 MYBACKUP (STRING, $4, @4);
1752 | function_arglist_backup REPARSE music_assign
1754 if (scm_is_true (scm_call_1 ($2, $3)))
1755 $$ = scm_cons ($3, $1);
1757 $$ = check_scheme_arg (parser, @3,
1758 make_music_from_simple
1762 | function_arglist_backup REPARSE bare_number_common
1764 $$ = check_scheme_arg (parser, @3,
1767 | function_arglist_backup REPARSE duration_length
1769 $$ = check_scheme_arg (parser, @3,
1772 | function_arglist_backup REPARSE symbol_list_arg
1774 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1779 function_arglist_nonbackup
1780 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1782 $$ = scm_cons (loc_on_music (@4, $1), $3);
1786 function_arglist_skip_nonbackup:
1787 function_arglist_nonbackup
1788 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1790 $$ = scm_cons (loc_on_music (@3, $1), $3);
1794 function_arglist_common:
1795 EXPECT_NO_MORE_ARGS {
1798 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1800 if (scm_is_true (scm_call_1 ($1, $3)))
1801 $$ = scm_cons ($3, $2);
1803 $$ = check_scheme_arg (parser, @3,
1804 make_music_from_simple
1808 | EXPECT_SCM function_arglist_optional bare_number_common
1810 $$ = check_scheme_arg (parser, @3,
1813 | EXPECT_SCM function_arglist_optional post_event_nofinger
1815 $$ = check_scheme_arg (parser, @3,
1818 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1820 SCM n = scm_difference ($4, SCM_UNDEFINED);
1821 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1823 | function_arglist_common_reparse REPARSE SCM_ARG
1825 $$ = check_scheme_arg (parser, @3,
1828 | function_arglist_common_reparse REPARSE lyric_element_music
1830 $$ = check_scheme_arg (parser, @3,
1833 | function_arglist_common_reparse REPARSE bare_number_common
1835 $$ = check_scheme_arg (parser, @3,
1838 | function_arglist_common_reparse REPARSE duration_length
1840 $$ = check_scheme_arg (parser, @3,
1843 | function_arglist_common_reparse REPARSE symbol_list_arg
1845 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1849 function_arglist_common_reparse:
1850 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1853 SCM res = try_string_variants ($1, $3);
1854 if (!SCM_UNBNDP (res))
1855 if (scm_is_pair (res))
1856 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1858 MYREPARSE (@3, $1, SCM_ARG, res);
1859 else if (scm_is_true
1861 ($1, make_music_from_simple (parser, @3, $3))))
1862 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1864 // This is going to flag a syntax error, we
1865 // know the predicate to be false.
1866 MYREPARSE (@3, $1, SCM_ARG, $3);
1868 | EXPECT_SCM function_arglist_optional STRING
1871 SCM res = try_string_variants ($1, $3);
1872 if (!SCM_UNBNDP (res))
1873 if (scm_is_pair (res))
1874 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1876 MYREPARSE (@3, $1, SCM_ARG, res);
1877 else if (scm_is_true
1879 ($1, make_music_from_simple (parser, @3, $3))))
1880 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1882 // This is going to flag a syntax error, we
1883 // know the predicate to be false.
1884 MYREPARSE (@3, $1, SCM_ARG, $3);
1886 | EXPECT_SCM function_arglist_optional full_markup
1889 if (scm_is_true (scm_call_1 ($1, $3)))
1890 MYREPARSE (@3, $1, SCM_ARG, $3);
1891 else if (scm_is_true
1893 ($1, make_music_from_simple (parser, @3, $3))))
1894 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1896 // This is going to flag a syntax error, we
1897 // know the predicate to be false.
1898 MYREPARSE (@3, $1, SCM_ARG, $3);
1900 | EXPECT_SCM function_arglist_optional UNSIGNED
1903 if (scm_is_true (scm_call_1 ($1, $3)))
1904 MYREPARSE (@3, $1, REAL, $3);
1906 SCM d = make_duration ($3);
1907 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
1908 MYREPARSE (@3, $1, REAL, $3);
1910 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
1913 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
1916 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
1918 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
1921 SCM n = scm_difference ($4, SCM_UNDEFINED);
1922 if (scm_is_true (scm_call_1 ($1, n)))
1923 MYREPARSE (@4, $1, REAL, n);
1925 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1926 t->set_property ("digit", $4);
1927 SCM m = t->unprotect ();
1928 if (scm_is_true (scm_call_1 ($1, m)))
1929 MYREPARSE (@4, $1, SCM_ARG, m);
1931 MYREPARSE (@4, $1, SCM_ARG, $4);
1935 | EXPECT_SCM function_arglist_optional '-' REAL
1938 SCM n = scm_difference ($4, SCM_UNDEFINED);
1939 MYREPARSE (@4, $1, REAL, n);
1943 function_arglist_closed:
1944 function_arglist_closed_nonbackup
1945 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1947 $$ = scm_cons (loc_on_music (@4, $1), $3);
1951 function_arglist_closed_common:
1952 EXPECT_NO_MORE_ARGS {
1955 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1957 $$ = check_scheme_arg (parser, @3,
1960 | EXPECT_SCM function_arglist_optional bare_number_common_closed
1962 $$ = check_scheme_arg (parser, @3,
1965 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1967 $$ = check_scheme_arg (parser, @3,
1968 scm_difference ($4, SCM_UNDEFINED),
1971 | EXPECT_SCM function_arglist_optional post_event_nofinger
1973 $$ = check_scheme_arg (parser, @3,
1976 | function_arglist_common_reparse REPARSE SCM_ARG
1978 $$ = check_scheme_arg (parser, @3,
1981 | function_arglist_common_reparse REPARSE bare_number_common_closed
1983 $$ = check_scheme_arg (parser, @3,
1986 | function_arglist_common_reparse REPARSE symbol_list_arg
1988 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1992 function_arglist_optional:
1993 function_arglist_backup
1994 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
1996 $$ = scm_cons (loc_on_music (@4, $1), $3);
1998 | function_arglist_skip_backup BACKUP
2001 function_arglist_skip_backup:
2002 function_arglist_backup
2003 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2005 $$ = scm_cons (loc_on_music (@3, $1), $3);
2009 embedded_scm_closed:
2011 | scm_function_call_closed
2014 embedded_scm_arg_closed:
2015 embedded_scm_bare_arg
2016 | scm_function_call_closed
2020 scm_function_call_closed:
2021 SCM_FUNCTION function_arglist_closed {
2022 $$ = MAKE_SYNTAX ("music-function", @$,
2027 music_function_call:
2028 MUSIC_FUNCTION function_arglist {
2029 $$ = MAKE_SYNTAX ("music-function", @$,
2036 /**/ { $$ = SCM_EOL; }
2037 | '=' simple_string {
2044 | repeated_music { $$ = $1; }
2045 | re_rhythmed_music { $$ = $1; }
2046 | complex_music_prefix music
2048 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2052 complex_music_prefix:
2053 CONTEXT symbol optional_id optional_context_mod {
2054 Context_mod *ctxmod = unsmob_context_mod ($4);
2057 mods = ctxmod->get_mods ();
2058 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2060 | NEWCONTEXT symbol optional_id optional_context_mod {
2061 Context_mod *ctxmod = unsmob_context_mod ($4);
2064 mods = ctxmod->get_mods ();
2065 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2070 mode_changing_head grouped_music_list {
2071 if ($1 == ly_symbol2scm ("chords"))
2073 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2079 parser->lexer_->pop_state ();
2081 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2082 Context_mod *ctxmod = unsmob_context_mod ($2);
2085 mods = ctxmod->get_mods ();
2086 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2087 if ($1 == ly_symbol2scm ("ChordNames"))
2089 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2091 parser->lexer_->pop_state ();
2097 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2098 parser->lexer_->push_note_state (nn);
2100 $$ = ly_symbol2scm ("notes");
2104 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2105 parser->lexer_->push_note_state (nn);
2107 $$ = ly_symbol2scm ("drums");
2110 parser->lexer_->push_figuredbass_state ();
2112 $$ = ly_symbol2scm ("figures");
2115 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2116 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2117 nn = parser->lexer_->lookup_identifier ("pitchnames");
2118 parser->lexer_->push_chord_state (nn);
2119 $$ = ly_symbol2scm ("chords");
2123 { parser->lexer_->push_lyric_state ();
2124 $$ = ly_symbol2scm ("lyrics");
2128 mode_changing_head_with_context:
2130 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2131 parser->lexer_->push_note_state (nn);
2133 $$ = ly_symbol2scm ("DrumStaff");
2136 parser->lexer_->push_figuredbass_state ();
2138 $$ = ly_symbol2scm ("FiguredBass");
2141 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2142 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2143 nn = parser->lexer_->lookup_identifier ("pitchnames");
2144 parser->lexer_->push_chord_state (nn);
2145 $$ = ly_symbol2scm ("ChordNames");
2148 { parser->lexer_->push_lyric_state ();
2149 $$ = ly_symbol2scm ("Lyrics");
2154 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2157 /* Can also use music at the expensive of two S/Rs similar to
2158 \repeat \alternative */
2159 parser->lexer_->pop_state ();
2161 $$ = scm_cons ($3, SCM_EOL);
2163 | new_lyrics ADDLYRICS {
2164 parser->lexer_->push_lyric_state ();
2166 parser->lexer_->pop_state ();
2167 $$ = scm_cons ($4, $1);
2172 composite_music new_lyrics {
2173 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2175 | LYRICSTO simple_string {
2176 parser->lexer_->push_lyric_state ();
2178 parser->lexer_->pop_state ();
2179 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2184 CHANGE STRING '=' STRING {
2185 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
2192 $$ = scm_reverse_x ($1, SCM_EOL);
2194 | symbol_list_rev property_path {
2195 $$ = scm_reverse_x ($1, $2);
2201 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2204 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2206 | OVERRIDE property_path '=' scalar {
2207 if (scm_ilength ($2) < 2) {
2208 parser->parser_error (@2, _("bad grob property path"));
2211 $$ = scm_cons (ly_symbol2scm ("push"),
2212 scm_cons2 (scm_car ($2),
2217 | REVERT revert_arg {
2218 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2222 // This is all quite awkward for the sake of substantial backward
2223 // compatibility while at the same time allowing a more "natural" form
2224 // of specification not separating grob specification from grob
2225 // property path. The purpose of this definition of revert_arg is to
2226 // allow the symbol list which specifies grob and property to revert
2227 // to be optionally be split into two parts after the grob (which in
2228 // this case is just the first element of the list). symbol_list_part
2229 // is only one path component, but it can be parsed without lookahead,
2230 // so we can follow it with a synthetic BACKUP token when needed. If
2231 // the first symbol_list_part already contains multiple elements (only
2232 // possible if a Scheme expression provides them), we just parse for
2233 // additional elements introduced by '.', which is what the
2234 // SYMBOL_LIST backup in connection with the immediately following
2235 // rule using symbol_list_arg does.
2237 // As long as we don't have our coffers filled with both grob and at
2238 // least one grob property specification, the rest of the required
2239 // symbol list chain may be provided either with or without a leading
2240 // dot. This is for both allowing the traditional
2241 // \revert Accidental #'color
2242 // as well as well as the "naive" form
2243 // \revert Accidental.color
2246 revert_arg_backup BACKUP symbol_list_arg
2255 if (scm_is_null ($1)
2256 || scm_is_null (scm_cdr ($1)))
2257 MYBACKUP (SCM_ARG, $1, @1);
2259 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2263 // revert_arg_part delivers results in reverse
2266 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2268 $$ = scm_append_x (scm_list_2 ($5, $3));
2270 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2272 $$ = scm_append_x (scm_list_2 ($4, $3));
2277 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2278 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2280 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2281 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2282 | DENIES { $$ = ly_symbol2scm ("denies"); }
2284 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2285 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2286 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2287 | NAME { $$ = ly_symbol2scm ("context-name"); }
2291 property_operation { $$ = $1; }
2292 | context_def_mod STRING {
2293 $$ = scm_list_2 ($1, $2);
2295 | context_def_mod embedded_scm
2297 if (!scm_is_string ($2)
2298 && ly_symbol2scm ("consists") != $1
2299 && ly_symbol2scm ("remove") != $1)
2302 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2306 $$ = scm_list_2 ($1, $2);
2311 // If defined, at least two members.
2315 SCM l = scm_reverse_x ($1, SCM_EOL);
2318 (scm_object_property (scm_car (l),
2319 ly_symbol2scm ("is-grob?"))))
2320 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2321 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2322 parser->parser_error (@1, _ ("bad grob property path"));
2329 // If defined, at least three members
2333 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2335 parser->parser_error (@1, _ ("bad grob property path"));
2339 | grob_prop_spec property_path
2341 if (!SCM_UNBNDP ($1)) {
2342 $$ = scm_append_x (scm_list_2 ($1, $2));
2343 if (scm_is_null (scm_cddr ($$))) {
2344 parser->parser_error (@$, _ ("bad grob property path"));
2352 // Exactly two elements or undefined
2356 SCM l = scm_reverse_x ($1, SCM_EOL);
2357 switch (scm_ilength (l)) {
2359 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2363 parser->parser_error (@1, _ ("bad context property path"));
2370 simple_music_property_def:
2371 OVERRIDE grob_prop_path '=' scalar {
2372 if (SCM_UNBNDP ($2))
2375 $$ = scm_list_5 (scm_car ($2),
2376 ly_symbol2scm ("OverrideProperty"),
2382 | REVERT simple_revert_context revert_arg {
2383 $$ = scm_list_4 ($2,
2384 ly_symbol2scm ("RevertProperty"),
2388 | SET context_prop_spec '=' scalar {
2389 if (SCM_UNBNDP ($2))
2392 $$ = scm_list_4 (scm_car ($2),
2393 ly_symbol2scm ("PropertySet"),
2397 | UNSET context_prop_spec {
2398 if (SCM_UNBNDP ($2))
2401 $$ = scm_list_3 (scm_car ($2),
2402 ly_symbol2scm ("PropertyUnset"),
2408 // This is all quite awkward for the sake of substantial backward
2409 // compatibility while at the same time allowing a more "natural" form
2410 // of specification not separating grob specification from grob
2411 // property path. The purpose of this definition of
2412 // simple_revert_context is to allow the symbol list which specifies
2413 // grob and property to revert to be optionally be split into two
2414 // parts after the grob (which may be preceded by a context
2415 // specification, a case which we distinguish by checking whether the
2416 // first symbol is a valid grob symbol instead).
2418 // See revert_arg above for the main work horse of this arrangement.
2419 // simple_revert_context just caters for the context and delegates the
2420 // rest of the job to revert_arg.
2422 simple_revert_context:
2425 $1 = scm_reverse_x ($1, SCM_EOL);
2426 if (scm_is_null ($1)
2428 (scm_object_property (scm_car ($1),
2429 ly_symbol2scm ("is-grob?")))) {
2430 $$ = ly_symbol2scm ("Bottom");
2431 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2434 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2441 simple_music_property_def {
2442 if (SCM_UNBNDP ($1))
2443 $$ = MAKE_SYNTAX ("void-music", @1);
2445 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2456 simple_string: STRING {
2461 if (scm_is_string ($1)) {
2464 parser->parser_error (@1, (_ ("simple string expected")));
2465 $$ = scm_string (SCM_EOL);
2472 $$ = scm_string_to_symbol ($1);
2476 // This is a bit of overkill but makes the same
2477 // routine responsible for all symbol interpretations.
2478 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2480 if (SCM_UNBNDP ($$))
2482 parser->parser_error (@1, (_ ("symbol expected")));
2483 // Generate a unique symbol in case it is used
2484 // for an assignment or similar
2485 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2494 // The following is a rather defensive variant of admitting
2495 // negative numbers: the grammar would permit number_factor or
2496 // even number_expression. However, function arguments allow
2497 // only this simple kind of negative number, so to have things
2498 // like \tweak and \override behave reasonably similar, it
2499 // makes sense to rule out things like -- which are rather an
2500 // accent in function argument contexts.
2503 $$ = scm_difference ($2, SCM_UNDEFINED);
2510 simple_element post_events {
2511 // Let the rhythmic music iterator sort this mess out.
2512 if (scm_is_pair ($2)) {
2513 $$ = make_music_from_simple (parser, @1, $1);
2514 if (unsmob_music ($$))
2515 unsmob_music ($$)->set_property ("articulations",
2516 scm_reverse_x ($2, SCM_EOL));
2519 parser->parser_error (@1, _("music expected"));
2520 $$ = MAKE_SYNTAX ("void-music", @1);
2524 | simple_chord_elements post_events {
2525 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2528 /* why is this giving wrong start location? -ns
2530 i.set_location (@1, @2);
2531 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2533 | CHORD_REPETITION optional_notemode_duration post_events {
2535 i.set_location (@1, @3);
2536 $$ = MAKE_SYNTAX ("repetition-chord", i,
2537 $2, scm_reverse_x ($3, SCM_EOL));
2539 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2541 i.set_location (@1, @3);
2542 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2543 scm_reverse_x ($3, SCM_EOL));
2546 | note_chord_element
2551 chord_body optional_notemode_duration post_events
2553 Music *m = unsmob_music ($1);
2554 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2555 SCM es = m->get_property ("elements");
2556 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2558 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2559 unsmob_music (scm_car (s))->set_property ("duration", dur);
2560 es = ly_append2 (es, postevs);
2562 m-> set_property ("elements", es);
2564 $$ = m->self_scm ();
2569 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2571 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2573 | CHORD_BODY_IDENTIFIER
2576 chord_body_elements:
2577 /* empty */ { $$ = SCM_EOL; }
2578 | chord_body_elements chord_body_element {
2579 if (!SCM_UNBNDP ($2))
2580 $$ = scm_cons ($2, $1);
2585 pitch exclamations questions octave_check post_events
2587 bool q = to_boolean ($3);
2588 bool ex = to_boolean ($2);
2592 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2593 n->set_property ("pitch", $1);
2595 n->set_property ("cautionary", SCM_BOOL_T);
2597 n->set_property ("force-accidental", SCM_BOOL_T);
2599 if (scm_is_pair (post)) {
2600 SCM arts = scm_reverse_x (post, SCM_EOL);
2601 n->set_property ("articulations", arts);
2603 if (scm_is_number (check))
2605 int q = scm_to_int (check);
2606 n->set_property ("absolute-octave", scm_from_int (q-1));
2609 $$ = n->unprotect ();
2611 | DRUM_PITCH post_events {
2612 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2613 n->set_property ("drum-type", $1);
2615 if (scm_is_pair ($2)) {
2616 SCM arts = scm_reverse_x ($2, SCM_EOL);
2617 n->set_property ("articulations", arts);
2619 $$ = n->unprotect ();
2621 | music_function_chord_body
2623 Music *m = unsmob_music ($1);
2625 while (m && m->is_mus_type ("music-wrapper-music")) {
2626 $$ = m->get_property ("element");
2627 m = unsmob_music ($$);
2630 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2631 parser->parser_error (@$, _ ("not a rhythmic event"));
2637 music_function_chord_body:
2642 // Event functions may only take closed arglists, otherwise it would
2643 // not be clear whether a following postevent should be associated
2644 // with the last argument of the event function or with the expression
2645 // for which the function call acts itself as event.
2647 music_function_call_closed:
2648 MUSIC_FUNCTION function_arglist_closed {
2649 $$ = MAKE_SYNTAX ("music-function", @$,
2654 event_function_event:
2655 EVENT_FUNCTION function_arglist_closed {
2656 $$ = MAKE_SYNTAX ("music-function", @$,
2678 | post_events post_event {
2680 if (Music *m = unsmob_music ($2))
2682 if (m->is_mus_type ("post-event-wrapper"))
2684 for (SCM p = m->get_property ("elements");
2688 $$ = scm_cons (scm_car (p), $$);
2692 $$ = scm_cons ($2, $$);
2698 post_event_nofinger:
2699 direction_less_event {
2702 | script_dir music_function_call_closed {
2704 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2705 parser->parser_error (@2, _ ("post-event expected"));
2706 $$ = SCM_UNSPECIFIED;
2707 } else if (!SCM_UNBNDP ($1))
2709 unsmob_music ($$)->set_property ("direction", $1);
2713 if (!parser->lexer_->is_lyric_state ())
2714 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2715 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2718 if (!parser->lexer_->is_lyric_state ())
2719 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2720 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2722 | script_dir direction_reqd_event {
2723 if (!SCM_UNBNDP ($1))
2725 Music *m = unsmob_music ($2);
2726 m->set_property ("direction", $1);
2730 | script_dir direction_less_event {
2731 if (!SCM_UNBNDP ($1))
2733 Music *m = unsmob_music ($2);
2734 m->set_property ("direction", $1);
2741 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2746 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2757 string_number_event:
2759 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2760 s->set_property ("string-number", $1);
2761 $$ = s->unprotect ();
2765 direction_less_event:
2767 | EVENT_IDENTIFIER {
2771 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2772 a->set_property ("tremolo-type", $1);
2773 $$ = a->unprotect ();
2775 | event_function_event
2778 direction_reqd_event:
2782 | script_abbreviation {
2783 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2784 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2785 if (scm_is_string (s))
2786 a->set_property ("articulation-type", s);
2787 else parser->parser_error (@1, _ ("expecting string as script definition"));
2788 $$ = a->unprotect ();
2793 /**/ { $$ = SCM_EOL; }
2794 | '=' quotes { $$ = $2; }
2808 $$ = scm_from_int (1);
2811 $$ = scm_oneplus ($1);
2817 $$ = scm_from_int (-1);
2820 $$ = scm_oneminus ($1);
2825 NOTENAME_PITCH quotes {
2826 if (!scm_is_eq (SCM_INUM0, $2))
2828 Pitch p = *unsmob_pitch ($1);
2829 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2830 $$ = p.smobbed_copy ();
2840 TONICNAME_PITCH quotes {
2841 if (!scm_is_eq (SCM_INUM0, $2))
2843 Pitch p = *unsmob_pitch ($1);
2844 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2845 $$ = p.smobbed_copy ();
2857 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2858 t->set_property ("text", $1);
2859 $$ = t->unprotect ();
2862 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2863 t->set_property ("text",
2864 make_simple_markup ($1));
2865 $$ = t->unprotect ();
2867 | embedded_scm_closed
2869 Music *m = unsmob_music ($1);
2870 if (m && m->is_mus_type ("post-event"))
2872 else if (Text_interface::is_markup ($1)) {
2873 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2874 t->set_property ("text", $1);
2875 $$ = t->unprotect ();
2877 parser->parser_error (@1, _ ("not an articulation"));
2883 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2884 t->set_property ("digit", $1);
2885 $$ = t->unprotect ();
2889 script_abbreviation:
2891 $$ = scm_from_locale_string ("Hat");
2894 $$ = scm_from_locale_string ("Plus");
2897 $$ = scm_from_locale_string ("Dash");
2900 $$ = scm_from_locale_string ("Bang");
2903 $$ = scm_from_locale_string ("Larger");
2906 $$ = scm_from_locale_string ("Dot");
2909 $$ = scm_from_locale_string ("Underscore");
2914 '_' { $$ = scm_from_int (DOWN); }
2915 | '^' { $$ = scm_from_int (UP); }
2916 | '-' { $$ = SCM_UNDEFINED; }
2920 multiplied_duration {
2925 maybe_notemode_duration:
2929 | multiplied_duration {
2931 parser->default_duration_ = *unsmob_duration ($$);
2936 optional_notemode_duration:
2937 maybe_notemode_duration
2939 if (SCM_UNBNDP ($$))
2940 $$ = parser->default_duration_.smobbed_copy ();
2946 $$ = make_duration ($1, scm_to_int ($2));
2947 if (SCM_UNBNDP ($$))
2949 parser->parser_error (@1, _ ("not a duration"));
2950 $$ = Duration ().smobbed_copy ();
2953 | DURATION_IDENTIFIER dots {
2954 Duration *d = unsmob_duration ($1);
2955 Duration k (d->duration_log (),
2956 d->dot_count () + scm_to_int ($2));
2957 k = k.compressed (d->factor ());
2958 scm_remember_upto_here_1 ($1);
2959 $$ = k.smobbed_copy ();
2963 multiplied_duration:
2967 | multiplied_duration '*' UNSIGNED {
2968 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2970 | multiplied_duration '*' FRACTION {
2971 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2973 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2982 $$ = scm_oneplus ($1);
2991 if (SCM_UNBNDP (make_duration ($2)))
2992 parser->parser_error (@2, _ ("not a duration"));
2998 UNSIGNED { $$ = $1; }
2999 | STRING { $$ = $1; }
3000 | full_markup { $$ = $1; }
3003 // as an integer, it needs to be non-negative, and otherwise
3004 // it needs to be suitable as a markup.
3005 if (scm_is_integer ($1)
3006 ? scm_is_true (scm_negative_p ($1))
3007 : !Text_interface::is_markup ($1))
3009 parser->parser_error (@1, _ ("bass number expected"));
3015 figured_bass_alteration:
3016 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3017 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3018 | '!' { $$ = scm_from_int (0); }
3023 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3024 $$ = bfr->unprotect ();
3027 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3028 $$ = bfr->self_scm ();
3030 if (scm_is_number ($1))
3031 bfr->set_property ("figure", $1);
3032 else if (Text_interface::is_markup ($1))
3033 bfr->set_property ("text", $1);
3039 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3041 | bass_figure figured_bass_alteration {
3042 Music *m = unsmob_music ($1);
3043 if (scm_to_double ($2)) {
3044 SCM salter = m->get_property ("alteration");
3045 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3046 m->set_property ("alteration",
3047 scm_sum (alter, $2));
3049 m->set_property ("alteration", scm_from_int (0));
3052 | bass_figure figured_bass_modification {
3053 Music *m = unsmob_music ($1);
3054 m->set_property ($2, SCM_BOOL_T);
3059 figured_bass_modification:
3061 $$ = ly_symbol2scm ("augmented");
3064 $$ = ly_symbol2scm ("no-continuation");
3067 $$ = ly_symbol2scm ("diminished");
3070 $$ = ly_symbol2scm ("augmented-slash");
3080 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3088 | figure_list br_bass_figure {
3089 $$ = scm_cons ($2, $1);
3094 FIGURE_OPEN figure_list FIGURE_CLOSE {
3095 $$ = scm_reverse_x ($2, SCM_EOL);
3101 /**/ { $$ = SCM_BOOL_F; }
3102 | REST { $$ = SCM_BOOL_T; }
3106 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3107 if (!parser->lexer_->is_note_state ())
3108 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3109 if (!SCM_UNBNDP ($2)
3111 || scm_is_number ($4)
3113 || scm_is_true ($6))
3116 if (scm_is_true ($6))
3117 n = MY_MAKE_MUSIC ("RestEvent", @$);
3119 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3121 n->set_property ("pitch", $1);
3122 if (SCM_UNBNDP ($5))
3123 n->set_property ("duration",
3124 parser->default_duration_.smobbed_copy ());
3126 n->set_property ("duration", $5);
3128 if (scm_is_number ($4))
3130 int q = scm_to_int ($4);
3131 n->set_property ("absolute-octave", scm_from_int (q-1));
3134 if (to_boolean ($3))
3135 n->set_property ("cautionary", SCM_BOOL_T);
3136 if (to_boolean ($2) || to_boolean ($3))
3137 n->set_property ("force-accidental", SCM_BOOL_T);
3139 $$ = n->unprotect ();
3142 | DRUM_PITCH optional_notemode_duration {
3143 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3144 n->set_property ("duration", $2);
3145 n->set_property ("drum-type", $1);
3147 $$ = n->unprotect ();
3149 | RESTNAME optional_notemode_duration {
3151 if (ly_scm2string ($1) == "s") {
3153 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3156 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3159 ev->set_property ("duration", $2);
3160 $$ = ev->unprotect ();
3164 simple_chord_elements:
3166 if (!parser->lexer_->is_chord_state ())
3167 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3170 | figure_spec optional_notemode_duration {
3171 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3173 unsmob_music (scm_car (s))->set_property ("duration", $2);
3181 if (!parser->lexer_->is_lyric_state ())
3182 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3186 if (!parser->lexer_->is_lyric_state ())
3187 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3193 lyric_element_music:
3194 lyric_element optional_notemode_duration post_events {
3195 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3196 if (scm_is_pair ($3))
3197 unsmob_music ($$)->set_property
3198 ("articulations", scm_reverse_x ($3, SCM_EOL));
3203 steno_tonic_pitch optional_notemode_duration {
3204 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3206 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3207 SCM its = scm_reverse_x ($4, SCM_EOL);
3208 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3216 | chord_items chord_item {
3217 $$ = scm_cons ($2, $$);
3223 $$ = ly_symbol2scm ("chord-colon");
3226 $$ = ly_symbol2scm ("chord-caret");
3228 | CHORD_SLASH steno_tonic_pitch {
3229 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3231 | CHORD_BASS steno_tonic_pitch {
3232 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3241 $$ = scm_reverse_x ($1, SCM_EOL);
3249 step_number { $$ = scm_cons ($1, SCM_EOL); }
3250 | step_numbers '.' step_number {
3251 $$ = scm_cons ($3, $$);
3257 $$ = make_chord_step ($1, 0);
3260 $$ = make_chord_step ($1, SHARP_ALTERATION);
3262 | UNSIGNED CHORD_MINUS {
3263 $$ = make_chord_step ($1, FLAT_ALTERATION);
3271 | UNSIGNED '-' UNSIGNED {
3272 $$ = scm_cons ($1, $3);
3279 TODO: should deprecate in favor of Scheme?
3283 number_expression '+' number_term {
3284 $$ = scm_sum ($1, $3);
3286 | number_expression '-' number_term {
3287 $$ = scm_difference ($1, $3);
3296 | number_factor '*' number_factor {
3297 $$ = scm_product ($1, $3);
3299 | number_factor '/' number_factor {
3300 $$ = scm_divide ($1, $3);
3305 '-' number_factor { /* %prec UNARY_MINUS */
3306 $$ = scm_difference ($2, SCM_UNDEFINED);
3312 bare_number_common_closed
3313 | REAL NUMBER_IDENTIFIER
3315 $$ = scm_product ($1, $2);
3319 bare_number_common_closed:
3327 | UNSIGNED NUMBER_IDENTIFIER {
3328 $$ = scm_product ($1, $2);
3334 | bare_number_common_closed
3343 { $$ = SCM_UNDEFINED; }
3346 if (SCM_UNBNDP ($1))
3354 { $$ = SCM_UNDEFINED; }
3357 if (SCM_UNBNDP ($1))
3366 { parser->lexer_->push_markup_state (); }
3369 parser->lexer_->pop_state ();
3375 { parser->lexer_->push_markup_state (); }
3378 parser->lexer_->pop_state ();
3384 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3386 | markup_head_1_list simple_markup
3388 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3389 @2, $1, scm_list_1 ($2)));
3399 if (Text_interface::is_markup ($1))
3400 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3401 else if (Text_interface::is_markup_list ($1))
3402 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3404 parser->parser_error (@1, _ ("not a markup"));
3405 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3412 markup_composed_list {
3415 | markup_uncomposed_list
3418 markup_uncomposed_list:
3419 markup_braced_list {
3422 | markup_command_list {
3423 $$ = scm_list_1 ($1);
3425 | markup_scm MARKUPLIST_IDENTIFIER
3430 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3431 parser->lexer_->push_note_state (nn);
3432 } '{' score_body '}' {
3433 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3434 parser->lexer_->pop_state ();
3438 markup_composed_list:
3439 markup_head_1_list markup_uncomposed_list {
3440 $$ = MAKE_SYNTAX ("composed-markup-list",
3446 '{' markup_braced_list_body '}' {
3447 $$ = scm_reverse_x ($2, SCM_EOL);
3451 markup_braced_list_body:
3452 /* empty */ { $$ = SCM_EOL; }
3453 | markup_braced_list_body markup {
3454 $$ = scm_cons ($2, $1);
3456 | markup_braced_list_body markup_list {
3457 $$ = scm_reverse_x ($2, $1);
3461 markup_command_list:
3462 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3463 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3467 markup_command_basic_arguments:
3468 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3469 $$ = scm_cons ($3, $2);
3471 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3472 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3474 | EXPECT_NO_MORE_ARGS {
3479 markup_command_list_arguments:
3480 markup_command_basic_arguments { $$ = $1; }
3481 | EXPECT_MARKUP markup_command_list_arguments markup {
3482 $$ = scm_cons ($3, $2);
3487 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3488 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3493 markup_head_1_item {
3494 $$ = scm_list_1 ($1);
3496 | markup_head_1_list markup_head_1_item {
3497 $$ = scm_cons ($2, $1);
3503 $$ = make_simple_markup ($1);
3506 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3507 parser->lexer_->push_note_state (nn);
3508 } '{' score_body '}' {
3509 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3510 parser->lexer_->pop_state ();
3512 | MARKUP_FUNCTION markup_command_basic_arguments {
3513 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3515 | markup_scm MARKUP_IDENTIFIER
3522 markup_head_1_list simple_markup
3524 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3525 @2, $1, scm_list_1 ($2)));
3535 Lily_parser::set_yydebug (bool x)
3541 Lily_parser::do_yyparse ()
3543 SCM retval = SCM_UNDEFINED;
3544 yyparse (this, &retval);
3554 It is a little strange to have this function in this file, but
3555 otherwise, we have to import music classes into the lexer.
3559 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3561 if (unsmob_book (sid)) {
3562 Book *book = unsmob_book (sid)->clone ();
3563 *destination = book->self_scm ();
3566 return BOOK_IDENTIFIER;
3567 } else if (scm_is_number (sid)) {
3569 return NUMBER_IDENTIFIER;
3570 } else if (unsmob_context_def (sid)) {
3571 Context_def *def= unsmob_context_def (sid)->clone ();
3573 *destination = def->self_scm ();
3576 return CONTEXT_DEF_IDENTIFIER;
3577 } else if (unsmob_context_mod (sid)) {
3578 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3580 return CONTEXT_MOD_IDENTIFIER;
3581 } else if (Music *mus = unsmob_music (sid)) {
3582 mus = mus->clone ();
3583 *destination = mus->self_scm ();
3584 bool is_event = mus->is_mus_type ("post-event");
3586 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3587 } else if (unsmob_pitch (sid)) {
3588 *destination = unsmob_pitch (sid)->smobbed_copy ();
3589 return PITCH_IDENTIFIER;
3590 } else if (unsmob_duration (sid)) {
3591 *destination = unsmob_duration (sid)->smobbed_copy ();
3592 return DURATION_IDENTIFIER;
3593 } else if (unsmob_output_def (sid)) {
3594 Output_def *p = unsmob_output_def (sid);
3597 *destination = p->self_scm ();
3599 return OUTPUT_DEF_IDENTIFIER;
3606 get_next_unique_context_id ()
3608 return scm_from_locale_string ("$uniqueContextId");
3613 get_next_unique_lyrics_context_id ()
3615 static int new_context_count;
3617 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3618 return scm_from_locale_string (s);
3621 // check_scheme_arg checks one argument with a given predicate for use
3622 // in an argument list and throws a syntax error if it is unusable.
3623 // The argument is prepended to the argument list in any case. After
3624 // throwing a syntax error, the argument list is terminated with #f as
3625 // its last cdr in order to mark it as uncallable while not losing
3626 // track of its total length.
3628 // There are a few special considerations: if optional argument disp
3629 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3630 // instead of arg in a prospective error message. This is useful if
3631 // arg is not the actual argument but rather a transformation of it.
3633 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3634 // and an error message using disp is produced unconditionally.
3636 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3637 SCM arg, SCM args, SCM pred, SCM disp)
3639 if (SCM_UNBNDP (arg))
3640 args = scm_cons (disp, args);
3642 args = scm_cons (arg, args);
3643 if (scm_is_true (scm_call_1 (pred, arg)))
3646 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3647 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3648 SCM_UNBNDP (disp) ? arg : disp);
3649 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3653 SCM loc_on_music (Input loc, SCM arg)
3655 if (Music *m = unsmob_music (arg))
3659 return m->unprotect ();
3665 try_string_variants (SCM pred, SCM str)
3667 // a matching predicate is always ok
3668 if (scm_is_true (scm_call_1 (pred, str)))
3670 // a symbol may be interpreted as a list of symbols if it helps
3671 if (scm_is_symbol (str)) {
3672 str = scm_list_1 (str);
3673 if (scm_is_true (scm_call_1 (pred, str)))
3675 return SCM_UNDEFINED;
3678 // If this cannot be a string representation of a symbol list,
3681 if (!is_regular_identifier (str, true))
3682 return SCM_UNDEFINED;
3684 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3685 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3686 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3688 // Let's attempt the symbol list interpretation first.
3690 if (scm_is_true (scm_call_1 (pred, str)))
3693 // If there is just one symbol in the list, we might interpret
3694 // it as a single symbol
3696 if (scm_is_null (scm_cdr (str)))
3698 str = scm_car (str);
3699 if (scm_is_true (scm_call_1 (pred, str)))
3703 return SCM_UNDEFINED;
3707 is_regular_identifier (SCM id, bool multiple)
3709 if (!scm_is_string (id))
3712 string str = ly_scm2string (id);
3714 bool middle = false;
3716 for (string::iterator it=str.begin(); it != str.end (); it++)
3719 if ((c >= 'a' && c <= 'z')
3720 || (c >= 'A' && c <= 'Z')
3723 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3732 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3734 if (unsmob_music (simple))
3736 if (parser->lexer_->is_note_state ()) {
3737 if (scm_is_symbol (simple)) {
3738 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3739 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3740 n->set_property ("drum-type", simple);
3741 return n->unprotect ();
3743 if (unsmob_pitch (simple)) {
3744 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3745 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3746 n->set_property ("pitch", simple);
3747 return n->unprotect ();
3750 } else if (parser->lexer_->is_lyric_state ()) {
3751 if (Text_interface::is_markup (simple))
3752 return MAKE_SYNTAX ("lyric-event", loc, simple,
3753 parser->default_duration_.smobbed_copy ());
3754 } else if (parser->lexer_->is_chord_state ()) {
3755 if (unsmob_pitch (simple))
3756 return make_chord_elements (loc, simple,
3757 parser->default_duration_.smobbed_copy (),
3764 make_music_with_input (SCM name, Input where)
3766 Music *m = make_music_by_name (name);
3767 m->set_spot (where);
3772 make_simple_markup (SCM a)
3778 make_duration (SCM d, int dots)
3780 int t = scm_to_int (d);
3781 if (t > 0 && (t & (t-1)) == 0)
3782 return Duration (intlog2 (t), dots).smobbed_copy ();
3784 return SCM_UNDEFINED;
3788 make_chord_step (SCM step_scm, Rational alter)
3790 int step = scm_to_int (step_scm);
3793 alter += FLAT_ALTERATION;
3797 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3798 return m.smobbed_copy ();
3803 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3805 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3806 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3807 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3809 unsmob_music (scm_car (s))->set_spot (loc);
3815 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3817 Lily_lexer *lex = parser->lexer_;
3821 lex->prepare_for_next_token ();
3822 return lex->yylex ();