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. */
68 /* The above precedences tackle the shift/reduce problem
71 \repeat .. \alternative
73 \repeat { \repeat .. \alternative }
77 \repeat { \repeat } \alternative
83 %right ':' UNSIGNED REAL E_UNSIGNED EVENT_IDENTIFIER EVENT_FUNCTION '^' '_'
84 HYPHEN EXTENDER DURATION_IDENTIFIER '!'
86 /* The above are needed for collecting tremoli and other items (that
87 could otherwise be interpreted as belonging to the next function
88 argument) greedily, and together with the next rule will serve to
89 join numbers and units greedily instead of allowing them into
90 separate function arguments
93 %nonassoc NUMBER_IDENTIFIER
105 %{ // -*-Fundamental-*-
110 * The rules for who is protecting what are very shady. Uniformise
113 * There are too many lexical modes?
124 #include "context-def.hh"
125 #include "context-mod.hh"
126 #include "dimensions.hh"
127 #include "file-path.hh"
129 #include "international.hh"
130 #include "lily-guile.hh"
131 #include "lily-lexer.hh"
132 #include "lily-parser.hh"
136 #include "output-def.hh"
137 #include "paper-book.hh"
138 #include "scm-hash.hh"
140 #include "text-interface.hh"
144 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
146 parser->parser_error (*i, s);
149 // The following are somewhat precarious constructs as they may change
150 // the value of the lookahead token. That implies that the lookahead
151 // token must not yet have made an impact on the state stack other
152 // than causing the reduction of the current rule, or switching the
153 // lookahead token while Bison is mulling it over will cause trouble.
155 #define MYBACKUP(Token, Value, Location) \
157 if (yychar != YYEMPTY) \
158 parser->lexer_->push_extra_token \
159 (yylloc, yychar, yylval); \
161 parser->lexer_->push_extra_token \
162 (Location, Token, Value); \
163 parser->lexer_->push_extra_token (Location, BACKUP); \
168 #define MYREPARSE(Location, Pred, Token, Value) \
170 if (yychar != YYEMPTY) \
171 parser->lexer_->push_extra_token \
172 (yylloc, yychar, yylval); \
173 parser->lexer_->push_extra_token \
174 (Location, Token, Value); \
175 parser->lexer_->push_extra_token \
176 (Location, REPARSE, Pred); \
185 #define MY_MAKE_MUSIC(x, spot) \
186 make_music_with_input (ly_symbol2scm (x), \
187 parser->lexer_->override_input (spot))
190 - Don't use lily module, create a new module instead.
191 - delay application of the function
193 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
194 scm_apply_0 (proc, args)
195 /* Syntactic Sugar. */
196 #define MAKE_SYNTAX(name, location, ...) \
197 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (parser->lexer_->override_input (location)), ##__VA_ARGS__, SCM_UNDEFINED))
198 #define START_MAKE_SYNTAX(name, ...) \
199 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
200 #define FINISH_MAKE_SYNTAX(start, location, ...) \
201 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (parser->lexer_->override_input (location)), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
203 SCM get_next_unique_context_id ();
204 SCM get_next_unique_lyrics_context_id ();
211 #define _(x) gettext (x)
215 static Music *make_music_with_input (SCM name, Input where);
216 SCM check_scheme_arg (Lily_parser *parser, Input loc,
217 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
218 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
219 SCM loc_on_music (Input loc, SCM arg);
220 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
221 SCM make_chord_step (SCM step, Rational alter);
222 SCM make_simple_markup (SCM a);
223 SCM make_duration (SCM t, int dots = 0);
224 bool is_regular_identifier (SCM id, bool multiple=false);
225 SCM try_string_variants (SCM pred, SCM str);
226 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
230 /* The third option is an alias that will be used to display the
231 syntax error. Bison CVS now correctly handles backslash escapes.
233 FIXME: Bison needs to translate some of these, eg, STRING.
237 /* Keyword tokens with plain escaped name. */
238 %token END_OF_FILE 0 "end of input"
239 %token ACCEPTS "\\accepts"
240 %token ADDLYRICS "\\addlyrics"
241 %token ALIAS "\\alias"
242 %token ALTERNATIVE "\\alternative"
244 %token BOOKPART "\\bookpart"
245 %token CHANGE "\\change"
246 %token CHORDMODE "\\chordmode"
247 %token CHORDS "\\chords"
248 %token CONSISTS "\\consists"
249 %token CONTEXT "\\context"
250 %token DEFAULT "\\default"
251 %token DEFAULTCHILD "\\defaultchild"
252 %token DENIES "\\denies"
253 %token DESCRIPTION "\\description"
254 %token DRUMMODE "\\drummode"
255 %token DRUMS "\\drums"
256 %token FIGUREMODE "\\figuremode"
257 %token FIGURES "\\figures"
258 %token HEADER "\\header"
259 %token INVALID "\\version-error"
260 %token LAYOUT "\\layout"
261 %token LYRICMODE "\\lyricmode"
262 %token LYRICS "\\lyrics"
263 %token LYRICSTO "\\lyricsto"
264 %token MARKUP "\\markup"
265 %token MARKUPLIST "\\markuplist"
268 %token NOTEMODE "\\notemode"
269 %token OVERRIDE "\\override"
270 %token PAPER "\\paper"
271 %token REMOVE "\\remove"
272 %token REPEAT "\\repeat"
274 %token REVERT "\\revert"
275 %token SCORE "\\score"
276 %token SCORELINES "\\score-lines"
277 %token SEQUENTIAL "\\sequential"
279 %token SIMULTANEOUS "\\simultaneous"
280 %token TEMPO "\\tempo"
282 %token UNSET "\\unset"
285 /* Keyword token exceptions. */
286 %token NEWCONTEXT "\\new"
289 /* Other string tokens. */
291 %token CHORD_BASS "/+"
292 %token CHORD_CARET "^"
293 %token CHORD_COLON ":"
294 %token CHORD_MINUS "-"
295 %token CHORD_SLASH "/"
296 %token ANGLE_OPEN "<"
297 %token ANGLE_CLOSE ">"
298 %token DOUBLE_ANGLE_OPEN "<<"
299 %token DOUBLE_ANGLE_CLOSE ">>"
300 %token E_BACKSLASH "\\"
301 %token E_EXCLAMATION "\\!"
306 If we give names, Bison complains.
308 %token FIGURE_CLOSE /* "\\>" */
309 %token FIGURE_OPEN /* "\\<" */
310 %token FIGURE_SPACE "_"
313 %token MULTI_MEASURE_REST
319 /* Artificial tokens, for more generic function syntax */
320 %token EXPECT_MARKUP "markup?"
321 %token EXPECT_SCM "scheme?"
322 %token BACKUP "(backed-up?)"
323 %token REPARSE "(reparsed?)"
324 %token EXPECT_MARKUP_LIST "markup-list?"
325 %token EXPECT_OPTIONAL "optional?"
326 /* After the last argument. */
327 %token EXPECT_NO_MORE_ARGS;
329 /* An artificial token for parsing embedded Lilypond */
330 %token EMBEDDED_LILY "#{"
332 %token BOOK_IDENTIFIER
333 %token CHORD_MODIFIER
334 %token CHORD_REPETITION
335 %token CONTEXT_DEF_IDENTIFIER
336 %token CONTEXT_MOD_IDENTIFIER
338 %token PITCH_IDENTIFIER
339 %token DURATION_IDENTIFIER
340 %token EVENT_IDENTIFIER
341 %token EVENT_FUNCTION
344 %token MARKUP_FUNCTION
345 %token MARKUP_LIST_FUNCTION
346 %token MARKUP_IDENTIFIER
347 %token MARKUPLIST_IDENTIFIER
348 %token MUSIC_FUNCTION
349 %token MUSIC_IDENTIFIER
350 %token NOTENAME_PITCH
351 %token NUMBER_IDENTIFIER
352 %token OUTPUT_DEF_IDENTIFIER
357 %token SCM_IDENTIFIER
361 %token TONICNAME_PITCH
365 /* We don't assign precedence to / and *, because we might need varied
366 prec levels in different prods */
375 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
376 parser->lexer_->push_note_state (nn);
377 } embedded_lilypond {
378 parser->lexer_->pop_state ();
383 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
384 | lilypond toplevel_expression {
386 | lilypond assignment {
389 parser->error_level_ = 1;
392 parser->error_level_ = 1;
399 parser->lexer_->add_scope (get_header (parser));
401 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
404 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
405 scm_call_2 (proc, parser->self_scm (), $1);
408 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
409 scm_call_2 (proc, parser->self_scm (), $1);
412 SCM proc = parser->lexer_->lookup_identifier
413 (unsmob_book($1)->paper_
414 ? "toplevel-book-handler"
415 : "toplevel-bookpart-handler");
416 scm_call_2 (proc, parser->self_scm (), $1);
419 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
420 scm_call_2 (proc, parser->self_scm (), $1);
423 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
424 scm_call_2 (proc, parser->self_scm (), $1);
427 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
428 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
431 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
432 scm_call_2 (proc, parser->self_scm (), $1);
435 // Evaluate and ignore #xxx, as opposed to \xxx
436 parser->lexer_->eval_scm_token ($1);
438 | embedded_scm_active
440 SCM out = SCM_UNDEFINED;
441 if (Text_interface::is_markup ($1))
442 out = scm_list_1 ($1);
443 else if (Text_interface::is_markup_list ($1))
445 if (scm_is_pair (out))
447 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
448 scm_call_2 (proc, parser->self_scm (), out);
449 } else if (unsmob_score ($1))
451 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
452 scm_call_2 (proc, parser->self_scm (), $1);
453 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
454 parser->parser_error (@1, _("bad expression type"));
458 Output_def * od = unsmob_output_def ($1);
460 if (od->c_variable ("is-paper") == SCM_BOOL_T)
461 id = ly_symbol2scm ("$defaultpaper");
462 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
463 id = ly_symbol2scm ("$defaultmidi");
464 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
465 id = ly_symbol2scm ("$defaultlayout");
467 parser->lexer_->set_identifier (id, $1);
474 $$ = parser->lexer_->eval_scm_token ($1);
484 embedded_scm_bare_arg:
488 $$ = parser->lexer_->eval_scm_token ($1);
492 | context_modification
494 | context_def_spec_block
500 /* The generic version may end in music, or not */
507 /* embedded_scm_arg is _not_ casting pitches to music by default, this
508 * has to be done by the function itself. Note that this may cause
509 * the results of scm_function_call or embedded_scm_bare_arg to be
510 * turned into music from pitches as well. Note that this creates a
511 * distinctly awkward situation for calculated drum pitches. Those
512 * are at the current point of time rejected as music constituents as
513 * they can't be distinguished from "proper" symbols.
517 embedded_scm_bare_arg
523 SCM_FUNCTION function_arglist {
524 $$ = MAKE_SYNTAX ("music-function", @$,
529 embedded_lilypond_number:
530 '-' embedded_lilypond_number
532 $$ = scm_difference ($2, SCM_UNDEFINED);
535 | UNSIGNED NUMBER_IDENTIFIER
537 $$ = scm_product ($1, $2);
544 // FIXME: @$ does not contain a useful source location
545 // for empty rules, and the only token in the whole
546 // production, EMBEDDED_LILY, is synthetic and also
547 // contains no source location.
548 $$ = MAKE_SYNTAX ("void-music", @$);
550 | identifier_init_nonumber
551 | embedded_lilypond_number
552 | post_event post_events
554 $$ = scm_reverse_x ($2, SCM_EOL);
555 if (Music *m = unsmob_music ($1))
557 if (m->is_mus_type ("post-event-wrapper"))
559 (scm_list_2 (m->get_property ("elements"),
562 $$ = scm_cons ($1, $$);
565 && scm_is_null (scm_cdr ($$)))
569 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
570 m->set_property ("elements", $$);
571 $$ = m->unprotect ();
574 | multiplied_duration
575 | music_embedded music_embedded music_list {
576 $3 = scm_reverse_x ($3, SCM_EOL);
577 if (unsmob_music ($2))
578 $3 = scm_cons ($2, $3);
579 if (unsmob_music ($1))
580 $3 = scm_cons ($1, $3);
581 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
584 parser->error_level_ = 1;
585 $$ = SCM_UNSPECIFIED;
587 | INVALID embedded_lilypond {
588 parser->error_level_ = 1;
594 lilypond_header_body:
595 /* empty */ { $$ = SCM_UNSPECIFIED; }
596 | lilypond_header_body assignment {
599 | lilypond_header_body embedded_scm {
605 HEADER '{' lilypond_header_body '}' {
606 $$ = parser->lexer_->remove_scope ();
618 assignment_id '=' identifier_init {
619 parser->lexer_->set_identifier ($1, $3);
620 $$ = SCM_UNSPECIFIED;
622 | assignment_id property_path '=' identifier_init {
623 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
624 parser->lexer_->set_identifier (path, $4);
625 $$ = SCM_UNSPECIFIED;
631 identifier_init_nonumber
633 | post_event_nofinger post_events
635 $$ = scm_reverse_x ($2, SCM_EOL);
636 if (Music *m = unsmob_music ($1))
638 if (m->is_mus_type ("post-event-wrapper"))
640 (scm_list_2 (m->get_property ("elements"),
643 $$ = scm_cons ($1, $$);
646 && scm_is_null (scm_cdr ($$)))
650 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
651 m->set_property ("elements", $$);
652 $$ = m->unprotect ();
657 identifier_init_nonumber:
662 | context_def_spec_block
669 | context_modification
672 context_def_spec_block:
673 CONTEXT '{' context_def_spec_body '}'
676 unsmob_context_def ($$)->origin ()->set_spot (@$);
684 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
685 parser->lexer_->push_note_state (nn);
689 parser->lexer_->pop_state ();
694 context_mod_embedded:
697 if (unsmob_music ($1)) {
698 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
699 $1 = scm_call_2 (proc, parser->self_scm (), $1);
701 if (unsmob_context_mod ($1))
704 parser->parser_error (@1, _ ("not a context mod"));
705 $$ = Context_mod ().smobbed_copy ();
711 context_def_spec_body:
713 $$ = Context_def::make_scm ();
715 | CONTEXT_DEF_IDENTIFIER {
718 | context_def_spec_body context_mod {
719 if (!SCM_UNBNDP ($2))
720 unsmob_context_def ($$)->add_context_mod ($2);
722 | context_def_spec_body context_modification {
723 Context_def *td = unsmob_context_def ($$);
724 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
725 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
726 td->add_context_mod (scm_car (m));
729 | context_def_spec_body context_mod_embedded {
730 Context_def *td = unsmob_context_def ($$);
731 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
732 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
733 td->add_context_mod (scm_car (m));
741 BOOK '{' book_body '}' {
743 unsmob_book ($$)->origin ()->set_spot (@$);
745 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
750 * Use 'handlers' like for toplevel-* stuff?
751 * grok \layout and \midi? */
754 Book *book = new Book;
755 init_papers (parser);
756 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
757 book->paper_->unprotect ();
758 push_paper (parser, book->paper_);
759 book->header_ = get_header (parser);
760 $$ = book->unprotect ();
761 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
764 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
766 | book_body paper_block {
767 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
768 set_paper (parser, unsmob_output_def ($2));
770 | book_body bookpart_block {
771 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
772 scm_call_2 (proc, $1, $2);
774 | book_body score_block {
775 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
776 scm_call_2 (proc, $1, $2);
778 | book_body composite_music {
779 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
780 scm_call_3 (proc, parser->self_scm (), $1, $2);
782 | book_body full_markup {
783 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
784 scm_call_2 (proc, $1, scm_list_1 ($2));
786 | book_body full_markup_list {
787 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
788 scm_call_2 (proc, $1, $2);
790 | book_body SCM_TOKEN {
791 // Evaluate and ignore #xxx, as opposed to \xxx
792 parser->lexer_->eval_scm_token ($2);
794 | book_body embedded_scm_active
796 SCM out = SCM_UNDEFINED;
797 if (Text_interface::is_markup ($2))
798 out = scm_list_1 ($2);
799 else if (Text_interface::is_markup_list ($2))
801 if (scm_is_pair (out))
803 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
804 scm_call_2 (proc, $1, out);
805 } else if (unsmob_score ($2))
807 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
808 scm_call_2 (proc, $1, $2);
809 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
810 parser->parser_error (@2, _("bad expression type"));
814 parser->lexer_->add_scope (unsmob_book ($1)->header_);
817 Book *book = unsmob_book ($1);
819 book->scores_ = SCM_EOL;
820 book->bookparts_ = SCM_EOL;
825 BOOKPART '{' bookpart_body '}' {
827 unsmob_book ($$)->origin ()->set_spot (@$);
828 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
834 Book *book = new Book;
835 $$ = book->unprotect ();
836 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
839 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
841 | bookpart_body paper_block {
842 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
844 | bookpart_body score_block {
845 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
846 scm_call_2 (proc, $1, $2);
848 | bookpart_body composite_music {
849 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
850 scm_call_3 (proc, parser->self_scm (), $1, $2);
852 | bookpart_body full_markup {
853 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
854 scm_call_2 (proc, $1, scm_list_1 ($2));
856 | bookpart_body full_markup_list {
857 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
858 scm_call_2 (proc, $1, $2);
860 | bookpart_body SCM_TOKEN {
861 // Evaluate and ignore #xxx, as opposed to \xxx
862 parser->lexer_->eval_scm_token ($2);
864 | bookpart_body embedded_scm_active
866 SCM out = SCM_UNDEFINED;
867 if (Text_interface::is_markup ($2))
868 out = scm_list_1 ($2);
869 else if (Text_interface::is_markup_list ($2))
871 if (scm_is_pair (out))
873 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
874 scm_call_2 (proc, $1, out);
875 } else if (unsmob_score ($2))
877 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
878 scm_call_2 (proc, $1, $2);
879 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
880 parser->parser_error (@2, _("bad expression type"));
884 Book *book = unsmob_book ($1);
885 if (!ly_is_module (book->header_))
886 book->header_ = ly_make_module (false);
887 parser->lexer_->add_scope (book->header_);
889 | bookpart_body error {
890 Book *book = unsmob_book ($1);
892 book->scores_ = SCM_EOL;
897 SCORE '{' score_body '}' {
898 unsmob_score ($3)->origin ()->set_spot (@$);
910 if (!scm_is_pair ($1)
911 || !ly_is_module (scm_car ($1)))
912 $1 = scm_cons (ly_make_module (false), $1);
913 parser->lexer_->add_scope (scm_car ($1));
918 | score_headers output_def
920 Output_def *od = unsmob_output_def ($2);
921 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
923 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
928 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
929 scm_set_cdr_x ($1, scm_cons ($2, scm_cdr ($1)));
931 $$ = scm_cons ($2, $1);
939 score_headers music {
940 SCM scorify = ly_lily_module_constant ("scorify-music");
941 $$ = scm_call_2 (scorify, $2, parser->self_scm ());
943 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
945 unsmob_score ($$)->set_header (scm_car ($1));
948 for (SCM p = scm_reverse_x ($1, SCM_EOL);
949 scm_is_pair (p); p = scm_cdr (p))
952 add_output_def (unsmob_output_def (scm_car (p)));
955 | embedded_scm_active {
956 if (!unsmob_score ($1))
958 $$ = (new Score)->unprotect ();
959 parser->parser_error (@1, _("score expected"));
964 Score *score = unsmob_score ($1);
965 if (!ly_is_module (score->get_header ()))
966 score->set_header (ly_make_module (false));
967 parser->lexer_->add_scope (score->get_header ());
969 | score_body output_def {
970 Output_def *od = unsmob_output_def ($2);
971 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
973 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
978 unsmob_score ($1)->add_output_def (od);
982 unsmob_score ($$)->error_found_ = true;
993 Output_def *od = unsmob_output_def ($1);
995 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
997 parser->parser_error (@1, _ ("need \\paper for paper block"));
998 $$ = get_paper (parser)->unprotect ();
1005 output_def_body '}' {
1008 parser->lexer_->remove_scope ();
1009 parser->lexer_->pop_state ();
1015 Output_def *p = get_paper (parser);
1016 p->input_origin_ = @$;
1017 parser->lexer_->add_scope (p->scope_);
1018 $$ = p->unprotect ();
1021 Output_def *p = get_midi (parser);
1022 $$ = p->unprotect ();
1023 parser->lexer_->add_scope (p->scope_);
1026 Output_def *p = get_layout (parser);
1028 parser->lexer_->add_scope (p->scope_);
1029 $$ = p->unprotect ();
1033 output_def_head_with_mode_switch:
1035 parser->lexer_->push_initial_state ();
1040 // We need this weird nonterminal because both music as well as a
1041 // context definition can start with \context and the difference is
1042 // only apparent after looking at the next token. If it is '{', there
1043 // is still time to escape from notes mode.
1045 music_or_context_def:
1047 | context_def_spec_block
1051 output_def_head_with_mode_switch '{' {
1053 unsmob_output_def ($$)->input_origin_.set_spot (@$);
1055 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1056 Output_def *o = unsmob_output_def ($3);
1057 o->input_origin_.set_spot (@$);
1058 $$ = o->self_scm ();
1059 parser->lexer_->remove_scope ();
1060 parser->lexer_->add_scope (o->scope_);
1062 | output_def_body assignment {
1065 | output_def_body embedded_scm {
1070 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1071 parser->lexer_->push_note_state (nn);
1072 } music_or_context_def
1074 parser->lexer_->pop_state ();
1075 if (unsmob_context_def ($3))
1076 assign_context_def (unsmob_output_def ($1), $3);
1079 SCM proc = parser->lexer_->lookup_identifier
1080 ("output-def-music-handler");
1081 scm_call_3 (proc, parser->self_scm (),
1085 | output_def_body error {
1091 TEMPO steno_duration '=' tempo_range {
1092 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1094 | TEMPO scalar steno_duration '=' tempo_range {
1095 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1098 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1103 The representation of a list is reversed to have efficient append. */
1109 | music_list music_embedded {
1110 if (unsmob_music ($2))
1111 $$ = scm_cons ($2, $1);
1113 | music_list error {
1114 Music *m = MY_MAKE_MUSIC("Music", @$);
1116 m->set_property ("error-found", SCM_BOOL_T);
1117 $$ = scm_cons (m->self_scm (), $1);
1118 m->unprotect (); /* UGH */
1125 $$ = scm_reverse_x ($2, SCM_EOL);
1130 | lyric_element_music
1133 $$ = make_music_from_simple (parser, @1, $1);
1134 if (!unsmob_music ($$))
1136 parser->parser_error (@1, _ ("music expected"));
1137 $$ = MAKE_SYNTAX ("void-music", @$);
1145 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1146 parser->parser_error (@1, _ ("unexpected post-event"));
1147 $$ = SCM_UNSPECIFIED;
1150 | music_embedded_backup
1154 | music_embedded_backup BACKUP lyric_element_music
1158 | multiplied_duration post_events
1160 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1162 parser->default_duration_ = *unsmob_duration ($1);
1163 n->set_property ("duration", $1);
1165 if (scm_is_pair ($2))
1166 n->set_property ("articulations",
1167 scm_reverse_x ($2, SCM_EOL));
1168 $$ = n->unprotect ();
1172 music_embedded_backup:
1175 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1177 else if (Music *m = unsmob_music ($1)) {
1178 if (m->is_mus_type ("post-event")) {
1179 parser->parser_error
1180 (@1, _ ("unexpected post-event"));
1181 $$ = SCM_UNSPECIFIED;
1184 } else if (parser->lexer_->is_lyric_state ()
1185 && Text_interface::is_markup ($1))
1186 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1188 @$.warning (_ ("Ignoring non-music expression"));
1194 // music_assign does not need to contain lyrics: there are no
1195 // assignments in lyricmode.
1198 | composite_music %prec COMPOSITE
1202 REPEAT simple_string unsigned_number music
1204 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1206 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1208 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1213 SEQUENTIAL braced_music_list {
1214 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1216 | braced_music_list {
1217 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1222 SIMULTANEOUS braced_music_list {
1223 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1225 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1226 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1232 | music_property_def
1236 context_modification:
1239 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1240 parser->lexer_->push_note_state (nn);
1241 } '{' context_mod_list '}'
1243 parser->lexer_->pop_state ();
1246 | WITH CONTEXT_MOD_IDENTIFIER
1250 | CONTEXT_MOD_IDENTIFIER
1254 | WITH context_modification_arg
1256 if (unsmob_music ($2)) {
1257 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1258 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1260 if (unsmob_context_mod ($2))
1263 parser->parser_error (@2, _ ("not a context mod"));
1264 $$ = Context_mod ().smobbed_copy ();
1269 context_modification_arg:
1274 optional_context_mod:
1278 | context_modification
1286 $$ = Context_mod ().smobbed_copy ();
1288 | context_mod_list context_mod {
1289 if (!SCM_UNBNDP ($2))
1290 unsmob_context_mod ($1)->add_context_mod ($2);
1292 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1293 Context_mod *md = unsmob_context_mod ($2);
1295 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1297 | context_mod_list context_mod_embedded {
1298 unsmob_context_mod ($1)->add_context_mods
1299 (unsmob_context_mod ($2)->get_mods ());
1311 | grouped_music_list
1315 simultaneous_music { $$ = $1; }
1316 | sequential_music { $$ = $1; }
1319 /* Function argument lists are arguably the most complex part in the
1320 * parser. They are pretty tricky to understand because of the way
1321 * they are processed, and because of optional arguments that can be
1322 * omitted. When there are several optional arguments in a row,
1323 * omitting one automatically omits all following arguments. Optional
1324 * arguments can only be omitted when either
1326 * a) the omission is explicitly started with \default
1327 * b) the omission is implicitly started by an argument not matching
1328 * its predicate, and there is a mandatory argument later that can
1329 * "catch" the argument that does not fit.
1331 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1332 * (corresponding to mandatory arguments and having a predicate
1333 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1334 * the semantic value of the EXPECT_OPTIONAL token is the default to
1335 * use when the optional argument is omitted, and EXPECT_SCM again has
1336 * the argument predicate as semantic value) in reverse order to the
1337 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1338 * processed inside-out while actual tokens are consumed.
1340 * This means that the argument list tokens determine the actions
1341 * taken as they arrive. The structure of the argument list is known
1342 * to the parser and stored in its parse stack when the first argument
1343 * is being parsed. What the parser does not know is which predicates
1344 * will match and whether or not \default will be appearing in the
1345 * argument list, and where.
1347 * Sequences of 0 or more optional arguments are scanned using either
1348 * function_arglist_backup or function_arglist_nonbackup. The first
1349 * is used when optional arguments are followed by at least one
1350 * mandatory argument: in that case optional arguments may be skipped
1351 * by either a false predicate (in which case the expression will be
1352 * pushed back as one or more tokens, preceded by a BACKUP token) or
1353 * by using \default.
1355 * If optional arguments are at the end of the argument list, they are
1356 * instead scanned using function_arglist_nonbackup: here the only
1357 * manner to enter into skipping of optional arguments is the use of
1360 * The argument list of a normal function call is parsed using
1361 * function_arglist. The part of an argument list before a mandatory
1362 * argument is parsed using function_arglist_optional.
1364 * The difference is that leading optional arguments are scanned using
1365 * function_arglist_nonbackup and function_arglist_backup,
1368 * Most other details are obvious in the rules themselves.
1374 | SYMBOL_LIST '.' symbol_list_rev
1376 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1382 | symbol_list_rev '.' symbol_list_part
1384 $$ = scm_append_x (scm_list_2 ($3, $1));
1388 // symbol_list_part delivers elements in reverse copy.
1393 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1394 $$ = try_string_variants (sym_l_p, $1);
1395 if (SCM_UNBNDP ($$)) {
1396 parser->parser_error (@1, _("not a symbol"));
1399 $$ = scm_reverse ($$);
1404 symbol_list_element:
1410 function_arglist_nonbackup:
1411 function_arglist_common
1412 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1414 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1416 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1418 SCM n = scm_difference ($5, SCM_UNDEFINED);
1419 if (scm_is_true (scm_call_1 ($2, n)))
1420 $$ = scm_cons (n, $3);
1422 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1423 t->set_property ("digit", $5);
1424 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1429 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1431 $$ = check_scheme_arg (parser, @4,
1432 scm_difference ($5, SCM_UNDEFINED),
1435 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1437 $$ = check_scheme_arg (parser, @4,
1438 scm_difference ($5, SCM_UNDEFINED),
1441 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1443 if (scm_is_true (scm_call_1 ($2, $4)))
1444 $$ = scm_cons ($4, $3);
1446 $$ = check_scheme_arg (parser, @4,
1447 make_music_from_simple
1451 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1453 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1455 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1457 if (scm_is_true (scm_call_1 ($2, $3)))
1458 $$ = scm_cons ($3, $1);
1460 $$ = check_scheme_arg (parser, @3,
1461 make_music_from_simple
1465 | function_arglist_nonbackup_reparse REPARSE duration_length
1467 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1469 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1471 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1473 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1475 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1477 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1479 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1481 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1483 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1487 function_arglist_nonbackup_reparse:
1488 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
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 pitch
1510 ($2, make_music_from_simple
1512 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1514 MYREPARSE (@4, $2, SCM_ARG, $4);
1516 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1521 ($2, make_music_from_simple
1523 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1525 MYREPARSE (@4, $2, SCM_ARG, $4);
1527 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1530 SCM res = try_string_variants ($2, $4);
1531 if (!SCM_UNBNDP (res))
1532 if (scm_is_pair (res))
1533 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1535 MYREPARSE (@4, $2, SCM_ARG, res);
1536 else if (scm_is_true
1538 ($2, make_music_from_simple
1540 MYREPARSE (@4, $2, STRING, $4);
1542 MYREPARSE (@4, $2, SCM_ARG, $4);
1544 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1547 if (scm_is_true (scm_call_1 ($2, $4)))
1548 MYREPARSE (@4, $2, SCM_ARG, $4);
1549 else if (scm_is_true
1551 ($2, make_music_from_simple
1553 MYREPARSE (@4, $2, STRING, $4);
1555 MYREPARSE (@4, $2, SCM_ARG, $4);
1557 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1560 if (scm_is_true (scm_call_1 ($2, $4)))
1561 MYREPARSE (@4, $2, REAL, $4);
1563 SCM d = make_duration ($4);
1564 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1565 MYREPARSE (@4, $2, REAL, $4); // trigger error
1567 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1570 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1572 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1577 // function_arglist_backup can't occur at the end of an argument
1579 function_arglist_backup:
1580 function_arglist_common
1581 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1583 if (scm_is_true (scm_call_1 ($2, $4)))
1584 $$ = scm_cons ($4, $3);
1586 $$ = make_music_from_simple (parser, @4, $4);
1587 if (scm_is_true (scm_call_1 ($2, $$)))
1588 $$ = scm_cons ($$, $3);
1591 $$ = scm_cons (loc_on_music (@3, $1), $3);
1592 MYBACKUP (SCM_ARG, $4, @4);
1596 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1598 if (scm_is_true (scm_call_1 ($2, $4)))
1600 $$ = scm_cons ($4, $3);
1602 $$ = scm_cons (loc_on_music (@3, $1), $3);
1603 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1606 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1610 ($2, make_music_from_simple
1614 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1615 } else if (scm_is_true (scm_call_1 ($2, $4)))
1616 $$ = scm_cons ($4, $3);
1618 $$ = scm_cons (loc_on_music (@3, $1), $3);
1619 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1622 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1626 ($2, make_music_from_simple
1630 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1631 } else 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 (TONICNAME_PITCH, $4, @4);
1638 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1640 if (scm_is_true (scm_call_1 ($2, $4)))
1641 $$ = scm_cons ($4, $3);
1643 $$ = scm_cons (loc_on_music (@3, $1), $3);
1644 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1647 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1649 if (scm_is_true (scm_call_1 ($2, $4)))
1651 MYREPARSE (@4, $2, REAL, $4);
1654 SCM d = make_duration ($4);
1655 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1657 $$ = scm_cons (loc_on_music (@3, $1), $3);
1658 MYBACKUP (UNSIGNED, $4, @4);
1660 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1665 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1667 if (scm_is_true (scm_call_1 ($2, $4)))
1670 MYREPARSE (@4, $2, REAL, $4);
1672 $$ = scm_cons (loc_on_music (@3, $1), $3);
1673 MYBACKUP (REAL, $4, @4);
1676 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1678 if (scm_is_true (scm_call_1 ($2, $4)))
1680 $$ = scm_cons ($4, $3);
1682 $$ = scm_cons (loc_on_music (@3, $1), $3);
1683 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1686 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1688 SCM n = scm_difference ($5, SCM_UNDEFINED);
1689 if (scm_is_true (scm_call_1 ($2, n))) {
1691 MYREPARSE (@5, $2, REAL, n);
1693 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1694 t->set_property ("digit", $5);
1695 $$ = t->unprotect ();
1696 if (scm_is_true (scm_call_1 ($2, $$)))
1697 $$ = scm_cons ($$, $3);
1699 $$ = scm_cons (loc_on_music (@3, $1), $3);
1700 MYBACKUP (UNSIGNED, $5, @5);
1701 parser->lexer_->push_extra_token (@4, '-');
1706 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1708 SCM n = scm_difference ($5, SCM_UNDEFINED);
1709 if (scm_is_true (scm_call_1 ($2, n))) {
1710 MYREPARSE (@5, $2, REAL, n);
1713 $$ = scm_cons (loc_on_music (@3, $1), $3);
1714 MYBACKUP (REAL, n, @5);
1717 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1719 SCM n = scm_difference ($5, SCM_UNDEFINED);
1720 if (scm_is_true (scm_call_1 ($2, n))) {
1721 $$ = scm_cons (n, $3);
1723 $$ = scm_cons (loc_on_music (@3, $1), $3);
1724 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
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 pitch_or_music
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 bare_number_common
1780 $$ = check_scheme_arg (parser, @3,
1783 | function_arglist_backup REPARSE duration_length
1785 $$ = check_scheme_arg (parser, @3,
1788 | function_arglist_backup REPARSE symbol_list_arg
1790 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1795 function_arglist_nonbackup
1796 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1798 $$ = scm_cons (loc_on_music (@4, $1), $3);
1802 function_arglist_skip_nonbackup:
1803 function_arglist_nonbackup
1804 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1806 $$ = scm_cons (loc_on_music (@3, $1), $3);
1810 function_arglist_common:
1811 EXPECT_NO_MORE_ARGS {
1814 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1816 if (scm_is_true (scm_call_1 ($1, $3)))
1817 $$ = scm_cons ($3, $2);
1819 $$ = check_scheme_arg (parser, @3,
1820 make_music_from_simple
1824 | EXPECT_SCM function_arglist_optional bare_number_common
1826 $$ = check_scheme_arg (parser, @3,
1829 | EXPECT_SCM function_arglist_optional post_event_nofinger
1831 $$ = check_scheme_arg (parser, @3,
1834 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1836 SCM n = scm_difference ($4, SCM_UNDEFINED);
1837 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1839 | function_arglist_common_reparse REPARSE SCM_ARG
1841 $$ = check_scheme_arg (parser, @3,
1844 | function_arglist_common_reparse REPARSE lyric_element_music
1846 $$ = check_scheme_arg (parser, @3,
1849 | function_arglist_common_reparse REPARSE pitch_or_music
1851 if (scm_is_true (scm_call_1 ($2, $3)))
1852 $$ = scm_cons ($3, $1);
1854 $$ = check_scheme_arg (parser, @3,
1855 make_music_from_simple
1859 | function_arglist_common_reparse REPARSE bare_number_common
1861 $$ = check_scheme_arg (parser, @3,
1864 | function_arglist_common_reparse REPARSE duration_length
1866 $$ = check_scheme_arg (parser, @3,
1869 | function_arglist_common_reparse REPARSE symbol_list_arg
1871 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1875 function_arglist_common_reparse:
1876 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1879 SCM res = try_string_variants ($1, $3);
1880 if (!SCM_UNBNDP (res))
1881 if (scm_is_pair (res))
1882 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1884 MYREPARSE (@3, $1, SCM_ARG, res);
1885 else if (scm_is_true
1887 ($1, make_music_from_simple (parser, @3, $3))))
1888 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1890 // This is going to flag a syntax error, we
1891 // know the predicate to be false.
1892 MYREPARSE (@3, $1, SCM_ARG, $3);
1894 | EXPECT_SCM function_arglist_optional pitch
1899 ($1, make_music_from_simple
1901 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
1903 MYREPARSE (@3, $1, SCM_ARG, $3);
1905 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
1910 ($1, make_music_from_simple
1912 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
1914 MYREPARSE (@3, $1, SCM_ARG, $3);
1916 | EXPECT_SCM function_arglist_optional STRING
1919 SCM res = try_string_variants ($1, $3);
1920 if (!SCM_UNBNDP (res))
1921 if (scm_is_pair (res))
1922 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1924 MYREPARSE (@3, $1, SCM_ARG, res);
1925 else if (scm_is_true
1927 ($1, make_music_from_simple (parser, @3, $3))))
1928 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1930 // This is going to flag a syntax error, we
1931 // know the predicate to be false.
1932 MYREPARSE (@3, $1, SCM_ARG, $3);
1934 | EXPECT_SCM function_arglist_optional full_markup
1937 if (scm_is_true (scm_call_1 ($1, $3)))
1938 MYREPARSE (@3, $1, SCM_ARG, $3);
1939 else if (scm_is_true
1941 ($1, make_music_from_simple (parser, @3, $3))))
1942 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1944 // This is going to flag a syntax error, we
1945 // know the predicate to be false.
1946 MYREPARSE (@3, $1, SCM_ARG, $3);
1948 | EXPECT_SCM function_arglist_optional UNSIGNED
1951 if (scm_is_true (scm_call_1 ($1, $3)))
1952 MYREPARSE (@3, $1, REAL, $3);
1954 SCM d = make_duration ($3);
1955 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
1956 MYREPARSE (@3, $1, REAL, $3);
1958 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
1961 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
1964 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
1966 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
1969 SCM n = scm_difference ($4, SCM_UNDEFINED);
1970 if (scm_is_true (scm_call_1 ($1, n)))
1971 MYREPARSE (@4, $1, REAL, n);
1973 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1974 t->set_property ("digit", $4);
1975 SCM m = t->unprotect ();
1976 if (scm_is_true (scm_call_1 ($1, m)))
1977 MYREPARSE (@4, $1, SCM_ARG, m);
1979 MYREPARSE (@4, $1, SCM_ARG, $4);
1983 | EXPECT_SCM function_arglist_optional '-' REAL
1986 SCM n = scm_difference ($4, SCM_UNDEFINED);
1987 MYREPARSE (@4, $1, REAL, n);
1991 function_arglist_optional:
1992 function_arglist_backup
1993 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
1995 $$ = scm_cons (loc_on_music (@4, $1), $3);
1997 | function_arglist_skip_backup BACKUP
2000 function_arglist_skip_backup:
2001 function_arglist_backup
2002 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2004 $$ = scm_cons (loc_on_music (@3, $1), $3);
2008 music_function_call:
2009 MUSIC_FUNCTION function_arglist {
2010 $$ = MAKE_SYNTAX ("music-function", @$,
2017 /**/ { $$ = SCM_EOL; }
2018 | '=' simple_string {
2025 | repeated_music { $$ = $1; }
2026 | re_rhythmed_music { $$ = $1; }
2027 | complex_music_prefix music
2029 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2033 complex_music_prefix:
2034 CONTEXT symbol optional_id optional_context_mod {
2035 Context_mod *ctxmod = unsmob_context_mod ($4);
2038 mods = ctxmod->get_mods ();
2039 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2041 | NEWCONTEXT symbol optional_id optional_context_mod {
2042 Context_mod *ctxmod = unsmob_context_mod ($4);
2045 mods = ctxmod->get_mods ();
2046 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2051 mode_changing_head grouped_music_list {
2052 if ($1 == ly_symbol2scm ("chords"))
2054 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2060 parser->lexer_->pop_state ();
2062 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2063 Context_mod *ctxmod = unsmob_context_mod ($2);
2066 mods = ctxmod->get_mods ();
2067 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2068 if ($1 == ly_symbol2scm ("ChordNames"))
2070 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2072 parser->lexer_->pop_state ();
2078 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2079 parser->lexer_->push_note_state (nn);
2081 $$ = ly_symbol2scm ("notes");
2085 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2086 parser->lexer_->push_note_state (nn);
2088 $$ = ly_symbol2scm ("drums");
2091 parser->lexer_->push_figuredbass_state ();
2093 $$ = ly_symbol2scm ("figures");
2096 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2097 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2098 nn = parser->lexer_->lookup_identifier ("pitchnames");
2099 parser->lexer_->push_chord_state (nn);
2100 $$ = ly_symbol2scm ("chords");
2104 { parser->lexer_->push_lyric_state ();
2105 $$ = ly_symbol2scm ("lyrics");
2109 mode_changing_head_with_context:
2111 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2112 parser->lexer_->push_note_state (nn);
2114 $$ = ly_symbol2scm ("DrumStaff");
2117 parser->lexer_->push_figuredbass_state ();
2119 $$ = ly_symbol2scm ("FiguredBass");
2122 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2123 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2124 nn = parser->lexer_->lookup_identifier ("pitchnames");
2125 parser->lexer_->push_chord_state (nn);
2126 $$ = ly_symbol2scm ("ChordNames");
2129 { parser->lexer_->push_lyric_state ();
2130 $$ = ly_symbol2scm ("Lyrics");
2135 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2138 /* Can also use music at the expensive of two S/Rs similar to
2139 \repeat \alternative */
2140 parser->lexer_->pop_state ();
2142 $$ = scm_cons ($3, SCM_EOL);
2144 | new_lyrics ADDLYRICS {
2145 parser->lexer_->push_lyric_state ();
2147 parser->lexer_->pop_state ();
2148 $$ = scm_cons ($4, $1);
2153 composite_music new_lyrics {
2154 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2156 | LYRICSTO simple_string {
2157 parser->lexer_->push_lyric_state ();
2159 parser->lexer_->pop_state ();
2160 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2165 CHANGE symbol '=' simple_string {
2166 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2173 $$ = scm_reverse_x ($1, SCM_EOL);
2175 | symbol_list_rev property_path {
2176 $$ = scm_reverse_x ($1, $2);
2182 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2185 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2187 | OVERRIDE property_path '=' scalar {
2188 if (scm_ilength ($2) < 2) {
2189 parser->parser_error (@2, _("bad grob property path"));
2192 $$ = scm_cons (ly_symbol2scm ("push"),
2193 scm_cons2 (scm_car ($2),
2198 | REVERT revert_arg {
2199 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2203 // This is all quite awkward for the sake of substantial backward
2204 // compatibility while at the same time allowing a more "natural" form
2205 // of specification not separating grob specification from grob
2206 // property path. The purpose of this definition of revert_arg is to
2207 // allow the symbol list which specifies grob and property to revert
2208 // to be optionally be split into two parts after the grob (which in
2209 // this case is just the first element of the list). symbol_list_part
2210 // is only one path component, but it can be parsed without lookahead,
2211 // so we can follow it with a synthetic BACKUP token when needed. If
2212 // the first symbol_list_part already contains multiple elements (only
2213 // possible if a Scheme expression provides them), we just parse for
2214 // additional elements introduced by '.', which is what the
2215 // SYMBOL_LIST backup in connection with the immediately following
2216 // rule using symbol_list_arg does.
2218 // As long as we don't have our coffers filled with both grob and at
2219 // least one grob property specification, the rest of the required
2220 // symbol list chain may be provided either with or without a leading
2221 // dot. This is for both allowing the traditional
2222 // \revert Accidental #'color
2223 // as well as well as the "naive" form
2224 // \revert Accidental.color
2227 revert_arg_backup BACKUP symbol_list_arg
2236 if (scm_is_null ($1)
2237 || scm_is_null (scm_cdr ($1)))
2238 MYBACKUP (SCM_ARG, $1, @1);
2240 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2244 // revert_arg_part delivers results in reverse
2247 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2249 $$ = scm_append_x (scm_list_2 ($5, $3));
2251 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2253 $$ = scm_append_x (scm_list_2 ($4, $3));
2258 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2259 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2261 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2262 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2263 | DENIES { $$ = ly_symbol2scm ("denies"); }
2265 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2266 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2267 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2268 | NAME { $$ = ly_symbol2scm ("context-name"); }
2272 property_operation { $$ = $1; }
2273 | context_def_mod STRING {
2274 $$ = scm_list_2 ($1, $2);
2276 | context_def_mod embedded_scm
2278 if (!scm_is_string ($2)
2279 && ly_symbol2scm ("consists") != $1
2280 && ly_symbol2scm ("remove") != $1)
2283 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2287 $$ = scm_list_2 ($1, $2);
2292 // If defined, at least two members.
2296 SCM l = scm_reverse_x ($1, SCM_EOL);
2299 (scm_object_property (scm_car (l),
2300 ly_symbol2scm ("is-grob?"))))
2301 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2302 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2303 parser->parser_error (@1, _ ("bad grob property path"));
2310 // If defined, at least three members
2314 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2316 parser->parser_error (@1, _ ("bad grob property path"));
2320 | grob_prop_spec property_path
2322 if (!SCM_UNBNDP ($1)) {
2323 $$ = scm_append_x (scm_list_2 ($1, $2));
2324 if (scm_is_null (scm_cddr ($$))) {
2325 parser->parser_error (@$, _ ("bad grob property path"));
2333 // Exactly two elements or undefined
2337 SCM l = scm_reverse_x ($1, SCM_EOL);
2338 switch (scm_ilength (l)) {
2340 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2344 parser->parser_error (@1, _ ("bad context property path"));
2351 simple_music_property_def:
2352 OVERRIDE grob_prop_path '=' scalar {
2353 if (SCM_UNBNDP ($2))
2356 $$ = scm_list_5 (scm_car ($2),
2357 ly_symbol2scm ("OverrideProperty"),
2363 | REVERT simple_revert_context revert_arg {
2364 $$ = scm_list_4 ($2,
2365 ly_symbol2scm ("RevertProperty"),
2369 | SET context_prop_spec '=' scalar {
2370 if (SCM_UNBNDP ($2))
2373 $$ = scm_list_4 (scm_car ($2),
2374 ly_symbol2scm ("PropertySet"),
2378 | UNSET context_prop_spec {
2379 if (SCM_UNBNDP ($2))
2382 $$ = scm_list_3 (scm_car ($2),
2383 ly_symbol2scm ("PropertyUnset"),
2389 // This is all quite awkward for the sake of substantial backward
2390 // compatibility while at the same time allowing a more "natural" form
2391 // of specification not separating grob specification from grob
2392 // property path. The purpose of this definition of
2393 // simple_revert_context is to allow the symbol list which specifies
2394 // grob and property to revert to be optionally be split into two
2395 // parts after the grob (which may be preceded by a context
2396 // specification, a case which we distinguish by checking whether the
2397 // first symbol is a valid grob symbol instead).
2399 // See revert_arg above for the main work horse of this arrangement.
2400 // simple_revert_context just caters for the context and delegates the
2401 // rest of the job to revert_arg.
2403 simple_revert_context:
2406 $1 = scm_reverse_x ($1, SCM_EOL);
2407 if (scm_is_null ($1)
2409 (scm_object_property (scm_car ($1),
2410 ly_symbol2scm ("is-grob?")))) {
2411 $$ = ly_symbol2scm ("Bottom");
2412 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2415 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2422 simple_music_property_def {
2423 if (SCM_UNBNDP ($1))
2424 $$ = MAKE_SYNTAX ("void-music", @1);
2426 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2437 simple_string: STRING {
2442 if (scm_is_string ($1)) {
2445 parser->parser_error (@1, (_ ("simple string expected")));
2446 $$ = scm_string (SCM_EOL);
2453 $$ = scm_string_to_symbol ($1);
2457 // This is a bit of overkill but makes the same
2458 // routine responsible for all symbol interpretations.
2459 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2461 if (SCM_UNBNDP ($$))
2463 parser->parser_error (@1, (_ ("symbol expected")));
2464 // Generate a unique symbol in case it is used
2465 // for an assignment or similar
2466 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2476 // The following is a rather defensive variant of admitting
2477 // negative numbers: the grammar would permit number_factor or
2478 // even number_expression. However, function arguments allow
2479 // only this simple kind of negative number, so to have things
2480 // like \tweak and \override behave reasonably similar, it
2481 // makes sense to rule out things like -- which are rather an
2482 // accent in function argument contexts.
2485 $$ = scm_difference ($2, SCM_UNDEFINED);
2491 simple_element post_events {
2492 // Let the rhythmic music iterator sort this mess out.
2493 if (scm_is_pair ($2)) {
2494 unsmob_music ($$)->set_property ("articulations",
2495 scm_reverse_x ($2, SCM_EOL));
2498 | CHORD_REPETITION optional_notemode_duration post_events {
2500 i.set_location (@1, @3);
2501 $$ = MAKE_SYNTAX ("repetition-chord", i,
2502 $2, scm_reverse_x ($3, SCM_EOL));
2504 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2506 i.set_location (@1, @3);
2507 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2508 scm_reverse_x ($3, SCM_EOL));
2511 | note_chord_element
2516 chord_body optional_notemode_duration post_events
2518 Music *m = unsmob_music ($1);
2519 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2520 SCM es = m->get_property ("elements");
2521 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2523 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2524 unsmob_music (scm_car (s))->set_property ("duration", dur);
2525 es = ly_append2 (es, postevs);
2527 m-> set_property ("elements", es);
2529 $$ = m->self_scm ();
2534 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2536 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2540 chord_body_elements:
2541 /* empty */ { $$ = SCM_EOL; }
2542 | chord_body_elements chord_body_element {
2543 if (!SCM_UNBNDP ($2))
2544 $$ = scm_cons ($2, $1);
2549 pitch exclamations questions octave_check post_events
2551 bool q = to_boolean ($3);
2552 bool ex = to_boolean ($2);
2556 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2557 n->set_property ("pitch", $1);
2559 n->set_property ("cautionary", SCM_BOOL_T);
2561 n->set_property ("force-accidental", SCM_BOOL_T);
2563 if (scm_is_pair (post)) {
2564 SCM arts = scm_reverse_x (post, SCM_EOL);
2565 n->set_property ("articulations", arts);
2567 if (scm_is_number (check))
2569 int q = scm_to_int (check);
2570 n->set_property ("absolute-octave", scm_from_int (q-1));
2573 $$ = n->unprotect ();
2575 | DRUM_PITCH post_events {
2576 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2577 n->set_property ("drum-type", $1);
2579 if (scm_is_pair ($2)) {
2580 SCM arts = scm_reverse_x ($2, SCM_EOL);
2581 n->set_property ("articulations", arts);
2583 $$ = n->unprotect ();
2585 | music_function_chord_body
2587 Music *m = unsmob_music ($1);
2589 while (m && m->is_mus_type ("music-wrapper-music")) {
2590 $$ = m->get_property ("element");
2591 m = unsmob_music ($$);
2594 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2595 parser->parser_error (@$, _ ("not a rhythmic event"));
2601 music_function_chord_body:
2606 event_function_event:
2607 EVENT_FUNCTION function_arglist {
2608 $$ = MAKE_SYNTAX ("music-function", @$,
2617 | post_events post_event {
2619 if (Music *m = unsmob_music ($2))
2621 if (m->is_mus_type ("post-event-wrapper"))
2623 for (SCM p = m->get_property ("elements");
2627 $$ = scm_cons (scm_car (p), $$);
2631 $$ = scm_cons ($2, $$);
2637 post_event_nofinger:
2638 direction_less_event {
2641 | script_dir music_function_call {
2643 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2644 parser->parser_error (@2, _ ("post-event expected"));
2645 $$ = SCM_UNSPECIFIED;
2646 } else if (!SCM_UNBNDP ($1))
2648 unsmob_music ($$)->set_property ("direction", $1);
2652 if (!parser->lexer_->is_lyric_state ())
2653 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2654 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2657 if (!parser->lexer_->is_lyric_state ())
2658 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2659 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2661 | script_dir direction_reqd_event {
2662 if (!SCM_UNBNDP ($1))
2664 Music *m = unsmob_music ($2);
2665 m->set_property ("direction", $1);
2669 | script_dir direction_less_event {
2670 if (!SCM_UNBNDP ($1))
2672 Music *m = unsmob_music ($2);
2673 m->set_property ("direction", $1);
2680 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2685 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2696 string_number_event:
2698 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2699 s->set_property ("string-number", $1);
2700 $$ = s->unprotect ();
2704 direction_less_event:
2706 | EVENT_IDENTIFIER {
2710 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2711 a->set_property ("tremolo-type", $1);
2712 $$ = a->unprotect ();
2714 | event_function_event
2717 direction_reqd_event:
2721 | script_abbreviation {
2722 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2723 if (scm_is_string (s)) {
2724 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2725 a->set_property ("articulation-type", s);
2726 $$ = a->unprotect ();
2728 Music *original = unsmob_music (s);
2729 if (original && original->is_mus_type ("post-event")) {
2730 Music *a = original->clone ();
2731 a->set_spot (parser->lexer_->override_input (@$));
2732 $$ = a->unprotect ();
2734 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2735 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2742 /**/ { $$ = SCM_EOL; }
2743 | '=' quotes { $$ = $2; }
2757 $$ = scm_from_int (1);
2760 $$ = scm_oneplus ($1);
2766 $$ = scm_from_int (-1);
2769 $$ = scm_oneminus ($1);
2774 NOTENAME_PITCH quotes {
2775 if (!scm_is_eq (SCM_INUM0, $2))
2777 Pitch p = *unsmob_pitch ($1);
2778 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2779 $$ = p.smobbed_copy ();
2789 TONICNAME_PITCH quotes {
2790 if (!scm_is_eq (SCM_INUM0, $2))
2792 Pitch p = *unsmob_pitch ($1);
2793 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2794 $$ = p.smobbed_copy ();
2801 | PITCH_IDENTIFIER quotes {
2802 if (!scm_is_eq (SCM_INUM0, $2))
2804 Pitch p = *unsmob_pitch ($1);
2805 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2806 $$ = p.smobbed_copy ();
2813 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2814 t->set_property ("text", $1);
2815 $$ = t->unprotect ();
2818 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2819 t->set_property ("text",
2820 make_simple_markup ($1));
2821 $$ = t->unprotect ();
2825 Music *m = unsmob_music ($1);
2826 if (m && m->is_mus_type ("post-event"))
2828 else if (Text_interface::is_markup ($1)) {
2829 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2830 t->set_property ("text", $1);
2831 $$ = t->unprotect ();
2833 parser->parser_error (@1, _ ("not an articulation"));
2839 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2840 t->set_property ("digit", $1);
2841 $$ = t->unprotect ();
2845 script_abbreviation:
2847 $$ = scm_from_locale_string ("Hat");
2850 $$ = scm_from_locale_string ("Plus");
2853 $$ = scm_from_locale_string ("Dash");
2856 $$ = scm_from_locale_string ("Bang");
2859 $$ = scm_from_locale_string ("Larger");
2862 $$ = scm_from_locale_string ("Dot");
2865 $$ = scm_from_locale_string ("Underscore");
2870 '_' { $$ = scm_from_int (DOWN); }
2871 | '^' { $$ = scm_from_int (UP); }
2872 | '-' { $$ = SCM_UNDEFINED; }
2876 multiplied_duration {
2881 maybe_notemode_duration:
2885 | multiplied_duration {
2887 parser->default_duration_ = *unsmob_duration ($$);
2892 optional_notemode_duration:
2893 maybe_notemode_duration
2895 if (SCM_UNBNDP ($$))
2896 $$ = parser->default_duration_.smobbed_copy ();
2902 $$ = make_duration ($1, scm_to_int ($2));
2903 if (SCM_UNBNDP ($$))
2905 parser->parser_error (@1, _ ("not a duration"));
2906 $$ = Duration ().smobbed_copy ();
2909 | DURATION_IDENTIFIER dots {
2910 Duration *d = unsmob_duration ($1);
2911 Duration k (d->duration_log (),
2912 d->dot_count () + scm_to_int ($2));
2913 k = k.compressed (d->factor ());
2914 scm_remember_upto_here_1 ($1);
2915 $$ = k.smobbed_copy ();
2919 multiplied_duration:
2923 | multiplied_duration '*' UNSIGNED {
2924 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2926 | multiplied_duration '*' FRACTION {
2927 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2929 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2938 $$ = scm_oneplus ($1);
2947 if (SCM_UNBNDP (make_duration ($2)))
2948 parser->parser_error (@2, _ ("not a duration"));
2954 UNSIGNED { $$ = $1; }
2955 | STRING { $$ = $1; }
2956 | full_markup { $$ = $1; }
2959 // as an integer, it needs to be non-negative, and otherwise
2960 // it needs to be suitable as a markup.
2961 if (scm_is_integer ($1)
2962 ? scm_is_true (scm_negative_p ($1))
2963 : !Text_interface::is_markup ($1))
2965 parser->parser_error (@1, _ ("bass number expected"));
2971 figured_bass_alteration:
2972 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2973 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2974 | '!' { $$ = scm_from_int (0); }
2979 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2980 $$ = bfr->unprotect ();
2983 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2984 $$ = bfr->self_scm ();
2986 if (scm_is_number ($1))
2987 bfr->set_property ("figure", $1);
2988 else if (Text_interface::is_markup ($1))
2989 bfr->set_property ("text", $1);
2995 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2997 | bass_figure figured_bass_alteration {
2998 Music *m = unsmob_music ($1);
2999 if (scm_to_double ($2)) {
3000 SCM salter = m->get_property ("alteration");
3001 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3002 m->set_property ("alteration",
3003 scm_sum (alter, $2));
3005 m->set_property ("alteration", scm_from_int (0));
3008 | bass_figure figured_bass_modification {
3009 Music *m = unsmob_music ($1);
3010 m->set_property ($2, SCM_BOOL_T);
3015 figured_bass_modification:
3017 $$ = ly_symbol2scm ("augmented");
3020 $$ = ly_symbol2scm ("no-continuation");
3023 $$ = ly_symbol2scm ("diminished");
3026 $$ = ly_symbol2scm ("augmented-slash");
3036 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3044 | figure_list br_bass_figure {
3045 $$ = scm_cons ($2, $1);
3050 FIGURE_OPEN figure_list FIGURE_CLOSE {
3051 $$ = scm_reverse_x ($2, SCM_EOL);
3057 /**/ { $$ = SCM_BOOL_F; }
3058 | REST { $$ = SCM_BOOL_T; }
3062 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3063 if (!parser->lexer_->is_note_state ())
3064 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3065 if (!SCM_UNBNDP ($2)
3067 || scm_is_number ($4)
3070 || scm_is_pair ($7))
3073 if (scm_is_true ($6))
3074 n = MY_MAKE_MUSIC ("RestEvent", @$);
3076 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3078 n->set_property ("pitch", $1);
3079 if (SCM_UNBNDP ($5))
3080 n->set_property ("duration",
3081 parser->default_duration_.smobbed_copy ());
3083 n->set_property ("duration", $5);
3085 if (scm_is_number ($4))
3087 int q = scm_to_int ($4);
3088 n->set_property ("absolute-octave", scm_from_int (q-1));
3091 if (to_boolean ($3))
3092 n->set_property ("cautionary", SCM_BOOL_T);
3093 if (to_boolean ($2) || to_boolean ($3))
3094 n->set_property ("force-accidental", SCM_BOOL_T);
3095 if (scm_is_pair ($7))
3096 n->set_property ("articulations",
3097 scm_reverse_x ($7, SCM_EOL));
3098 $$ = n->unprotect ();
3101 | simple_chord_elements post_events {
3102 if (scm_is_pair ($2)) {
3103 if (unsmob_pitch ($1))
3104 $1 = make_chord_elements (@1,
3106 parser->default_duration_.smobbed_copy (),
3109 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3111 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
3112 } else if (!unsmob_pitch ($1))
3113 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
3114 // A mere pitch drops through.
3119 DRUM_PITCH optional_notemode_duration {
3120 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3121 n->set_property ("duration", $2);
3122 n->set_property ("drum-type", $1);
3124 $$ = n->unprotect ();
3126 | RESTNAME optional_notemode_duration {
3128 if (ly_scm2string ($1) == "s") {
3130 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3133 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3136 ev->set_property ("duration", $2);
3137 $$ = ev->unprotect ();
3141 // Can return a single pitch rather than a list.
3142 simple_chord_elements:
3144 if (!parser->lexer_->is_chord_state ())
3145 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3148 | figure_spec optional_notemode_duration {
3149 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3151 unsmob_music (scm_car (s))->set_property ("duration", $2);
3159 if (!parser->lexer_->is_lyric_state ())
3160 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3164 if (!parser->lexer_->is_lyric_state ())
3165 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3171 lyric_element_music:
3172 lyric_element optional_notemode_duration post_events {
3173 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3174 if (scm_is_pair ($3))
3175 unsmob_music ($$)->set_property
3176 ("articulations", scm_reverse_x ($3, SCM_EOL));
3180 // Can return a single pitch rather than a list.
3182 steno_tonic_pitch maybe_notemode_duration {
3183 if (SCM_UNBNDP ($2))
3186 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3188 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3189 SCM its = scm_reverse_x ($4, SCM_EOL);
3190 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3198 | chord_items chord_item {
3199 $$ = scm_cons ($2, $$);
3205 $$ = ly_symbol2scm ("chord-colon");
3208 $$ = ly_symbol2scm ("chord-caret");
3210 | CHORD_SLASH steno_tonic_pitch {
3211 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3213 | CHORD_BASS steno_tonic_pitch {
3214 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3223 $$ = scm_reverse_x ($1, SCM_EOL);
3231 step_number { $$ = scm_cons ($1, SCM_EOL); }
3232 | step_numbers '.' step_number {
3233 $$ = scm_cons ($3, $$);
3239 $$ = make_chord_step ($1, 0);
3242 $$ = make_chord_step ($1, SHARP_ALTERATION);
3244 | UNSIGNED CHORD_MINUS {
3245 $$ = make_chord_step ($1, FLAT_ALTERATION);
3253 | unsigned_number '-' unsigned_number {
3254 $$ = scm_cons ($1, $3);
3261 TODO: should deprecate in favor of Scheme?
3265 number_expression '+' number_term {
3266 $$ = scm_sum ($1, $3);
3268 | number_expression '-' number_term {
3269 $$ = scm_difference ($1, $3);
3278 | number_factor '*' number_factor {
3279 $$ = scm_product ($1, $3);
3281 | number_factor '/' number_factor {
3282 $$ = scm_divide ($1, $3);
3287 '-' number_factor { /* %prec UNARY_MINUS */
3288 $$ = scm_difference ($2, SCM_UNDEFINED);
3296 | REAL NUMBER_IDENTIFIER
3298 $$ = scm_product ($1, $2);
3305 | UNSIGNED NUMBER_IDENTIFIER {
3306 $$ = scm_product ($1, $2);
3314 if (!scm_is_integer ($1)
3315 || scm_is_true (scm_negative_p ($1)))
3317 parser->parser_error (@1, _("not an unsigned integer"));
3323 if (!scm_is_integer ($1)
3324 || scm_is_true (scm_negative_p ($1)))
3326 parser->parser_error (@1, _("not an unsigned integer"));
3333 { $$ = SCM_UNDEFINED; }
3336 if (SCM_UNBNDP ($1))
3344 // This precedence rule is rather weird. It triggers when '!' is
3345 // encountered after a pitch, and is used for deciding whether to save
3346 // this instead for a figure modification. This should not actually
3347 // occur in practice as pitches and figures are generated in different
3348 // modes. Using a greedy (%right) precedence makes sure that we don't
3349 // get stuck in a wrong interpretation.
3350 { $$ = SCM_UNDEFINED; } %prec ':'
3353 if (SCM_UNBNDP ($1))
3362 { parser->lexer_->push_markup_state (); }
3365 parser->lexer_->pop_state ();
3371 { parser->lexer_->push_markup_state (); }
3374 parser->lexer_->pop_state ();
3380 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3382 | markup_head_1_list simple_markup
3384 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3385 @2, $1, scm_list_1 ($2)));
3395 if (Text_interface::is_markup ($1))
3396 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3397 else if (Text_interface::is_markup_list ($1))
3398 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3400 parser->parser_error (@1, _ ("not a markup"));
3401 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3408 markup_composed_list {
3411 | markup_uncomposed_list
3414 markup_uncomposed_list:
3415 markup_braced_list {
3418 | markup_command_list {
3419 $$ = scm_list_1 ($1);
3421 | markup_scm MARKUPLIST_IDENTIFIER
3426 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3427 parser->lexer_->push_note_state (nn);
3428 } '{' score_body '}' {
3429 unsmob_score ($4)->origin ()->set_spot (@$);
3430 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3431 parser->lexer_->pop_state ();
3435 markup_composed_list:
3436 markup_head_1_list markup_uncomposed_list {
3437 $$ = MAKE_SYNTAX ("composed-markup-list",
3443 '{' markup_braced_list_body '}' {
3444 $$ = scm_reverse_x ($2, SCM_EOL);
3448 markup_braced_list_body:
3449 /* empty */ { $$ = SCM_EOL; }
3450 | markup_braced_list_body markup {
3451 $$ = scm_cons ($2, $1);
3453 | markup_braced_list_body markup_list {
3454 $$ = scm_reverse_x ($2, $1);
3458 markup_command_list:
3459 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3460 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3464 markup_command_basic_arguments:
3465 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3466 $$ = scm_cons ($3, $2);
3468 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3469 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3471 | EXPECT_NO_MORE_ARGS {
3476 markup_command_list_arguments:
3477 markup_command_basic_arguments { $$ = $1; }
3478 | EXPECT_MARKUP markup_command_list_arguments markup {
3479 $$ = scm_cons ($3, $2);
3484 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3485 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3490 markup_head_1_item {
3491 $$ = scm_list_1 ($1);
3493 | markup_head_1_list markup_head_1_item {
3494 $$ = scm_cons ($2, $1);
3500 $$ = make_simple_markup ($1);
3503 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3504 parser->lexer_->push_note_state (nn);
3505 } '{' score_body '}' {
3506 unsmob_score ($4)->origin ()->set_spot (@$);
3507 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3508 parser->lexer_->pop_state ();
3510 | MARKUP_FUNCTION markup_command_basic_arguments {
3511 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3513 | markup_scm MARKUP_IDENTIFIER
3520 markup_head_1_list simple_markup
3522 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3523 @2, $1, scm_list_1 ($2)));
3533 Lily_parser::set_yydebug (bool x)
3539 Lily_parser::do_yyparse ()
3541 SCM retval = SCM_UNDEFINED;
3542 yyparse (this, &retval);
3552 It is a little strange to have this function in this file, but
3553 otherwise, we have to import music classes into the lexer.
3557 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3559 if (unsmob_book (sid)) {
3560 Book *book = unsmob_book (sid)->clone ();
3561 *destination = book->self_scm ();
3564 return BOOK_IDENTIFIER;
3565 } else if (scm_is_number (sid)) {
3567 return NUMBER_IDENTIFIER;
3568 } else if (unsmob_context_def (sid)) {
3569 Context_def *def= unsmob_context_def (sid)->clone ();
3571 *destination = def->self_scm ();
3574 return CONTEXT_DEF_IDENTIFIER;
3575 } else if (unsmob_context_mod (sid)) {
3576 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3578 return CONTEXT_MOD_IDENTIFIER;
3579 } else if (Music *mus = unsmob_music (sid)) {
3580 mus = mus->clone ();
3581 *destination = mus->self_scm ();
3582 bool is_event = mus->is_mus_type ("post-event");
3584 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3585 } else if (unsmob_pitch (sid)) {
3586 *destination = unsmob_pitch (sid)->smobbed_copy ();
3587 return PITCH_IDENTIFIER;
3588 } else if (unsmob_duration (sid)) {
3589 *destination = unsmob_duration (sid)->smobbed_copy ();
3590 return DURATION_IDENTIFIER;
3591 } else if (unsmob_output_def (sid)) {
3592 Output_def *p = unsmob_output_def (sid);
3595 *destination = p->self_scm ();
3597 return OUTPUT_DEF_IDENTIFIER;
3598 } else if (unsmob_score (sid)) {
3599 *destination = unsmob_score (sid)->clone ()->unprotect ();
3600 return SCM_IDENTIFIER;
3607 get_next_unique_context_id ()
3609 return scm_from_locale_string ("$uniqueContextId");
3614 get_next_unique_lyrics_context_id ()
3616 static int new_context_count;
3618 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3619 return scm_from_locale_string (s);
3622 // check_scheme_arg checks one argument with a given predicate for use
3623 // in an argument list and throws a syntax error if it is unusable.
3624 // The argument is prepended to the argument list in any case. After
3625 // throwing a syntax error, the argument list is terminated with #f as
3626 // its last cdr in order to mark it as uncallable while not losing
3627 // track of its total length.
3629 // There are a few special considerations: if optional argument disp
3630 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3631 // instead of arg in a prospective error message. This is useful if
3632 // arg is not the actual argument but rather a transformation of it.
3634 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3635 // and an error message using disp is produced unconditionally.
3637 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3638 SCM arg, SCM args, SCM pred, SCM disp)
3640 if (SCM_UNBNDP (arg))
3641 args = scm_cons (disp, args);
3643 args = scm_cons (arg, args);
3644 if (scm_is_true (scm_call_1 (pred, arg)))
3647 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3648 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3649 SCM_UNBNDP (disp) ? arg : disp);
3650 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3654 SCM loc_on_music (Input loc, SCM arg)
3656 if (Music *m = unsmob_music (arg))
3660 return m->unprotect ();
3666 try_string_variants (SCM pred, SCM str)
3668 // a matching predicate is always ok
3669 if (scm_is_true (scm_call_1 (pred, str)))
3671 // a symbol may be interpreted as a list of symbols if it helps
3672 if (scm_is_symbol (str)) {
3673 str = scm_list_1 (str);
3674 if (scm_is_true (scm_call_1 (pred, str)))
3676 return SCM_UNDEFINED;
3679 // If this cannot be a string representation of a symbol list,
3682 if (!is_regular_identifier (str, true))
3683 return SCM_UNDEFINED;
3685 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3686 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3687 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3689 // Let's attempt the symbol list interpretation first.
3691 if (scm_is_true (scm_call_1 (pred, str)))
3694 // If there is just one symbol in the list, we might interpret
3695 // it as a single symbol
3697 if (scm_is_null (scm_cdr (str)))
3699 str = scm_car (str);
3700 if (scm_is_true (scm_call_1 (pred, str)))
3704 return SCM_UNDEFINED;
3708 is_regular_identifier (SCM id, bool multiple)
3710 if (!scm_is_string (id))
3713 string str = ly_scm2string (id);
3715 bool middle = false;
3717 for (string::iterator it=str.begin(); it != str.end (); it++)
3720 if ((c >= 'a' && c <= 'z')
3721 || (c >= 'A' && c <= 'Z')
3724 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3733 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3735 if (unsmob_music (simple))
3737 if (parser->lexer_->is_note_state ()) {
3738 if (scm_is_symbol (simple)) {
3739 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3740 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3741 n->set_property ("drum-type", simple);
3742 return n->unprotect ();
3744 if (unsmob_pitch (simple)) {
3745 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3746 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3747 n->set_property ("pitch", simple);
3748 return n->unprotect ();
3751 } else if (parser->lexer_->is_lyric_state ()) {
3752 if (Text_interface::is_markup (simple))
3753 return MAKE_SYNTAX ("lyric-event", loc, simple,
3754 parser->default_duration_.smobbed_copy ());
3755 } else if (parser->lexer_->is_chord_state ()) {
3756 if (unsmob_pitch (simple))
3760 make_chord_elements (loc, simple,
3761 parser->default_duration_.smobbed_copy (),
3768 make_music_with_input (SCM name, Input where)
3770 Music *m = make_music_by_name (name);
3771 m->set_spot (where);
3776 make_simple_markup (SCM a)
3782 make_duration (SCM d, int dots)
3784 int t = scm_to_int (d);
3785 if (t > 0 && (t & (t-1)) == 0)
3786 return Duration (intlog2 (t), dots).smobbed_copy ();
3788 return SCM_UNDEFINED;
3792 make_chord_step (SCM step_scm, Rational alter)
3794 int step = scm_to_int (step_scm);
3797 alter += FLAT_ALTERATION;
3801 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3802 return m.smobbed_copy ();
3807 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3809 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3810 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3811 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3813 unsmob_music (scm_car (s))->set_spot (loc);
3819 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3821 Lily_lexer *lex = parser->lexer_;
3825 int tok = lex->pop_extra_token ();
3828 lex->prepare_for_next_token ();
3829 return lex->yylex ();