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--2014 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 SCM s = scm_call_2 (ly_lily_module_constant ("value->lily-string"), \
46 parser->self_scm ()); \
47 char *p = scm_to_locale_string (s); \
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
356 %token SCM_IDENTIFIER
360 %token TONICNAME_PITCH
364 /* We don't assign precedence to / and *, because we might need varied
365 prec levels in different prods */
374 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
375 parser->lexer_->push_note_state (nn);
376 } embedded_lilypond {
377 parser->lexer_->pop_state ();
382 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
383 | lilypond toplevel_expression {
385 | lilypond assignment {
388 parser->error_level_ = 1;
391 parser->error_level_ = 1;
398 parser->lexer_->add_scope (get_header (parser));
400 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
403 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
404 scm_call_2 (proc, parser->self_scm (), $1);
407 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
408 scm_call_2 (proc, parser->self_scm (), $1);
411 SCM proc = parser->lexer_->lookup_identifier
412 (unsmob_book($1)->paper_
413 ? "toplevel-book-handler"
414 : "toplevel-bookpart-handler");
415 scm_call_2 (proc, parser->self_scm (), $1);
418 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
419 scm_call_2 (proc, parser->self_scm (), $1);
422 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
423 scm_call_2 (proc, parser->self_scm (), $1);
426 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
427 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
430 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
431 scm_call_2 (proc, parser->self_scm (), $1);
434 // Evaluate and ignore #xxx, as opposed to \xxx
435 parser->lexer_->eval_scm_token ($1, @1);
437 | embedded_scm_active
439 SCM out = SCM_UNDEFINED;
440 if (Text_interface::is_markup ($1))
441 out = scm_list_1 ($1);
442 else if (Text_interface::is_markup_list ($1))
444 if (scm_is_pair (out))
446 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
447 scm_call_2 (proc, parser->self_scm (), out);
448 } else if (unsmob_score ($1))
450 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
451 scm_call_2 (proc, parser->self_scm (), $1);
452 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
453 parser->parser_error (@1, _("bad expression type"));
457 Output_def * od = unsmob_output_def ($1);
459 if (od->c_variable ("is-paper") == SCM_BOOL_T)
460 id = ly_symbol2scm ("$defaultpaper");
461 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
462 id = ly_symbol2scm ("$defaultmidi");
463 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
464 id = ly_symbol2scm ("$defaultlayout");
466 parser->lexer_->set_identifier (id, $1);
473 $$ = parser->lexer_->eval_scm_token ($1, @1);
483 embedded_scm_bare_arg:
487 $$ = parser->lexer_->eval_scm_token ($1, @1);
491 | context_modification
493 | context_def_spec_block
499 /* The generic version may end in music, or not */
506 /* embedded_scm_arg is _not_ casting pitches to music by default, this
507 * has to be done by the function itself. Note that this may cause
508 * the results of scm_function_call or embedded_scm_bare_arg to be
509 * turned into music from pitches as well. Note that this creates a
510 * distinctly awkward situation for calculated drum pitches. Those
511 * are at the current point of time rejected as music constituents as
512 * they can't be distinguished from "proper" symbols.
516 embedded_scm_bare_arg
522 SCM_FUNCTION function_arglist {
523 $$ = MAKE_SYNTAX ("music-function", @$,
528 embedded_lilypond_number:
529 '-' embedded_lilypond_number
531 $$ = scm_difference ($2, SCM_UNDEFINED);
534 | UNSIGNED NUMBER_IDENTIFIER
536 $$ = scm_product ($1, $2);
543 // FIXME: @$ does not contain a useful source location
544 // for empty rules, and the only token in the whole
545 // production, EMBEDDED_LILY, is synthetic and also
546 // contains no source location.
547 $$ = MAKE_SYNTAX ("void-music", @$);
549 | identifier_init_nonumber
550 | embedded_lilypond_number
551 | post_event post_events
553 $$ = scm_reverse_x ($2, SCM_EOL);
554 if (Music *m = unsmob_music ($1))
556 if (m->is_mus_type ("post-event-wrapper"))
558 (scm_list_2 (m->get_property ("elements"),
561 $$ = scm_cons ($1, $$);
564 && scm_is_null (scm_cdr ($$)))
568 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
569 m->set_property ("elements", $$);
570 $$ = m->unprotect ();
573 | multiplied_duration
574 | music_embedded music_embedded music_list {
575 $3 = scm_reverse_x ($3, SCM_EOL);
576 if (unsmob_music ($2))
577 $3 = scm_cons ($2, $3);
578 if (unsmob_music ($1))
579 $3 = scm_cons ($1, $3);
580 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
583 parser->error_level_ = 1;
584 $$ = SCM_UNSPECIFIED;
586 | INVALID embedded_lilypond {
587 parser->error_level_ = 1;
593 lilypond_header_body:
594 /* empty */ { $$ = SCM_UNSPECIFIED; }
595 | lilypond_header_body assignment {
598 | lilypond_header_body embedded_scm {
604 HEADER '{' lilypond_header_body '}' {
605 $$ = parser->lexer_->remove_scope ();
617 assignment_id '=' identifier_init {
618 parser->lexer_->set_identifier ($1, $3);
619 $$ = SCM_UNSPECIFIED;
621 | assignment_id property_path '=' identifier_init {
622 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
623 parser->lexer_->set_identifier (path, $4);
624 $$ = SCM_UNSPECIFIED;
626 | assignment_id '.' property_path '=' identifier_init {
627 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
628 parser->lexer_->set_identifier (path, $5);
629 $$ = SCM_UNSPECIFIED;
635 identifier_init_nonumber
637 | post_event_nofinger post_events
639 $$ = scm_reverse_x ($2, SCM_EOL);
640 if (Music *m = unsmob_music ($1))
642 if (m->is_mus_type ("post-event-wrapper"))
644 (scm_list_2 (m->get_property ("elements"),
647 $$ = scm_cons ($1, $$);
650 && scm_is_null (scm_cdr ($$)))
654 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
655 m->set_property ("elements", $$);
656 $$ = m->unprotect ();
661 identifier_init_nonumber:
666 | context_def_spec_block
673 | context_modification
676 context_def_spec_block:
677 CONTEXT '{' context_def_spec_body '}'
680 unsmob_context_def ($$)->origin ()->set_spot (@$);
688 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
689 parser->lexer_->push_note_state (nn);
693 parser->lexer_->pop_state ();
698 context_mod_embedded:
701 if (unsmob_music ($1)) {
702 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
703 $1 = scm_call_2 (proc, parser->self_scm (), $1);
705 if (unsmob_context_mod ($1))
708 parser->parser_error (@1, _ ("not a context mod"));
709 $$ = Context_mod ().smobbed_copy ();
715 context_def_spec_body:
717 $$ = Context_def::make_scm ();
719 | CONTEXT_DEF_IDENTIFIER {
722 | context_def_spec_body context_mod {
723 if (!SCM_UNBNDP ($2))
724 unsmob_context_def ($$)->add_context_mod ($2);
726 | context_def_spec_body context_modification {
727 Context_def *td = unsmob_context_def ($$);
728 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
729 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
730 td->add_context_mod (scm_car (m));
733 | context_def_spec_body context_mod_embedded {
734 Context_def *td = unsmob_context_def ($$);
735 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
736 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
737 td->add_context_mod (scm_car (m));
745 BOOK '{' book_body '}' {
747 unsmob_book ($$)->origin ()->set_spot (@$);
749 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
754 * Use 'handlers' like for toplevel-* stuff?
755 * grok \layout and \midi? */
758 Book *book = new Book;
759 init_papers (parser);
760 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
761 book->paper_->unprotect ();
762 push_paper (parser, book->paper_);
763 book->header_ = get_header (parser);
764 $$ = book->unprotect ();
765 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
768 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
770 | book_body paper_block {
771 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
772 set_paper (parser, unsmob_output_def ($2));
774 | book_body bookpart_block {
775 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
776 scm_call_2 (proc, $1, $2);
778 | book_body score_block {
779 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
780 scm_call_2 (proc, $1, $2);
782 | book_body composite_music {
783 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
784 scm_call_3 (proc, parser->self_scm (), $1, $2);
786 | book_body full_markup {
787 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
788 scm_call_2 (proc, $1, scm_list_1 ($2));
790 | book_body full_markup_list {
791 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
792 scm_call_2 (proc, $1, $2);
794 | book_body SCM_TOKEN {
795 // Evaluate and ignore #xxx, as opposed to \xxx
796 parser->lexer_->eval_scm_token ($2, @2);
798 | book_body embedded_scm_active
800 SCM out = SCM_UNDEFINED;
801 if (Text_interface::is_markup ($2))
802 out = scm_list_1 ($2);
803 else if (Text_interface::is_markup_list ($2))
805 if (scm_is_pair (out))
807 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
808 scm_call_2 (proc, $1, out);
809 } else if (unsmob_score ($2))
811 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
812 scm_call_2 (proc, $1, $2);
813 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
814 parser->parser_error (@2, _("bad expression type"));
818 parser->lexer_->add_scope (unsmob_book ($1)->header_);
821 Book *book = unsmob_book ($1);
823 book->scores_ = SCM_EOL;
824 book->bookparts_ = SCM_EOL;
829 BOOKPART '{' bookpart_body '}' {
831 unsmob_book ($$)->origin ()->set_spot (@$);
832 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
838 Book *book = new Book;
839 $$ = book->unprotect ();
840 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
843 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
845 | bookpart_body paper_block {
846 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
848 | bookpart_body score_block {
849 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
850 scm_call_2 (proc, $1, $2);
852 | bookpart_body composite_music {
853 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
854 scm_call_3 (proc, parser->self_scm (), $1, $2);
856 | bookpart_body full_markup {
857 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
858 scm_call_2 (proc, $1, scm_list_1 ($2));
860 | bookpart_body full_markup_list {
861 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
862 scm_call_2 (proc, $1, $2);
864 | bookpart_body SCM_TOKEN {
865 // Evaluate and ignore #xxx, as opposed to \xxx
866 parser->lexer_->eval_scm_token ($2, @2);
868 | bookpart_body embedded_scm_active
870 SCM out = SCM_UNDEFINED;
871 if (Text_interface::is_markup ($2))
872 out = scm_list_1 ($2);
873 else if (Text_interface::is_markup_list ($2))
875 if (scm_is_pair (out))
877 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
878 scm_call_2 (proc, $1, out);
879 } else if (unsmob_score ($2))
881 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
882 scm_call_2 (proc, $1, $2);
883 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
884 parser->parser_error (@2, _("bad expression type"));
888 Book *book = unsmob_book ($1);
889 if (!ly_is_module (book->header_))
890 book->header_ = ly_make_module (false);
891 parser->lexer_->add_scope (book->header_);
893 | bookpart_body error {
894 Book *book = unsmob_book ($1);
896 book->scores_ = SCM_EOL;
901 SCORE '{' score_body '}' {
902 unsmob_score ($3)->origin ()->set_spot (@$);
914 if (!scm_is_pair ($1)
915 || !ly_is_module (scm_car ($1)))
916 $1 = scm_cons (ly_make_module (false), $1);
917 parser->lexer_->add_scope (scm_car ($1));
922 | score_headers output_def
924 Output_def *od = unsmob_output_def ($2);
925 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
927 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
932 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
933 scm_set_cdr_x ($1, scm_cons ($2, scm_cdr ($1)));
935 $$ = scm_cons ($2, $1);
943 score_headers music {
944 SCM scorify = ly_lily_module_constant ("scorify-music");
945 $$ = scm_call_2 (scorify, $2, parser->self_scm ());
947 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
949 unsmob_score ($$)->set_header (scm_car ($1));
952 for (SCM p = scm_reverse_x ($1, SCM_EOL);
953 scm_is_pair (p); p = scm_cdr (p))
956 add_output_def (unsmob_output_def (scm_car (p)));
959 | embedded_scm_active {
960 if (!unsmob_score ($1))
962 $$ = (new Score)->unprotect ();
963 parser->parser_error (@1, _("score expected"));
968 Score *score = unsmob_score ($1);
969 if (!ly_is_module (score->get_header ()))
970 score->set_header (ly_make_module (false));
971 parser->lexer_->add_scope (score->get_header ());
973 | score_body output_def {
974 Output_def *od = unsmob_output_def ($2);
975 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
977 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
982 unsmob_score ($1)->add_output_def (od);
986 unsmob_score ($$)->error_found_ = true;
997 Output_def *od = unsmob_output_def ($1);
999 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1001 parser->parser_error (@1, _ ("need \\paper for paper block"));
1002 $$ = get_paper (parser)->unprotect ();
1009 output_def_body '}' {
1010 if (scm_is_pair ($1))
1013 parser->lexer_->remove_scope ();
1014 parser->lexer_->pop_state ();
1020 Output_def *p = get_paper (parser);
1021 p->input_origin_ = @$;
1022 parser->lexer_->add_scope (p->scope_);
1023 $$ = p->unprotect ();
1026 Output_def *p = get_midi (parser);
1027 $$ = p->unprotect ();
1028 parser->lexer_->add_scope (p->scope_);
1031 Output_def *p = get_layout (parser);
1033 parser->lexer_->add_scope (p->scope_);
1034 $$ = p->unprotect ();
1038 output_def_head_with_mode_switch:
1040 parser->lexer_->push_initial_state ();
1045 // We need this weird nonterminal because both music as well as a
1046 // context definition can start with \context and the difference is
1047 // only apparent after looking at the next token. If it is '{', there
1048 // is still time to escape from notes mode.
1050 music_or_context_def:
1052 | context_def_spec_block
1056 output_def_head_with_mode_switch '{' {
1057 unsmob_output_def ($1)->input_origin_.set_spot (@$);
1058 // This is a stupid trick to mark the beginning of the
1059 // body for deciding whether to allow
1060 // embedded_scm_active to have an output definition
1061 $$ = scm_list_1 ($1);
1063 | output_def_body assignment {
1064 if (scm_is_pair ($1))
1067 | output_def_body embedded_scm_active
1069 // We don't switch into note mode for Scheme functions
1070 // here. Does not seem warranted/required in output
1072 if (scm_is_pair ($1))
1074 Output_def *o = unsmob_output_def ($2);
1076 o->input_origin_.set_spot (@$);
1077 $1 = o->self_scm ();
1078 parser->lexer_->remove_scope ();
1079 parser->lexer_->add_scope (o->scope_);
1080 $2 = SCM_UNSPECIFIED;
1084 if (unsmob_context_def ($2))
1085 assign_context_def (unsmob_output_def ($1), $2);
1086 // Seems unlikely, but let's be complete:
1087 else if (unsmob_music ($2))
1089 SCM proc = parser->lexer_->lookup_identifier
1090 ("output-def-music-handler");
1091 scm_call_3 (proc, parser->self_scm (),
1093 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1094 parser->parser_error (@2, _("bad expression type"));
1097 | output_def_body SCM_TOKEN {
1098 if (scm_is_pair ($1))
1100 // Evaluate and ignore #xxx, as opposed to \xxx
1101 parser->lexer_->eval_scm_token ($2, @2);
1105 if (scm_is_pair ($1))
1107 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1108 parser->lexer_->push_note_state (nn);
1109 } music_or_context_def
1111 parser->lexer_->pop_state ();
1112 if (unsmob_context_def ($3))
1113 assign_context_def (unsmob_output_def ($1), $3);
1116 SCM proc = parser->lexer_->lookup_identifier
1117 ("output-def-music-handler");
1118 scm_call_3 (proc, parser->self_scm (),
1123 | output_def_body error {
1129 TEMPO steno_duration '=' tempo_range {
1130 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1132 | TEMPO scalar steno_duration '=' tempo_range {
1133 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1136 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1141 The representation of a list is reversed to have efficient append. */
1147 | music_list music_embedded {
1148 if (unsmob_music ($2))
1149 $$ = scm_cons ($2, $1);
1151 | music_list error {
1152 Music *m = MY_MAKE_MUSIC("Music", @$);
1154 m->set_property ("error-found", SCM_BOOL_T);
1155 $$ = scm_cons (m->self_scm (), $1);
1156 m->unprotect (); /* UGH */
1163 $$ = scm_reverse_x ($2, SCM_EOL);
1168 | lyric_element_music
1171 $$ = make_music_from_simple (parser, @1, $1);
1172 if (!unsmob_music ($$))
1174 parser->parser_error (@1, _ ("music expected"));
1175 $$ = MAKE_SYNTAX ("void-music", @$);
1183 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1184 parser->parser_error (@1, _ ("unexpected post-event"));
1185 $$ = SCM_UNSPECIFIED;
1188 | music_embedded_backup
1192 | music_embedded_backup BACKUP lyric_element_music
1196 | multiplied_duration post_events
1198 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1200 parser->default_duration_ = *unsmob_duration ($1);
1201 n->set_property ("duration", $1);
1203 if (scm_is_pair ($2))
1204 n->set_property ("articulations",
1205 scm_reverse_x ($2, SCM_EOL));
1206 $$ = n->unprotect ();
1210 music_embedded_backup:
1213 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1215 else if (Music *m = unsmob_music ($1)) {
1216 if (m->is_mus_type ("post-event")) {
1217 parser->parser_error
1218 (@1, _ ("unexpected post-event"));
1219 $$ = SCM_UNSPECIFIED;
1222 } else if (parser->lexer_->is_lyric_state ()
1223 && Text_interface::is_markup ($1))
1224 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1226 @$.warning (_ ("Ignoring non-music expression"));
1232 // music_assign does not need to contain lyrics: there are no
1233 // assignments in lyricmode.
1236 | composite_music %prec COMPOSITE
1240 REPEAT simple_string unsigned_number music
1242 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1244 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1246 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1251 SEQUENTIAL braced_music_list {
1252 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1254 | braced_music_list {
1255 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1260 SIMULTANEOUS braced_music_list {
1261 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1263 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1264 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1270 | music_property_def
1274 context_modification:
1277 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1278 parser->lexer_->push_note_state (nn);
1279 } '{' context_mod_list '}'
1281 parser->lexer_->pop_state ();
1284 | WITH CONTEXT_MOD_IDENTIFIER
1288 | CONTEXT_MOD_IDENTIFIER
1292 | WITH context_modification_arg
1294 if (unsmob_music ($2)) {
1295 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1296 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1298 if (unsmob_context_mod ($2))
1301 parser->parser_error (@2, _ ("not a context mod"));
1302 $$ = Context_mod ().smobbed_copy ();
1307 context_modification_arg:
1312 optional_context_mod:
1316 | context_modification
1324 $$ = Context_mod ().smobbed_copy ();
1326 | context_mod_list context_mod {
1327 if (!SCM_UNBNDP ($2))
1328 unsmob_context_mod ($1)->add_context_mod ($2);
1330 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1331 Context_mod *md = unsmob_context_mod ($2);
1333 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1335 | context_mod_list context_mod_embedded {
1336 unsmob_context_mod ($1)->add_context_mods
1337 (unsmob_context_mod ($2)->get_mods ());
1349 | grouped_music_list
1353 simultaneous_music { $$ = $1; }
1354 | sequential_music { $$ = $1; }
1357 /* Function argument lists are arguably the most complex part in the
1358 * parser. They are pretty tricky to understand because of the way
1359 * they are processed, and because of optional arguments that can be
1360 * omitted. When there are several optional arguments in a row,
1361 * omitting one automatically omits all following arguments. Optional
1362 * arguments can only be omitted when either
1364 * a) the omission is explicitly started with \default
1365 * b) the omission is implicitly started by an argument not matching
1366 * its predicate, and there is a mandatory argument later that can
1367 * "catch" the argument that does not fit.
1369 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1370 * (corresponding to mandatory arguments and having a predicate
1371 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1372 * the semantic value of the EXPECT_OPTIONAL token is the default to
1373 * use when the optional argument is omitted, and EXPECT_SCM again has
1374 * the argument predicate as semantic value) in reverse order to the
1375 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1376 * processed inside-out while actual tokens are consumed.
1378 * This means that the argument list tokens determine the actions
1379 * taken as they arrive. The structure of the argument list is known
1380 * to the parser and stored in its parse stack when the first argument
1381 * is being parsed. What the parser does not know is which predicates
1382 * will match and whether or not \default will be appearing in the
1383 * argument list, and where.
1385 * Sequences of 0 or more optional arguments are scanned using either
1386 * function_arglist_backup or function_arglist_nonbackup. The first
1387 * is used when optional arguments are followed by at least one
1388 * mandatory argument: in that case optional arguments may be skipped
1389 * by either a false predicate (in which case the expression will be
1390 * pushed back as one or more tokens, preceded by a BACKUP token) or
1391 * by using \default.
1393 * If optional arguments are at the end of the argument list, they are
1394 * instead scanned using function_arglist_nonbackup: here the only
1395 * manner to enter into skipping of optional arguments is the use of
1398 * The argument list of a normal function call is parsed using
1399 * function_arglist. The part of an argument list before a mandatory
1400 * argument is parsed using function_arglist_optional.
1402 * The difference is that leading optional arguments are scanned using
1403 * function_arglist_nonbackup and function_arglist_backup,
1406 * Most other details are obvious in the rules themselves.
1412 | SYMBOL_LIST '.' symbol_list_rev
1414 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1420 | symbol_list_rev '.' symbol_list_part
1422 $$ = scm_append_x (scm_list_2 ($3, $1));
1426 // symbol_list_part delivers elements in reverse copy.
1431 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1432 $$ = try_string_variants (sym_l_p, $1);
1433 if (SCM_UNBNDP ($$)) {
1434 parser->parser_error (@1, _("not a symbol"));
1437 $$ = scm_reverse ($$);
1442 symbol_list_element:
1448 function_arglist_nonbackup:
1449 function_arglist_common
1450 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1452 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1454 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1456 SCM n = scm_difference ($5, SCM_UNDEFINED);
1457 if (scm_is_true (scm_call_1 ($2, n)))
1458 $$ = scm_cons (n, $3);
1460 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1461 t->set_property ("digit", $5);
1462 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1467 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1469 $$ = check_scheme_arg (parser, @4,
1470 scm_difference ($5, SCM_UNDEFINED),
1473 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1475 $$ = check_scheme_arg (parser, @4,
1476 scm_difference ($5, SCM_UNDEFINED),
1479 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1481 if (scm_is_true (scm_call_1 ($2, $4)))
1482 $$ = scm_cons ($4, $3);
1484 $$ = check_scheme_arg (parser, @4,
1485 make_music_from_simple
1489 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1491 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1493 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1495 if (scm_is_true (scm_call_1 ($2, $3)))
1496 $$ = scm_cons ($3, $1);
1498 $$ = check_scheme_arg (parser, @3,
1499 make_music_from_simple
1503 | function_arglist_nonbackup_reparse REPARSE duration_length
1505 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1507 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1509 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1511 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1513 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1515 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1517 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1519 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1521 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1525 function_arglist_nonbackup_reparse:
1526 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1529 SCM res = try_string_variants ($2, $4);
1530 if (!SCM_UNBNDP (res))
1531 if (scm_is_pair (res))
1532 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1534 MYREPARSE (@4, $2, SCM_ARG, res);
1535 else if (scm_is_true
1537 ($2, make_music_from_simple
1539 MYREPARSE (@4, $2, STRING, $4);
1541 MYREPARSE (@4, $2, SCM_ARG, $4);
1543 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1548 ($2, make_music_from_simple
1550 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1552 MYREPARSE (@4, $2, SCM_ARG, $4);
1554 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1559 ($2, make_music_from_simple
1561 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1563 MYREPARSE (@4, $2, SCM_ARG, $4);
1565 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1568 SCM res = try_string_variants ($2, $4);
1569 if (!SCM_UNBNDP (res))
1570 if (scm_is_pair (res))
1571 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1573 MYREPARSE (@4, $2, SCM_ARG, res);
1574 else if (scm_is_true
1576 ($2, make_music_from_simple
1578 MYREPARSE (@4, $2, STRING, $4);
1580 MYREPARSE (@4, $2, SCM_ARG, $4);
1582 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1585 if (scm_is_true (scm_call_1 ($2, $4)))
1586 MYREPARSE (@4, $2, SCM_ARG, $4);
1587 else if (scm_is_true
1589 ($2, make_music_from_simple
1591 MYREPARSE (@4, $2, STRING, $4);
1593 MYREPARSE (@4, $2, SCM_ARG, $4);
1595 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1598 if (scm_is_true (scm_call_1 ($2, $4)))
1599 MYREPARSE (@4, $2, REAL, $4);
1601 SCM d = make_duration ($4);
1602 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1603 MYREPARSE (@4, $2, REAL, $4); // trigger error
1605 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1608 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1610 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1615 // function_arglist_backup can't occur at the end of an argument
1617 function_arglist_backup:
1618 function_arglist_common
1619 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1621 if (scm_is_true (scm_call_1 ($2, $4)))
1622 $$ = scm_cons ($4, $3);
1624 $$ = make_music_from_simple (parser, @4, $4);
1625 if (scm_is_true (scm_call_1 ($2, $$)))
1626 $$ = scm_cons ($$, $3);
1629 $$ = scm_cons (loc_on_music (@3, $1), $3);
1630 MYBACKUP (SCM_ARG, $4, @4);
1634 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1636 if (scm_is_true (scm_call_1 ($2, $4)))
1638 $$ = scm_cons ($4, $3);
1640 $$ = scm_cons (loc_on_music (@3, $1), $3);
1641 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1644 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1648 ($2, make_music_from_simple
1652 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1653 } else if (scm_is_true (scm_call_1 ($2, $4)))
1654 $$ = scm_cons ($4, $3);
1656 $$ = scm_cons (loc_on_music (@3, $1), $3);
1657 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1660 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1664 ($2, make_music_from_simple
1668 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1669 } else if (scm_is_true (scm_call_1 ($2, $4)))
1670 $$ = scm_cons ($4, $3);
1672 $$ = scm_cons (loc_on_music (@3, $1), $3);
1673 MYBACKUP (TONICNAME_PITCH, $4, @4);
1676 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1678 if (scm_is_true (scm_call_1 ($2, $4)))
1679 $$ = scm_cons ($4, $3);
1681 $$ = scm_cons (loc_on_music (@3, $1), $3);
1682 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1685 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1687 if (scm_is_true (scm_call_1 ($2, $4)))
1689 MYREPARSE (@4, $2, REAL, $4);
1692 SCM d = make_duration ($4);
1693 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1695 $$ = scm_cons (loc_on_music (@3, $1), $3);
1696 MYBACKUP (UNSIGNED, $4, @4);
1698 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1703 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1705 if (scm_is_true (scm_call_1 ($2, $4)))
1708 MYREPARSE (@4, $2, REAL, $4);
1710 $$ = scm_cons (loc_on_music (@3, $1), $3);
1711 MYBACKUP (REAL, $4, @4);
1714 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1716 if (scm_is_true (scm_call_1 ($2, $4)))
1718 $$ = scm_cons ($4, $3);
1720 $$ = scm_cons (loc_on_music (@3, $1), $3);
1721 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1724 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1726 SCM n = scm_difference ($5, SCM_UNDEFINED);
1727 if (scm_is_true (scm_call_1 ($2, n))) {
1729 MYREPARSE (@5, $2, REAL, n);
1731 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1732 t->set_property ("digit", $5);
1733 $$ = t->unprotect ();
1734 if (scm_is_true (scm_call_1 ($2, $$)))
1735 $$ = scm_cons ($$, $3);
1737 $$ = scm_cons (loc_on_music (@3, $1), $3);
1738 MYBACKUP (UNSIGNED, $5, @5);
1739 parser->lexer_->push_extra_token (@4, '-');
1744 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1746 SCM n = scm_difference ($5, SCM_UNDEFINED);
1747 if (scm_is_true (scm_call_1 ($2, n))) {
1748 MYREPARSE (@5, $2, REAL, n);
1751 $$ = scm_cons (loc_on_music (@3, $1), $3);
1752 MYBACKUP (REAL, n, @5);
1755 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1757 SCM n = scm_difference ($5, SCM_UNDEFINED);
1758 if (scm_is_true (scm_call_1 ($2, n))) {
1759 $$ = scm_cons (n, $3);
1761 $$ = scm_cons (loc_on_music (@3, $1), $3);
1762 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1765 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1767 if (scm_is_true (scm_call_1 ($2, $4)))
1769 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1772 $$ = scm_cons (loc_on_music (@3, $1), $3);
1773 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1776 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1778 SCM res = try_string_variants ($2, $4);
1779 if (!SCM_UNBNDP (res))
1780 if (scm_is_pair (res)) {
1782 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1785 $$ = scm_cons (res, $3);
1787 $$ = scm_cons (loc_on_music (@3, $1), $3);
1788 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1791 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1793 SCM res = try_string_variants ($2, $4);
1794 if (!SCM_UNBNDP (res))
1795 if (scm_is_pair (res)) {
1797 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1800 $$ = scm_cons (res, $3);
1802 $$ = scm_cons (loc_on_music (@3, $1), $3);
1803 MYBACKUP (STRING, $4, @4);
1806 | function_arglist_backup REPARSE pitch_or_music
1808 if (scm_is_true (scm_call_1 ($2, $3)))
1809 $$ = scm_cons ($3, $1);
1811 $$ = check_scheme_arg (parser, @3,
1812 make_music_from_simple
1816 | function_arglist_backup REPARSE bare_number_common
1818 $$ = check_scheme_arg (parser, @3,
1821 | function_arglist_backup REPARSE duration_length
1823 $$ = check_scheme_arg (parser, @3,
1826 | function_arglist_backup REPARSE symbol_list_arg
1828 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1833 function_arglist_nonbackup
1834 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1836 $$ = scm_cons (loc_on_music (@4, $1), $3);
1840 function_arglist_skip_nonbackup:
1841 function_arglist_nonbackup
1842 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1844 $$ = scm_cons (loc_on_music (@3, $1), $3);
1848 function_arglist_common:
1849 EXPECT_NO_MORE_ARGS {
1852 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1854 if (scm_is_true (scm_call_1 ($1, $3)))
1855 $$ = scm_cons ($3, $2);
1857 $$ = check_scheme_arg (parser, @3,
1858 make_music_from_simple
1862 | EXPECT_SCM function_arglist_optional bare_number_common
1864 $$ = check_scheme_arg (parser, @3,
1867 | EXPECT_SCM function_arglist_optional post_event_nofinger
1869 $$ = check_scheme_arg (parser, @3,
1872 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1874 SCM n = scm_difference ($4, SCM_UNDEFINED);
1875 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1877 | function_arglist_common_reparse REPARSE SCM_ARG
1879 $$ = check_scheme_arg (parser, @3,
1882 | function_arglist_common_reparse REPARSE lyric_element_music
1884 $$ = check_scheme_arg (parser, @3,
1887 | function_arglist_common_reparse REPARSE pitch_or_music
1889 if (scm_is_true (scm_call_1 ($2, $3)))
1890 $$ = scm_cons ($3, $1);
1892 $$ = check_scheme_arg (parser, @3,
1893 make_music_from_simple
1897 | function_arglist_common_reparse REPARSE bare_number_common
1899 $$ = check_scheme_arg (parser, @3,
1902 | function_arglist_common_reparse REPARSE duration_length
1904 $$ = check_scheme_arg (parser, @3,
1907 | function_arglist_common_reparse REPARSE symbol_list_arg
1909 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1913 function_arglist_common_reparse:
1914 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1917 SCM res = try_string_variants ($1, $3);
1918 if (!SCM_UNBNDP (res))
1919 if (scm_is_pair (res))
1920 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1922 MYREPARSE (@3, $1, SCM_ARG, res);
1923 else if (scm_is_true
1925 ($1, make_music_from_simple (parser, @3, $3))))
1926 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1928 // This is going to flag a syntax error, we
1929 // know the predicate to be false.
1930 MYREPARSE (@3, $1, SCM_ARG, $3);
1932 | EXPECT_SCM function_arglist_optional pitch
1937 ($1, make_music_from_simple
1939 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
1941 MYREPARSE (@3, $1, SCM_ARG, $3);
1943 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
1948 ($1, make_music_from_simple
1950 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
1952 MYREPARSE (@3, $1, SCM_ARG, $3);
1954 | EXPECT_SCM function_arglist_optional STRING
1957 SCM res = try_string_variants ($1, $3);
1958 if (!SCM_UNBNDP (res))
1959 if (scm_is_pair (res))
1960 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1962 MYREPARSE (@3, $1, SCM_ARG, res);
1963 else if (scm_is_true
1965 ($1, make_music_from_simple (parser, @3, $3))))
1966 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1968 // This is going to flag a syntax error, we
1969 // know the predicate to be false.
1970 MYREPARSE (@3, $1, SCM_ARG, $3);
1972 | EXPECT_SCM function_arglist_optional full_markup
1975 if (scm_is_true (scm_call_1 ($1, $3)))
1976 MYREPARSE (@3, $1, SCM_ARG, $3);
1977 else if (scm_is_true
1979 ($1, make_music_from_simple (parser, @3, $3))))
1980 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1982 // This is going to flag a syntax error, we
1983 // know the predicate to be false.
1984 MYREPARSE (@3, $1, SCM_ARG, $3);
1986 | EXPECT_SCM function_arglist_optional UNSIGNED
1989 if (scm_is_true (scm_call_1 ($1, $3)))
1990 MYREPARSE (@3, $1, REAL, $3);
1992 SCM d = make_duration ($3);
1993 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
1994 MYREPARSE (@3, $1, REAL, $3);
1996 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
1999 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2002 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2004 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2007 SCM n = scm_difference ($4, SCM_UNDEFINED);
2008 if (scm_is_true (scm_call_1 ($1, n)))
2009 MYREPARSE (@4, $1, REAL, n);
2011 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2012 t->set_property ("digit", $4);
2013 SCM m = t->unprotect ();
2014 if (scm_is_true (scm_call_1 ($1, m)))
2015 MYREPARSE (@4, $1, SCM_ARG, m);
2017 MYREPARSE (@4, $1, SCM_ARG, $4);
2021 | EXPECT_SCM function_arglist_optional '-' REAL
2024 SCM n = scm_difference ($4, SCM_UNDEFINED);
2025 MYREPARSE (@4, $1, REAL, n);
2029 function_arglist_optional:
2030 function_arglist_backup
2031 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2033 $$ = scm_cons (loc_on_music (@4, $1), $3);
2035 | function_arglist_skip_backup BACKUP
2038 function_arglist_skip_backup:
2039 function_arglist_backup
2040 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2042 $$ = scm_cons (loc_on_music (@3, $1), $3);
2046 music_function_call:
2047 MUSIC_FUNCTION function_arglist {
2048 $$ = MAKE_SYNTAX ("music-function", @$,
2055 /**/ { $$ = SCM_EOL; }
2056 | '=' simple_string {
2061 // We must not have lookahead tokens parsed in lyric mode. In order
2062 // to save confusion, we take almost the same set as permitted with
2063 // \lyricmode and/or \lyrics. However, music identifiers are also
2064 // allowed, and they obviously do not require switching into lyrics
2065 // mode for parsing.
2069 parser->lexer_->push_lyric_state ();
2070 } grouped_music_list
2072 parser->lexer_->pop_state ();
2080 | repeated_music { $$ = $1; }
2081 | re_rhythmed_music { $$ = $1; }
2082 | complex_music_prefix music
2084 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2088 complex_music_prefix:
2089 CONTEXT symbol optional_id optional_context_mod {
2090 Context_mod *ctxmod = unsmob_context_mod ($4);
2093 mods = ctxmod->get_mods ();
2094 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2096 | NEWCONTEXT symbol optional_id optional_context_mod {
2097 Context_mod *ctxmod = unsmob_context_mod ($4);
2100 mods = ctxmod->get_mods ();
2101 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2106 mode_changing_head grouped_music_list {
2107 if ($1 == ly_symbol2scm ("chords"))
2109 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2115 parser->lexer_->pop_state ();
2117 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2118 Context_mod *ctxmod = unsmob_context_mod ($2);
2121 mods = ctxmod->get_mods ();
2122 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2123 if ($1 == ly_symbol2scm ("ChordNames"))
2125 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2127 parser->lexer_->pop_state ();
2133 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2134 parser->lexer_->push_note_state (nn);
2136 $$ = ly_symbol2scm ("notes");
2140 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2141 parser->lexer_->push_note_state (nn);
2143 $$ = ly_symbol2scm ("drums");
2146 parser->lexer_->push_figuredbass_state ();
2148 $$ = ly_symbol2scm ("figures");
2151 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2152 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2153 nn = parser->lexer_->lookup_identifier ("pitchnames");
2154 parser->lexer_->push_chord_state (nn);
2155 $$ = ly_symbol2scm ("chords");
2159 { parser->lexer_->push_lyric_state ();
2160 $$ = ly_symbol2scm ("lyrics");
2164 mode_changing_head_with_context:
2166 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2167 parser->lexer_->push_note_state (nn);
2169 $$ = ly_symbol2scm ("DrumStaff");
2172 parser->lexer_->push_figuredbass_state ();
2174 $$ = ly_symbol2scm ("FiguredBass");
2177 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2178 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2179 nn = parser->lexer_->lookup_identifier ("pitchnames");
2180 parser->lexer_->push_chord_state (nn);
2181 $$ = ly_symbol2scm ("ChordNames");
2184 { parser->lexer_->push_lyric_state ();
2185 $$ = ly_symbol2scm ("Lyrics");
2190 ADDLYRICS lyric_mode_music {
2191 $$ = scm_list_1 ($2);
2193 | new_lyrics ADDLYRICS lyric_mode_music {
2194 $$ = scm_cons ($3, $1);
2199 composite_music new_lyrics {
2200 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2202 | LYRICSTO simple_string lyric_mode_music {
2203 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $3);
2208 CHANGE symbol '=' simple_string {
2209 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2216 $$ = scm_reverse_x ($1, SCM_EOL);
2218 | symbol_list_rev property_path {
2219 $$ = scm_reverse_x ($1, $2);
2225 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2228 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2230 | OVERRIDE property_path '=' scalar {
2231 if (scm_ilength ($2) < 2) {
2232 parser->parser_error (@2, _("bad grob property path"));
2235 $$ = scm_cons (ly_symbol2scm ("push"),
2236 scm_cons2 (scm_car ($2),
2241 | REVERT revert_arg {
2242 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2246 // This is all quite awkward for the sake of substantial backward
2247 // compatibility while at the same time allowing a more "natural" form
2248 // of specification not separating grob specification from grob
2249 // property path. The purpose of this definition of revert_arg is to
2250 // allow the symbol list which specifies grob and property to revert
2251 // to be optionally be split into two parts after the grob (which in
2252 // this case is just the first element of the list). symbol_list_part
2253 // is only one path component, but it can be parsed without lookahead,
2254 // so we can follow it with a synthetic BACKUP token when needed. If
2255 // the first symbol_list_part already contains multiple elements (only
2256 // possible if a Scheme expression provides them), we just parse for
2257 // additional elements introduced by '.', which is what the
2258 // SYMBOL_LIST backup in connection with the immediately following
2259 // rule using symbol_list_arg does.
2261 // As long as we don't have our coffers filled with both grob and at
2262 // least one grob property specification, the rest of the required
2263 // symbol list chain may be provided either with or without a leading
2264 // dot. This is for both allowing the traditional
2265 // \revert Accidental #'color
2266 // as well as well as the "naive" form
2267 // \revert Accidental.color
2270 revert_arg_backup BACKUP symbol_list_arg
2279 if (scm_is_null ($1)
2280 || scm_is_null (scm_cdr ($1)))
2281 MYBACKUP (SCM_ARG, $1, @1);
2283 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2287 // revert_arg_part delivers results in reverse
2290 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2292 $$ = scm_append_x (scm_list_2 ($5, $3));
2294 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2296 $$ = scm_append_x (scm_list_2 ($4, $3));
2301 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2302 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2304 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2305 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2306 | DENIES { $$ = ly_symbol2scm ("denies"); }
2308 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2309 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2310 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2311 | NAME { $$ = ly_symbol2scm ("context-name"); }
2315 property_operation { $$ = $1; }
2316 | context_def_mod STRING {
2317 $$ = scm_list_2 ($1, $2);
2319 | context_def_mod embedded_scm
2321 if (!scm_is_string ($2)
2322 && ly_symbol2scm ("consists") != $1
2323 && ly_symbol2scm ("remove") != $1)
2326 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2330 $$ = scm_list_2 ($1, $2);
2335 // If defined, at least two members.
2339 SCM l = scm_reverse_x ($1, SCM_EOL);
2342 (scm_object_property (scm_car (l),
2343 ly_symbol2scm ("is-grob?"))))
2344 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2345 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2346 parser->parser_error (@1, _ ("bad grob property path"));
2353 // If defined, at least three members
2357 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2359 parser->parser_error (@1, _ ("bad grob property path"));
2363 | grob_prop_spec property_path
2365 if (!SCM_UNBNDP ($1)) {
2366 $$ = scm_append_x (scm_list_2 ($1, $2));
2367 if (scm_is_null (scm_cddr ($$))) {
2368 parser->parser_error (@$, _ ("bad grob property path"));
2376 // Exactly two elements or undefined
2380 SCM l = scm_reverse_x ($1, SCM_EOL);
2381 switch (scm_ilength (l)) {
2383 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2387 parser->parser_error (@1, _ ("bad context property path"));
2394 simple_music_property_def:
2395 OVERRIDE grob_prop_path '=' scalar {
2396 if (SCM_UNBNDP ($2))
2399 $$ = scm_list_5 (scm_car ($2),
2400 ly_symbol2scm ("OverrideProperty"),
2406 | REVERT simple_revert_context revert_arg {
2407 $$ = scm_list_4 ($2,
2408 ly_symbol2scm ("RevertProperty"),
2412 | SET context_prop_spec '=' scalar {
2413 if (SCM_UNBNDP ($2))
2416 $$ = scm_list_4 (scm_car ($2),
2417 ly_symbol2scm ("PropertySet"),
2421 | UNSET context_prop_spec {
2422 if (SCM_UNBNDP ($2))
2425 $$ = scm_list_3 (scm_car ($2),
2426 ly_symbol2scm ("PropertyUnset"),
2432 // This is all quite awkward for the sake of substantial backward
2433 // compatibility while at the same time allowing a more "natural" form
2434 // of specification not separating grob specification from grob
2435 // property path. The purpose of this definition of
2436 // simple_revert_context is to allow the symbol list which specifies
2437 // grob and property to revert to be optionally be split into two
2438 // parts after the grob (which may be preceded by a context
2439 // specification, a case which we distinguish by checking whether the
2440 // first symbol is a valid grob symbol instead).
2442 // See revert_arg above for the main work horse of this arrangement.
2443 // simple_revert_context just caters for the context and delegates the
2444 // rest of the job to revert_arg.
2446 simple_revert_context:
2449 $1 = scm_reverse_x ($1, SCM_EOL);
2450 if (scm_is_null ($1)
2452 (scm_object_property (scm_car ($1),
2453 ly_symbol2scm ("is-grob?")))) {
2454 $$ = ly_symbol2scm ("Bottom");
2455 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2458 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2465 simple_music_property_def {
2466 if (SCM_UNBNDP ($1))
2467 $$ = MAKE_SYNTAX ("void-music", @1);
2469 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2480 simple_string: STRING {
2485 if (scm_is_string ($1)) {
2488 parser->parser_error (@1, (_ ("simple string expected")));
2489 $$ = scm_string (SCM_EOL);
2496 $$ = scm_string_to_symbol ($1);
2500 // This is a bit of overkill but makes the same
2501 // routine responsible for all symbol interpretations.
2502 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2504 if (SCM_UNBNDP ($$))
2506 parser->parser_error (@1, (_ ("symbol expected")));
2507 // Generate a unique symbol in case it is used
2508 // for an assignment or similar
2509 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2519 // The following is a rather defensive variant of admitting
2520 // negative numbers: the grammar would permit number_factor or
2521 // even number_expression. However, function arguments allow
2522 // only this simple kind of negative number, so to have things
2523 // like \tweak and \override behave reasonably similar, it
2524 // makes sense to rule out things like -- which are rather an
2525 // accent in function argument contexts.
2528 $$ = scm_difference ($2, SCM_UNDEFINED);
2534 simple_element post_events {
2535 // Let the rhythmic music iterator sort this mess out.
2536 if (scm_is_pair ($2)) {
2537 unsmob_music ($$)->set_property ("articulations",
2538 scm_reverse_x ($2, SCM_EOL));
2541 | CHORD_REPETITION optional_notemode_duration post_events {
2543 i.set_location (@1, @3);
2544 $$ = MAKE_SYNTAX ("repetition-chord", i,
2545 $2, scm_reverse_x ($3, SCM_EOL));
2547 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2549 i.set_location (@1, @3);
2550 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2551 scm_reverse_x ($3, SCM_EOL));
2554 | note_chord_element
2559 chord_body optional_notemode_duration post_events
2561 Music *m = unsmob_music ($1);
2562 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2563 SCM es = m->get_property ("elements");
2564 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2566 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2567 unsmob_music (scm_car (s))->set_property ("duration", dur);
2568 es = ly_append2 (es, postevs);
2570 m-> set_property ("elements", es);
2572 $$ = m->self_scm ();
2577 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2579 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2583 chord_body_elements:
2584 /* empty */ { $$ = SCM_EOL; }
2585 | chord_body_elements chord_body_element {
2586 if (!SCM_UNBNDP ($2))
2587 $$ = scm_cons ($2, $1);
2592 pitch exclamations questions octave_check post_events
2594 bool q = to_boolean ($3);
2595 bool ex = to_boolean ($2);
2599 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2600 n->set_property ("pitch", $1);
2602 n->set_property ("cautionary", SCM_BOOL_T);
2604 n->set_property ("force-accidental", SCM_BOOL_T);
2606 if (scm_is_pair (post)) {
2607 SCM arts = scm_reverse_x (post, SCM_EOL);
2608 n->set_property ("articulations", arts);
2610 if (scm_is_number (check))
2612 int q = scm_to_int (check);
2613 n->set_property ("absolute-octave", scm_from_int (q-1));
2616 $$ = n->unprotect ();
2618 | DRUM_PITCH post_events {
2619 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2620 n->set_property ("drum-type", $1);
2622 if (scm_is_pair ($2)) {
2623 SCM arts = scm_reverse_x ($2, SCM_EOL);
2624 n->set_property ("articulations", arts);
2626 $$ = n->unprotect ();
2628 | music_function_chord_body
2630 Music *m = unsmob_music ($1);
2632 while (m && m->is_mus_type ("music-wrapper-music")) {
2633 $$ = m->get_property ("element");
2634 m = unsmob_music ($$);
2637 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2638 parser->parser_error (@$, _ ("not a rhythmic event"));
2644 music_function_chord_body:
2650 event_function_event:
2651 EVENT_FUNCTION function_arglist {
2652 $$ = MAKE_SYNTAX ("music-function", @$,
2661 | post_events post_event {
2663 if (Music *m = unsmob_music ($2))
2665 if (m->is_mus_type ("post-event-wrapper"))
2667 for (SCM p = m->get_property ("elements");
2671 $$ = scm_cons (scm_car (p), $$);
2675 $$ = scm_cons ($2, $$);
2681 post_event_nofinger:
2682 direction_less_event {
2685 | script_dir music_function_call {
2687 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2688 parser->parser_error (@2, _ ("post-event expected"));
2689 $$ = SCM_UNSPECIFIED;
2690 } else if (!SCM_UNBNDP ($1))
2692 unsmob_music ($$)->set_property ("direction", $1);
2696 if (!parser->lexer_->is_lyric_state ())
2697 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2698 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2701 if (!parser->lexer_->is_lyric_state ())
2702 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2703 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2705 | script_dir direction_reqd_event {
2706 if (!SCM_UNBNDP ($1))
2708 Music *m = unsmob_music ($2);
2709 m->set_property ("direction", $1);
2713 | script_dir direction_less_event {
2714 if (!SCM_UNBNDP ($1))
2716 Music *m = unsmob_music ($2);
2717 m->set_property ("direction", $1);
2724 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2729 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2740 string_number_event:
2742 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2743 s->set_property ("string-number", $1);
2744 $$ = s->unprotect ();
2748 direction_less_event:
2750 | EVENT_IDENTIFIER {
2754 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2755 a->set_property ("tremolo-type", $1);
2756 $$ = a->unprotect ();
2758 | event_function_event
2761 direction_reqd_event:
2765 | script_abbreviation {
2766 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2767 if (scm_is_string (s)) {
2768 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2769 a->set_property ("articulation-type", s);
2770 $$ = a->unprotect ();
2772 Music *original = unsmob_music (s);
2773 if (original && original->is_mus_type ("post-event")) {
2774 Music *a = original->clone ();
2775 a->set_spot (parser->lexer_->override_input (@$));
2776 $$ = a->unprotect ();
2778 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2779 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2786 /**/ { $$ = SCM_EOL; }
2787 | '=' quotes { $$ = $2; }
2801 $$ = scm_from_int (1);
2804 $$ = scm_oneplus ($1);
2810 $$ = scm_from_int (-1);
2813 $$ = scm_oneminus ($1);
2818 NOTENAME_PITCH quotes {
2819 if (!scm_is_eq (SCM_INUM0, $2))
2821 Pitch p = *unsmob_pitch ($1);
2822 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2823 $$ = p.smobbed_copy ();
2833 TONICNAME_PITCH quotes {
2834 if (!scm_is_eq (SCM_INUM0, $2))
2836 Pitch p = *unsmob_pitch ($1);
2837 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2838 $$ = p.smobbed_copy ();
2845 | PITCH_IDENTIFIER quotes {
2846 if (!scm_is_eq (SCM_INUM0, $2))
2848 Pitch p = *unsmob_pitch ($1);
2849 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2850 $$ = 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 ();
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);
2988 $$ = scm_from_int (parser->default_tremolo_type_);
2991 if (SCM_UNBNDP (make_duration ($2))) {
2992 parser->parser_error (@2, _ ("not a duration"));
2993 $$ = scm_from_int (parser->default_tremolo_type_);
2996 parser->default_tremolo_type_ = scm_to_int ($2);
3002 UNSIGNED { $$ = $1; }
3003 | STRING { $$ = $1; }
3004 | full_markup { $$ = $1; }
3007 // as an integer, it needs to be non-negative, and otherwise
3008 // it needs to be suitable as a markup.
3009 if (scm_is_integer ($1)
3010 ? scm_is_true (scm_negative_p ($1))
3011 : !Text_interface::is_markup ($1))
3013 parser->parser_error (@1, _ ("bass number expected"));
3019 figured_bass_alteration:
3020 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3021 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3022 | '!' { $$ = scm_from_int (0); }
3027 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3028 $$ = bfr->unprotect ();
3031 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3032 $$ = bfr->self_scm ();
3034 if (scm_is_number ($1))
3035 bfr->set_property ("figure", $1);
3036 else if (Text_interface::is_markup ($1))
3037 bfr->set_property ("text", $1);
3043 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3045 | bass_figure figured_bass_alteration {
3046 Music *m = unsmob_music ($1);
3047 if (scm_to_double ($2)) {
3048 SCM salter = m->get_property ("alteration");
3049 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3050 m->set_property ("alteration",
3051 scm_sum (alter, $2));
3053 m->set_property ("alteration", scm_from_int (0));
3056 | bass_figure figured_bass_modification {
3057 Music *m = unsmob_music ($1);
3058 m->set_property ($2, SCM_BOOL_T);
3063 figured_bass_modification:
3065 $$ = ly_symbol2scm ("augmented");
3068 $$ = ly_symbol2scm ("no-continuation");
3071 $$ = ly_symbol2scm ("diminished");
3074 $$ = ly_symbol2scm ("augmented-slash");
3084 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3092 | figure_list br_bass_figure {
3093 $$ = scm_cons ($2, $1);
3098 FIGURE_OPEN figure_list FIGURE_CLOSE {
3099 $$ = scm_reverse_x ($2, SCM_EOL);
3105 /**/ { $$ = SCM_BOOL_F; }
3106 | REST { $$ = SCM_BOOL_T; }
3110 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3111 if (!parser->lexer_->is_note_state ())
3112 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3113 if (!SCM_UNBNDP ($2)
3115 || scm_is_number ($4)
3118 || scm_is_pair ($7))
3121 if (scm_is_true ($6))
3122 n = MY_MAKE_MUSIC ("RestEvent", @$);
3124 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3126 n->set_property ("pitch", $1);
3127 if (SCM_UNBNDP ($5))
3128 n->set_property ("duration",
3129 parser->default_duration_.smobbed_copy ());
3131 n->set_property ("duration", $5);
3133 if (scm_is_number ($4))
3135 int q = scm_to_int ($4);
3136 n->set_property ("absolute-octave", scm_from_int (q-1));
3139 if (to_boolean ($3))
3140 n->set_property ("cautionary", SCM_BOOL_T);
3141 if (to_boolean ($2) || to_boolean ($3))
3142 n->set_property ("force-accidental", SCM_BOOL_T);
3143 if (scm_is_pair ($7))
3144 n->set_property ("articulations",
3145 scm_reverse_x ($7, SCM_EOL));
3146 $$ = n->unprotect ();
3149 | simple_chord_elements post_events {
3150 if (scm_is_pair ($2)) {
3151 if (unsmob_pitch ($1))
3152 $1 = make_chord_elements (@1,
3154 parser->default_duration_.smobbed_copy (),
3157 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3159 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
3160 } else if (!unsmob_pitch ($1))
3161 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
3162 // A mere pitch drops through.
3167 DRUM_PITCH optional_notemode_duration {
3168 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3169 n->set_property ("duration", $2);
3170 n->set_property ("drum-type", $1);
3172 $$ = n->unprotect ();
3174 | RESTNAME optional_notemode_duration {
3176 if (ly_scm2string ($1) == "s") {
3178 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3181 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3184 ev->set_property ("duration", $2);
3185 $$ = ev->unprotect ();
3189 // Can return a single pitch rather than a list.
3190 simple_chord_elements:
3192 if (!parser->lexer_->is_chord_state ())
3193 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3196 | figure_spec optional_notemode_duration {
3197 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3199 unsmob_music (scm_car (s))->set_property ("duration", $2);
3207 if (!parser->lexer_->is_lyric_state ())
3208 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3212 if (!parser->lexer_->is_lyric_state ())
3213 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3219 lyric_element_music:
3220 lyric_element optional_notemode_duration post_events {
3221 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3222 if (scm_is_pair ($3))
3223 unsmob_music ($$)->set_property
3224 ("articulations", scm_reverse_x ($3, SCM_EOL));
3228 // Can return a single pitch rather than a list.
3230 steno_tonic_pitch maybe_notemode_duration {
3231 if (SCM_UNBNDP ($2))
3234 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3236 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3237 SCM its = scm_reverse_x ($4, SCM_EOL);
3238 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3246 | chord_items chord_item {
3247 $$ = scm_cons ($2, $$);
3253 $$ = ly_symbol2scm ("chord-colon");
3256 $$ = ly_symbol2scm ("chord-caret");
3258 | CHORD_SLASH steno_tonic_pitch {
3259 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3261 | CHORD_BASS steno_tonic_pitch {
3262 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3271 $$ = scm_reverse_x ($1, SCM_EOL);
3279 step_number { $$ = scm_cons ($1, SCM_EOL); }
3280 | step_numbers '.' step_number {
3281 $$ = scm_cons ($3, $$);
3287 $$ = make_chord_step ($1, 0);
3290 $$ = make_chord_step ($1, SHARP_ALTERATION);
3292 | UNSIGNED CHORD_MINUS {
3293 $$ = make_chord_step ($1, FLAT_ALTERATION);
3301 | unsigned_number '-' unsigned_number {
3302 $$ = scm_cons ($1, $3);
3309 TODO: should deprecate in favor of Scheme?
3313 number_expression '+' number_term {
3314 $$ = scm_sum ($1, $3);
3316 | number_expression '-' number_term {
3317 $$ = scm_difference ($1, $3);
3326 | number_factor '*' number_factor {
3327 $$ = scm_product ($1, $3);
3329 | number_factor '/' number_factor {
3330 $$ = scm_divide ($1, $3);
3335 '-' number_factor { /* %prec UNARY_MINUS */
3336 $$ = scm_difference ($2, SCM_UNDEFINED);
3344 | REAL NUMBER_IDENTIFIER
3346 $$ = scm_product ($1, $2);
3353 | UNSIGNED NUMBER_IDENTIFIER {
3354 $$ = scm_product ($1, $2);
3362 if (!scm_is_integer ($1)
3363 || scm_is_true (scm_negative_p ($1)))
3365 parser->parser_error (@1, _("not an unsigned integer"));
3371 if (!scm_is_integer ($1)
3372 || scm_is_true (scm_negative_p ($1)))
3374 parser->parser_error (@1, _("not an unsigned integer"));
3381 { $$ = SCM_UNDEFINED; }
3384 if (SCM_UNBNDP ($1))
3392 // This precedence rule is rather weird. It triggers when '!' is
3393 // encountered after a pitch, and is used for deciding whether to save
3394 // this instead for a figure modification. This should not actually
3395 // occur in practice as pitches and figures are generated in different
3396 // modes. Using a greedy (%right) precedence makes sure that we don't
3397 // get stuck in a wrong interpretation.
3398 { $$ = SCM_UNDEFINED; } %prec ':'
3401 if (SCM_UNBNDP ($1))
3410 { parser->lexer_->push_markup_state (); }
3413 parser->lexer_->pop_state ();
3419 { parser->lexer_->push_markup_state (); }
3422 parser->lexer_->pop_state ();
3428 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3430 | markup_head_1_list simple_markup
3432 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3433 @2, $1, scm_list_1 ($2)));
3443 if (Text_interface::is_markup ($1))
3444 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3445 else if (Text_interface::is_markup_list ($1))
3446 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3448 parser->parser_error (@1, _ ("not a markup"));
3449 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3456 markup_composed_list {
3459 | markup_uncomposed_list
3462 markup_uncomposed_list:
3463 markup_braced_list {
3466 | markup_command_list {
3467 $$ = scm_list_1 ($1);
3469 | markup_scm MARKUPLIST_IDENTIFIER
3474 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3475 parser->lexer_->push_note_state (nn);
3476 } '{' score_body '}' {
3477 unsmob_score ($4)->origin ()->set_spot (@$);
3478 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3479 parser->lexer_->pop_state ();
3483 markup_composed_list:
3484 markup_head_1_list markup_uncomposed_list {
3485 $$ = MAKE_SYNTAX ("composed-markup-list",
3491 '{' markup_braced_list_body '}' {
3492 $$ = scm_reverse_x ($2, SCM_EOL);
3496 markup_braced_list_body:
3497 /* empty */ { $$ = SCM_EOL; }
3498 | markup_braced_list_body markup {
3499 $$ = scm_cons ($2, $1);
3501 | markup_braced_list_body markup_list {
3502 $$ = scm_reverse_x ($2, $1);
3506 markup_command_list:
3507 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3508 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3512 markup_command_basic_arguments:
3513 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3514 $$ = scm_cons ($3, $2);
3516 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3517 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3519 | EXPECT_NO_MORE_ARGS {
3524 markup_command_list_arguments:
3525 markup_command_basic_arguments { $$ = $1; }
3526 | EXPECT_MARKUP markup_command_list_arguments markup {
3527 $$ = scm_cons ($3, $2);
3532 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3533 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3538 markup_head_1_item {
3539 $$ = scm_list_1 ($1);
3541 | markup_head_1_list markup_head_1_item {
3542 $$ = scm_cons ($2, $1);
3548 $$ = make_simple_markup ($1);
3551 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3552 parser->lexer_->push_note_state (nn);
3553 } '{' score_body '}' {
3554 unsmob_score ($4)->origin ()->set_spot (@$);
3555 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3556 parser->lexer_->pop_state ();
3558 | MARKUP_FUNCTION markup_command_basic_arguments {
3559 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3561 | markup_scm MARKUP_IDENTIFIER
3568 markup_head_1_list simple_markup
3570 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3571 @2, $1, scm_list_1 ($2)));
3581 Lily_parser::set_yydebug (bool x)
3587 Lily_parser::do_yyparse ()
3589 SCM retval = SCM_UNDEFINED;
3590 yyparse (this, &retval);
3600 It is a little strange to have this function in this file, but
3601 otherwise, we have to import music classes into the lexer.
3605 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3607 if (unsmob_book (sid)) {
3608 Book *book = unsmob_book (sid)->clone ();
3609 *destination = book->self_scm ();
3612 return BOOK_IDENTIFIER;
3613 } else if (scm_is_number (sid)) {
3615 return NUMBER_IDENTIFIER;
3616 } else if (unsmob_context_def (sid)) {
3617 Context_def *def= unsmob_context_def (sid)->clone ();
3619 *destination = def->self_scm ();
3622 return CONTEXT_DEF_IDENTIFIER;
3623 } else if (unsmob_context_mod (sid)) {
3624 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3626 return CONTEXT_MOD_IDENTIFIER;
3627 } else if (Music *mus = unsmob_music (sid)) {
3628 mus = mus->clone ();
3629 *destination = mus->self_scm ();
3630 bool is_event = mus->is_mus_type ("post-event");
3632 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3633 } else if (unsmob_pitch (sid)) {
3634 *destination = unsmob_pitch (sid)->smobbed_copy ();
3635 return PITCH_IDENTIFIER;
3636 } else if (unsmob_duration (sid)) {
3637 *destination = unsmob_duration (sid)->smobbed_copy ();
3638 return DURATION_IDENTIFIER;
3639 } else if (unsmob_output_def (sid)) {
3640 *destination = unsmob_output_def (sid)->clone ()->unprotect ();
3641 return SCM_IDENTIFIER;
3642 } else if (unsmob_score (sid)) {
3643 *destination = unsmob_score (sid)->clone ()->unprotect ();
3644 return SCM_IDENTIFIER;
3651 get_next_unique_context_id ()
3653 return scm_from_locale_string ("$uniqueContextId");
3658 get_next_unique_lyrics_context_id ()
3660 static int new_context_count;
3662 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3663 return scm_from_locale_string (s);
3666 // check_scheme_arg checks one argument with a given predicate for use
3667 // in an argument list and throws a syntax error if it is unusable.
3668 // The argument is prepended to the argument list in any case. After
3669 // throwing a syntax error, the argument list is terminated with #f as
3670 // its last cdr in order to mark it as uncallable while not losing
3671 // track of its total length.
3673 // There are a few special considerations: if optional argument disp
3674 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3675 // instead of arg in a prospective error message. This is useful if
3676 // arg is not the actual argument but rather a transformation of it.
3678 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3679 // and an error message using disp is produced unconditionally.
3681 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3682 SCM arg, SCM args, SCM pred, SCM disp)
3684 if (SCM_UNBNDP (arg))
3685 args = scm_cons (disp, args);
3687 args = scm_cons (arg, args);
3688 if (scm_is_true (scm_call_1 (pred, arg)))
3691 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3692 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3693 SCM_UNBNDP (disp) ? arg : disp);
3694 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3698 SCM loc_on_music (Input loc, SCM arg)
3700 if (Music *m = unsmob_music (arg))
3704 return m->unprotect ();
3710 try_string_variants (SCM pred, SCM str)
3712 // a matching predicate is always ok
3713 if (scm_is_true (scm_call_1 (pred, str)))
3715 // a symbol may be interpreted as a list of symbols if it helps
3716 if (scm_is_symbol (str)) {
3717 str = scm_list_1 (str);
3718 if (scm_is_true (scm_call_1 (pred, str)))
3720 return SCM_UNDEFINED;
3723 // If this cannot be a string representation of a symbol list,
3726 if (!is_regular_identifier (str, true))
3727 return SCM_UNDEFINED;
3729 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3730 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3731 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3733 // Let's attempt the symbol list interpretation first.
3735 if (scm_is_true (scm_call_1 (pred, str)))
3738 // If there is just one symbol in the list, we might interpret
3739 // it as a single symbol
3741 if (scm_is_null (scm_cdr (str)))
3743 str = scm_car (str);
3744 if (scm_is_true (scm_call_1 (pred, str)))
3748 return SCM_UNDEFINED;
3752 is_regular_identifier (SCM id, bool multiple)
3754 if (!scm_is_string (id))
3757 string str = ly_scm2string (id);
3759 bool middle = false;
3761 for (string::iterator it=str.begin(); it != str.end (); it++)
3764 if ((c >= 'a' && c <= 'z')
3765 || (c >= 'A' && c <= 'Z')
3768 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3777 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3779 if (unsmob_music (simple))
3781 if (parser->lexer_->is_note_state ()) {
3782 if (scm_is_symbol (simple)) {
3783 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3784 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3785 n->set_property ("drum-type", simple);
3786 return n->unprotect ();
3788 if (unsmob_pitch (simple)) {
3789 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3790 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3791 n->set_property ("pitch", simple);
3792 return n->unprotect ();
3795 } else if (parser->lexer_->is_lyric_state ()) {
3796 if (Text_interface::is_markup (simple))
3797 return MAKE_SYNTAX ("lyric-event", loc, simple,
3798 parser->default_duration_.smobbed_copy ());
3799 } else if (parser->lexer_->is_chord_state ()) {
3800 if (unsmob_pitch (simple))
3804 make_chord_elements (loc, simple,
3805 parser->default_duration_.smobbed_copy (),
3812 make_music_with_input (SCM name, Input where)
3814 Music *m = make_music_by_name (name);
3815 m->set_spot (where);
3820 make_simple_markup (SCM a)
3826 make_duration (SCM d, int dots)
3828 int t = scm_to_int (d);
3829 if (t > 0 && (t & (t-1)) == 0)
3830 return Duration (intlog2 (t), dots).smobbed_copy ();
3832 return SCM_UNDEFINED;
3836 make_chord_step (SCM step_scm, Rational alter)
3838 int step = scm_to_int (step_scm);
3841 alter += FLAT_ALTERATION;
3845 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3846 return m.smobbed_copy ();
3851 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3853 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3854 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3855 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3857 unsmob_music (scm_car (s))->set_spot (loc);
3863 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3865 Lily_lexer *lex = parser->lexer_;
3869 int tok = lex->pop_extra_token ();
3872 lex->prepare_for_next_token ();
3873 return lex->yylex ();