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 {
2063 | repeated_music { $$ = $1; }
2064 | re_rhythmed_music { $$ = $1; }
2065 | complex_music_prefix music
2067 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2071 complex_music_prefix:
2072 CONTEXT symbol optional_id optional_context_mod {
2073 Context_mod *ctxmod = unsmob_context_mod ($4);
2076 mods = ctxmod->get_mods ();
2077 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2079 | NEWCONTEXT symbol optional_id optional_context_mod {
2080 Context_mod *ctxmod = unsmob_context_mod ($4);
2083 mods = ctxmod->get_mods ();
2084 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2089 mode_changing_head grouped_music_list {
2090 if ($1 == ly_symbol2scm ("chords"))
2092 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2098 parser->lexer_->pop_state ();
2100 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2101 Context_mod *ctxmod = unsmob_context_mod ($2);
2104 mods = ctxmod->get_mods ();
2105 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2106 if ($1 == ly_symbol2scm ("ChordNames"))
2108 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2110 parser->lexer_->pop_state ();
2116 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2117 parser->lexer_->push_note_state (nn);
2119 $$ = ly_symbol2scm ("notes");
2123 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2124 parser->lexer_->push_note_state (nn);
2126 $$ = ly_symbol2scm ("drums");
2129 parser->lexer_->push_figuredbass_state ();
2131 $$ = ly_symbol2scm ("figures");
2134 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2135 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2136 nn = parser->lexer_->lookup_identifier ("pitchnames");
2137 parser->lexer_->push_chord_state (nn);
2138 $$ = ly_symbol2scm ("chords");
2142 { parser->lexer_->push_lyric_state ();
2143 $$ = ly_symbol2scm ("lyrics");
2147 mode_changing_head_with_context:
2149 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2150 parser->lexer_->push_note_state (nn);
2152 $$ = ly_symbol2scm ("DrumStaff");
2155 parser->lexer_->push_figuredbass_state ();
2157 $$ = ly_symbol2scm ("FiguredBass");
2160 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2161 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2162 nn = parser->lexer_->lookup_identifier ("pitchnames");
2163 parser->lexer_->push_chord_state (nn);
2164 $$ = ly_symbol2scm ("ChordNames");
2167 { parser->lexer_->push_lyric_state ();
2168 $$ = ly_symbol2scm ("Lyrics");
2173 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2176 /* Can also use music at the expensive of two S/Rs similar to
2177 \repeat \alternative */
2178 parser->lexer_->pop_state ();
2180 $$ = scm_cons ($3, SCM_EOL);
2182 | new_lyrics ADDLYRICS {
2183 parser->lexer_->push_lyric_state ();
2185 parser->lexer_->pop_state ();
2186 $$ = scm_cons ($4, $1);
2191 composite_music new_lyrics {
2192 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2194 | LYRICSTO simple_string {
2195 parser->lexer_->push_lyric_state ();
2197 parser->lexer_->pop_state ();
2198 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2203 CHANGE symbol '=' simple_string {
2204 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2211 $$ = scm_reverse_x ($1, SCM_EOL);
2213 | symbol_list_rev property_path {
2214 $$ = scm_reverse_x ($1, $2);
2220 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2223 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2225 | OVERRIDE property_path '=' scalar {
2226 if (scm_ilength ($2) < 2) {
2227 parser->parser_error (@2, _("bad grob property path"));
2230 $$ = scm_cons (ly_symbol2scm ("push"),
2231 scm_cons2 (scm_car ($2),
2236 | REVERT revert_arg {
2237 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2241 // This is all quite awkward for the sake of substantial backward
2242 // compatibility while at the same time allowing a more "natural" form
2243 // of specification not separating grob specification from grob
2244 // property path. The purpose of this definition of revert_arg is to
2245 // allow the symbol list which specifies grob and property to revert
2246 // to be optionally be split into two parts after the grob (which in
2247 // this case is just the first element of the list). symbol_list_part
2248 // is only one path component, but it can be parsed without lookahead,
2249 // so we can follow it with a synthetic BACKUP token when needed. If
2250 // the first symbol_list_part already contains multiple elements (only
2251 // possible if a Scheme expression provides them), we just parse for
2252 // additional elements introduced by '.', which is what the
2253 // SYMBOL_LIST backup in connection with the immediately following
2254 // rule using symbol_list_arg does.
2256 // As long as we don't have our coffers filled with both grob and at
2257 // least one grob property specification, the rest of the required
2258 // symbol list chain may be provided either with or without a leading
2259 // dot. This is for both allowing the traditional
2260 // \revert Accidental #'color
2261 // as well as well as the "naive" form
2262 // \revert Accidental.color
2265 revert_arg_backup BACKUP symbol_list_arg
2274 if (scm_is_null ($1)
2275 || scm_is_null (scm_cdr ($1)))
2276 MYBACKUP (SCM_ARG, $1, @1);
2278 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2282 // revert_arg_part delivers results in reverse
2285 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2287 $$ = scm_append_x (scm_list_2 ($5, $3));
2289 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2291 $$ = scm_append_x (scm_list_2 ($4, $3));
2296 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2297 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2299 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2300 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2301 | DENIES { $$ = ly_symbol2scm ("denies"); }
2303 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2304 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2305 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2306 | NAME { $$ = ly_symbol2scm ("context-name"); }
2310 property_operation { $$ = $1; }
2311 | context_def_mod STRING {
2312 $$ = scm_list_2 ($1, $2);
2314 | context_def_mod embedded_scm
2316 if (!scm_is_string ($2)
2317 && ly_symbol2scm ("consists") != $1
2318 && ly_symbol2scm ("remove") != $1)
2321 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2325 $$ = scm_list_2 ($1, $2);
2330 // If defined, at least two members.
2334 SCM l = scm_reverse_x ($1, SCM_EOL);
2337 (scm_object_property (scm_car (l),
2338 ly_symbol2scm ("is-grob?"))))
2339 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2340 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2341 parser->parser_error (@1, _ ("bad grob property path"));
2348 // If defined, at least three members
2352 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2354 parser->parser_error (@1, _ ("bad grob property path"));
2358 | grob_prop_spec property_path
2360 if (!SCM_UNBNDP ($1)) {
2361 $$ = scm_append_x (scm_list_2 ($1, $2));
2362 if (scm_is_null (scm_cddr ($$))) {
2363 parser->parser_error (@$, _ ("bad grob property path"));
2371 // Exactly two elements or undefined
2375 SCM l = scm_reverse_x ($1, SCM_EOL);
2376 switch (scm_ilength (l)) {
2378 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2382 parser->parser_error (@1, _ ("bad context property path"));
2389 simple_music_property_def:
2390 OVERRIDE grob_prop_path '=' scalar {
2391 if (SCM_UNBNDP ($2))
2394 $$ = scm_list_5 (scm_car ($2),
2395 ly_symbol2scm ("OverrideProperty"),
2401 | REVERT simple_revert_context revert_arg {
2402 $$ = scm_list_4 ($2,
2403 ly_symbol2scm ("RevertProperty"),
2407 | SET context_prop_spec '=' scalar {
2408 if (SCM_UNBNDP ($2))
2411 $$ = scm_list_4 (scm_car ($2),
2412 ly_symbol2scm ("PropertySet"),
2416 | UNSET context_prop_spec {
2417 if (SCM_UNBNDP ($2))
2420 $$ = scm_list_3 (scm_car ($2),
2421 ly_symbol2scm ("PropertyUnset"),
2427 // This is all quite awkward for the sake of substantial backward
2428 // compatibility while at the same time allowing a more "natural" form
2429 // of specification not separating grob specification from grob
2430 // property path. The purpose of this definition of
2431 // simple_revert_context is to allow the symbol list which specifies
2432 // grob and property to revert to be optionally be split into two
2433 // parts after the grob (which may be preceded by a context
2434 // specification, a case which we distinguish by checking whether the
2435 // first symbol is a valid grob symbol instead).
2437 // See revert_arg above for the main work horse of this arrangement.
2438 // simple_revert_context just caters for the context and delegates the
2439 // rest of the job to revert_arg.
2441 simple_revert_context:
2444 $1 = scm_reverse_x ($1, SCM_EOL);
2445 if (scm_is_null ($1)
2447 (scm_object_property (scm_car ($1),
2448 ly_symbol2scm ("is-grob?")))) {
2449 $$ = ly_symbol2scm ("Bottom");
2450 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2453 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2460 simple_music_property_def {
2461 if (SCM_UNBNDP ($1))
2462 $$ = MAKE_SYNTAX ("void-music", @1);
2464 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2475 simple_string: STRING {
2480 if (scm_is_string ($1)) {
2483 parser->parser_error (@1, (_ ("simple string expected")));
2484 $$ = scm_string (SCM_EOL);
2491 $$ = scm_string_to_symbol ($1);
2495 // This is a bit of overkill but makes the same
2496 // routine responsible for all symbol interpretations.
2497 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2499 if (SCM_UNBNDP ($$))
2501 parser->parser_error (@1, (_ ("symbol expected")));
2502 // Generate a unique symbol in case it is used
2503 // for an assignment or similar
2504 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2514 // The following is a rather defensive variant of admitting
2515 // negative numbers: the grammar would permit number_factor or
2516 // even number_expression. However, function arguments allow
2517 // only this simple kind of negative number, so to have things
2518 // like \tweak and \override behave reasonably similar, it
2519 // makes sense to rule out things like -- which are rather an
2520 // accent in function argument contexts.
2523 $$ = scm_difference ($2, SCM_UNDEFINED);
2529 simple_element post_events {
2530 // Let the rhythmic music iterator sort this mess out.
2531 if (scm_is_pair ($2)) {
2532 unsmob_music ($$)->set_property ("articulations",
2533 scm_reverse_x ($2, SCM_EOL));
2536 | CHORD_REPETITION optional_notemode_duration post_events {
2538 i.set_location (@1, @3);
2539 $$ = MAKE_SYNTAX ("repetition-chord", i,
2540 $2, scm_reverse_x ($3, SCM_EOL));
2542 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2544 i.set_location (@1, @3);
2545 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2546 scm_reverse_x ($3, SCM_EOL));
2549 | note_chord_element
2554 chord_body optional_notemode_duration post_events
2556 Music *m = unsmob_music ($1);
2557 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2558 SCM es = m->get_property ("elements");
2559 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2561 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2562 unsmob_music (scm_car (s))->set_property ("duration", dur);
2563 es = ly_append2 (es, postevs);
2565 m-> set_property ("elements", es);
2567 $$ = m->self_scm ();
2572 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2574 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2578 chord_body_elements:
2579 /* empty */ { $$ = SCM_EOL; }
2580 | chord_body_elements chord_body_element {
2581 if (!SCM_UNBNDP ($2))
2582 $$ = scm_cons ($2, $1);
2587 pitch exclamations questions octave_check post_events
2589 bool q = to_boolean ($3);
2590 bool ex = to_boolean ($2);
2594 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2595 n->set_property ("pitch", $1);
2597 n->set_property ("cautionary", SCM_BOOL_T);
2599 n->set_property ("force-accidental", SCM_BOOL_T);
2601 if (scm_is_pair (post)) {
2602 SCM arts = scm_reverse_x (post, SCM_EOL);
2603 n->set_property ("articulations", arts);
2605 if (scm_is_number (check))
2607 int q = scm_to_int (check);
2608 n->set_property ("absolute-octave", scm_from_int (q-1));
2611 $$ = n->unprotect ();
2613 | DRUM_PITCH post_events {
2614 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2615 n->set_property ("drum-type", $1);
2617 if (scm_is_pair ($2)) {
2618 SCM arts = scm_reverse_x ($2, SCM_EOL);
2619 n->set_property ("articulations", arts);
2621 $$ = n->unprotect ();
2623 | music_function_chord_body
2625 Music *m = unsmob_music ($1);
2627 while (m && m->is_mus_type ("music-wrapper-music")) {
2628 $$ = m->get_property ("element");
2629 m = unsmob_music ($$);
2632 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2633 parser->parser_error (@$, _ ("not a rhythmic event"));
2639 music_function_chord_body:
2645 event_function_event:
2646 EVENT_FUNCTION function_arglist {
2647 $$ = MAKE_SYNTAX ("music-function", @$,
2656 | post_events post_event {
2658 if (Music *m = unsmob_music ($2))
2660 if (m->is_mus_type ("post-event-wrapper"))
2662 for (SCM p = m->get_property ("elements");
2666 $$ = scm_cons (scm_car (p), $$);
2670 $$ = scm_cons ($2, $$);
2676 post_event_nofinger:
2677 direction_less_event {
2680 | script_dir music_function_call {
2682 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2683 parser->parser_error (@2, _ ("post-event expected"));
2684 $$ = SCM_UNSPECIFIED;
2685 } else if (!SCM_UNBNDP ($1))
2687 unsmob_music ($$)->set_property ("direction", $1);
2691 if (!parser->lexer_->is_lyric_state ())
2692 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2693 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2696 if (!parser->lexer_->is_lyric_state ())
2697 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2698 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2700 | script_dir direction_reqd_event {
2701 if (!SCM_UNBNDP ($1))
2703 Music *m = unsmob_music ($2);
2704 m->set_property ("direction", $1);
2708 | script_dir direction_less_event {
2709 if (!SCM_UNBNDP ($1))
2711 Music *m = unsmob_music ($2);
2712 m->set_property ("direction", $1);
2719 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2724 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2735 string_number_event:
2737 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2738 s->set_property ("string-number", $1);
2739 $$ = s->unprotect ();
2743 direction_less_event:
2745 | EVENT_IDENTIFIER {
2749 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2750 a->set_property ("tremolo-type", $1);
2751 $$ = a->unprotect ();
2753 | event_function_event
2756 direction_reqd_event:
2760 | script_abbreviation {
2761 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2762 if (scm_is_string (s)) {
2763 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2764 a->set_property ("articulation-type", s);
2765 $$ = a->unprotect ();
2767 Music *original = unsmob_music (s);
2768 if (original && original->is_mus_type ("post-event")) {
2769 Music *a = original->clone ();
2770 a->set_spot (parser->lexer_->override_input (@$));
2771 $$ = a->unprotect ();
2773 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2774 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2781 /**/ { $$ = SCM_EOL; }
2782 | '=' quotes { $$ = $2; }
2796 $$ = scm_from_int (1);
2799 $$ = scm_oneplus ($1);
2805 $$ = scm_from_int (-1);
2808 $$ = scm_oneminus ($1);
2813 NOTENAME_PITCH quotes {
2814 if (!scm_is_eq (SCM_INUM0, $2))
2816 Pitch p = *unsmob_pitch ($1);
2817 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2818 $$ = p.smobbed_copy ();
2828 TONICNAME_PITCH quotes {
2829 if (!scm_is_eq (SCM_INUM0, $2))
2831 Pitch p = *unsmob_pitch ($1);
2832 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2833 $$ = p.smobbed_copy ();
2840 | PITCH_IDENTIFIER quotes {
2841 if (!scm_is_eq (SCM_INUM0, $2))
2843 Pitch p = *unsmob_pitch ($1);
2844 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2845 $$ = p.smobbed_copy ();
2852 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2853 t->set_property ("text", $1);
2854 $$ = t->unprotect ();
2857 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2858 t->set_property ("text",
2859 make_simple_markup ($1));
2860 $$ = t->unprotect ();
2864 Music *m = unsmob_music ($1);
2865 if (m && m->is_mus_type ("post-event"))
2867 else if (Text_interface::is_markup ($1)) {
2868 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2869 t->set_property ("text", $1);
2870 $$ = t->unprotect ();
2872 parser->parser_error (@1, _ ("not an articulation"));
2878 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2879 t->set_property ("digit", $1);
2880 $$ = t->unprotect ();
2884 script_abbreviation:
2886 $$ = scm_from_locale_string ("Hat");
2889 $$ = scm_from_locale_string ("Plus");
2892 $$ = scm_from_locale_string ("Dash");
2895 $$ = scm_from_locale_string ("Bang");
2898 $$ = scm_from_locale_string ("Larger");
2901 $$ = scm_from_locale_string ("Dot");
2904 $$ = scm_from_locale_string ("Underscore");
2909 '_' { $$ = scm_from_int (DOWN); }
2910 | '^' { $$ = scm_from_int (UP); }
2911 | '-' { $$ = SCM_UNDEFINED; }
2915 multiplied_duration {
2920 maybe_notemode_duration:
2924 | multiplied_duration {
2926 parser->default_duration_ = *unsmob_duration ($$);
2931 optional_notemode_duration:
2932 maybe_notemode_duration
2934 if (SCM_UNBNDP ($$))
2935 $$ = parser->default_duration_.smobbed_copy ();
2941 $$ = make_duration ($1, scm_to_int ($2));
2942 if (SCM_UNBNDP ($$))
2944 parser->parser_error (@1, _ ("not a duration"));
2945 $$ = Duration ().smobbed_copy ();
2948 | DURATION_IDENTIFIER dots {
2949 Duration *d = unsmob_duration ($1);
2950 Duration k (d->duration_log (),
2951 d->dot_count () + scm_to_int ($2));
2952 k = k.compressed (d->factor ());
2953 scm_remember_upto_here_1 ($1);
2954 $$ = k.smobbed_copy ();
2958 multiplied_duration:
2962 | multiplied_duration '*' UNSIGNED {
2963 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2965 | multiplied_duration '*' FRACTION {
2966 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2968 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2977 $$ = scm_oneplus ($1);
2983 $$ = scm_from_int (parser->default_tremolo_type_);
2986 if (SCM_UNBNDP (make_duration ($2))) {
2987 parser->parser_error (@2, _ ("not a duration"));
2988 $$ = scm_from_int (parser->default_tremolo_type_);
2991 parser->default_tremolo_type_ = scm_to_int ($2);
2997 UNSIGNED { $$ = $1; }
2998 | STRING { $$ = $1; }
2999 | full_markup { $$ = $1; }
3002 // as an integer, it needs to be non-negative, and otherwise
3003 // it needs to be suitable as a markup.
3004 if (scm_is_integer ($1)
3005 ? scm_is_true (scm_negative_p ($1))
3006 : !Text_interface::is_markup ($1))
3008 parser->parser_error (@1, _ ("bass number expected"));
3014 figured_bass_alteration:
3015 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3016 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3017 | '!' { $$ = scm_from_int (0); }
3022 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3023 $$ = bfr->unprotect ();
3026 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3027 $$ = bfr->self_scm ();
3029 if (scm_is_number ($1))
3030 bfr->set_property ("figure", $1);
3031 else if (Text_interface::is_markup ($1))
3032 bfr->set_property ("text", $1);
3038 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3040 | bass_figure figured_bass_alteration {
3041 Music *m = unsmob_music ($1);
3042 if (scm_to_double ($2)) {
3043 SCM salter = m->get_property ("alteration");
3044 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3045 m->set_property ("alteration",
3046 scm_sum (alter, $2));
3048 m->set_property ("alteration", scm_from_int (0));
3051 | bass_figure figured_bass_modification {
3052 Music *m = unsmob_music ($1);
3053 m->set_property ($2, SCM_BOOL_T);
3058 figured_bass_modification:
3060 $$ = ly_symbol2scm ("augmented");
3063 $$ = ly_symbol2scm ("no-continuation");
3066 $$ = ly_symbol2scm ("diminished");
3069 $$ = ly_symbol2scm ("augmented-slash");
3079 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3087 | figure_list br_bass_figure {
3088 $$ = scm_cons ($2, $1);
3093 FIGURE_OPEN figure_list FIGURE_CLOSE {
3094 $$ = scm_reverse_x ($2, SCM_EOL);
3100 /**/ { $$ = SCM_BOOL_F; }
3101 | REST { $$ = SCM_BOOL_T; }
3105 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3106 if (!parser->lexer_->is_note_state ())
3107 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3108 if (!SCM_UNBNDP ($2)
3110 || scm_is_number ($4)
3113 || scm_is_pair ($7))
3116 if (scm_is_true ($6))
3117 n = MY_MAKE_MUSIC ("RestEvent", @$);
3119 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3121 n->set_property ("pitch", $1);
3122 if (SCM_UNBNDP ($5))
3123 n->set_property ("duration",
3124 parser->default_duration_.smobbed_copy ());
3126 n->set_property ("duration", $5);
3128 if (scm_is_number ($4))
3130 int q = scm_to_int ($4);
3131 n->set_property ("absolute-octave", scm_from_int (q-1));
3134 if (to_boolean ($3))
3135 n->set_property ("cautionary", SCM_BOOL_T);
3136 if (to_boolean ($2) || to_boolean ($3))
3137 n->set_property ("force-accidental", SCM_BOOL_T);
3138 if (scm_is_pair ($7))
3139 n->set_property ("articulations",
3140 scm_reverse_x ($7, SCM_EOL));
3141 $$ = n->unprotect ();
3144 | simple_chord_elements post_events {
3145 if (scm_is_pair ($2)) {
3146 if (unsmob_pitch ($1))
3147 $1 = make_chord_elements (@1,
3149 parser->default_duration_.smobbed_copy (),
3152 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3154 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
3155 } else if (!unsmob_pitch ($1))
3156 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
3157 // A mere pitch drops through.
3162 DRUM_PITCH optional_notemode_duration {
3163 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3164 n->set_property ("duration", $2);
3165 n->set_property ("drum-type", $1);
3167 $$ = n->unprotect ();
3169 | RESTNAME optional_notemode_duration {
3171 if (ly_scm2string ($1) == "s") {
3173 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3176 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3179 ev->set_property ("duration", $2);
3180 $$ = ev->unprotect ();
3184 // Can return a single pitch rather than a list.
3185 simple_chord_elements:
3187 if (!parser->lexer_->is_chord_state ())
3188 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3191 | figure_spec optional_notemode_duration {
3192 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3194 unsmob_music (scm_car (s))->set_property ("duration", $2);
3202 if (!parser->lexer_->is_lyric_state ())
3203 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3207 if (!parser->lexer_->is_lyric_state ())
3208 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3214 lyric_element_music:
3215 lyric_element optional_notemode_duration post_events {
3216 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3217 if (scm_is_pair ($3))
3218 unsmob_music ($$)->set_property
3219 ("articulations", scm_reverse_x ($3, SCM_EOL));
3223 // Can return a single pitch rather than a list.
3225 steno_tonic_pitch maybe_notemode_duration {
3226 if (SCM_UNBNDP ($2))
3229 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3231 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3232 SCM its = scm_reverse_x ($4, SCM_EOL);
3233 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3241 | chord_items chord_item {
3242 $$ = scm_cons ($2, $$);
3248 $$ = ly_symbol2scm ("chord-colon");
3251 $$ = ly_symbol2scm ("chord-caret");
3253 | CHORD_SLASH steno_tonic_pitch {
3254 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3256 | CHORD_BASS steno_tonic_pitch {
3257 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3266 $$ = scm_reverse_x ($1, SCM_EOL);
3274 step_number { $$ = scm_cons ($1, SCM_EOL); }
3275 | step_numbers '.' step_number {
3276 $$ = scm_cons ($3, $$);
3282 $$ = make_chord_step ($1, 0);
3285 $$ = make_chord_step ($1, SHARP_ALTERATION);
3287 | UNSIGNED CHORD_MINUS {
3288 $$ = make_chord_step ($1, FLAT_ALTERATION);
3296 | unsigned_number '-' unsigned_number {
3297 $$ = scm_cons ($1, $3);
3304 TODO: should deprecate in favor of Scheme?
3308 number_expression '+' number_term {
3309 $$ = scm_sum ($1, $3);
3311 | number_expression '-' number_term {
3312 $$ = scm_difference ($1, $3);
3321 | number_factor '*' number_factor {
3322 $$ = scm_product ($1, $3);
3324 | number_factor '/' number_factor {
3325 $$ = scm_divide ($1, $3);
3330 '-' number_factor { /* %prec UNARY_MINUS */
3331 $$ = scm_difference ($2, SCM_UNDEFINED);
3339 | REAL NUMBER_IDENTIFIER
3341 $$ = scm_product ($1, $2);
3348 | UNSIGNED NUMBER_IDENTIFIER {
3349 $$ = scm_product ($1, $2);
3357 if (!scm_is_integer ($1)
3358 || scm_is_true (scm_negative_p ($1)))
3360 parser->parser_error (@1, _("not an unsigned integer"));
3366 if (!scm_is_integer ($1)
3367 || scm_is_true (scm_negative_p ($1)))
3369 parser->parser_error (@1, _("not an unsigned integer"));
3376 { $$ = SCM_UNDEFINED; }
3379 if (SCM_UNBNDP ($1))
3387 // This precedence rule is rather weird. It triggers when '!' is
3388 // encountered after a pitch, and is used for deciding whether to save
3389 // this instead for a figure modification. This should not actually
3390 // occur in practice as pitches and figures are generated in different
3391 // modes. Using a greedy (%right) precedence makes sure that we don't
3392 // get stuck in a wrong interpretation.
3393 { $$ = SCM_UNDEFINED; } %prec ':'
3396 if (SCM_UNBNDP ($1))
3405 { parser->lexer_->push_markup_state (); }
3408 parser->lexer_->pop_state ();
3414 { parser->lexer_->push_markup_state (); }
3417 parser->lexer_->pop_state ();
3423 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3425 | markup_head_1_list simple_markup
3427 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3428 @2, $1, scm_list_1 ($2)));
3438 if (Text_interface::is_markup ($1))
3439 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3440 else if (Text_interface::is_markup_list ($1))
3441 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3443 parser->parser_error (@1, _ ("not a markup"));
3444 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3451 markup_composed_list {
3454 | markup_uncomposed_list
3457 markup_uncomposed_list:
3458 markup_braced_list {
3461 | markup_command_list {
3462 $$ = scm_list_1 ($1);
3464 | markup_scm MARKUPLIST_IDENTIFIER
3469 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3470 parser->lexer_->push_note_state (nn);
3471 } '{' score_body '}' {
3472 unsmob_score ($4)->origin ()->set_spot (@$);
3473 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3474 parser->lexer_->pop_state ();
3478 markup_composed_list:
3479 markup_head_1_list markup_uncomposed_list {
3480 $$ = MAKE_SYNTAX ("composed-markup-list",
3486 '{' markup_braced_list_body '}' {
3487 $$ = scm_reverse_x ($2, SCM_EOL);
3491 markup_braced_list_body:
3492 /* empty */ { $$ = SCM_EOL; }
3493 | markup_braced_list_body markup {
3494 $$ = scm_cons ($2, $1);
3496 | markup_braced_list_body markup_list {
3497 $$ = scm_reverse_x ($2, $1);
3501 markup_command_list:
3502 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3503 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3507 markup_command_basic_arguments:
3508 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3509 $$ = scm_cons ($3, $2);
3511 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3512 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3514 | EXPECT_NO_MORE_ARGS {
3519 markup_command_list_arguments:
3520 markup_command_basic_arguments { $$ = $1; }
3521 | EXPECT_MARKUP markup_command_list_arguments markup {
3522 $$ = scm_cons ($3, $2);
3527 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3528 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3533 markup_head_1_item {
3534 $$ = scm_list_1 ($1);
3536 | markup_head_1_list markup_head_1_item {
3537 $$ = scm_cons ($2, $1);
3543 $$ = make_simple_markup ($1);
3546 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3547 parser->lexer_->push_note_state (nn);
3548 } '{' score_body '}' {
3549 unsmob_score ($4)->origin ()->set_spot (@$);
3550 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3551 parser->lexer_->pop_state ();
3553 | MARKUP_FUNCTION markup_command_basic_arguments {
3554 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3556 | markup_scm MARKUP_IDENTIFIER
3563 markup_head_1_list simple_markup
3565 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3566 @2, $1, scm_list_1 ($2)));
3576 Lily_parser::set_yydebug (bool x)
3582 Lily_parser::do_yyparse ()
3584 SCM retval = SCM_UNDEFINED;
3585 yyparse (this, &retval);
3595 It is a little strange to have this function in this file, but
3596 otherwise, we have to import music classes into the lexer.
3600 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3602 if (unsmob_book (sid)) {
3603 Book *book = unsmob_book (sid)->clone ();
3604 *destination = book->self_scm ();
3607 return BOOK_IDENTIFIER;
3608 } else if (scm_is_number (sid)) {
3610 return NUMBER_IDENTIFIER;
3611 } else if (unsmob_context_def (sid)) {
3612 Context_def *def= unsmob_context_def (sid)->clone ();
3614 *destination = def->self_scm ();
3617 return CONTEXT_DEF_IDENTIFIER;
3618 } else if (unsmob_context_mod (sid)) {
3619 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3621 return CONTEXT_MOD_IDENTIFIER;
3622 } else if (Music *mus = unsmob_music (sid)) {
3623 mus = mus->clone ();
3624 *destination = mus->self_scm ();
3625 bool is_event = mus->is_mus_type ("post-event");
3627 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3628 } else if (unsmob_pitch (sid)) {
3629 *destination = unsmob_pitch (sid)->smobbed_copy ();
3630 return PITCH_IDENTIFIER;
3631 } else if (unsmob_duration (sid)) {
3632 *destination = unsmob_duration (sid)->smobbed_copy ();
3633 return DURATION_IDENTIFIER;
3634 } else if (unsmob_output_def (sid)) {
3635 *destination = unsmob_output_def (sid)->clone ()->unprotect ();
3636 return SCM_IDENTIFIER;
3637 } else if (unsmob_score (sid)) {
3638 *destination = unsmob_score (sid)->clone ()->unprotect ();
3639 return SCM_IDENTIFIER;
3646 get_next_unique_context_id ()
3648 return scm_from_locale_string ("$uniqueContextId");
3653 get_next_unique_lyrics_context_id ()
3655 static int new_context_count;
3657 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3658 return scm_from_locale_string (s);
3661 // check_scheme_arg checks one argument with a given predicate for use
3662 // in an argument list and throws a syntax error if it is unusable.
3663 // The argument is prepended to the argument list in any case. After
3664 // throwing a syntax error, the argument list is terminated with #f as
3665 // its last cdr in order to mark it as uncallable while not losing
3666 // track of its total length.
3668 // There are a few special considerations: if optional argument disp
3669 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3670 // instead of arg in a prospective error message. This is useful if
3671 // arg is not the actual argument but rather a transformation of it.
3673 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3674 // and an error message using disp is produced unconditionally.
3676 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3677 SCM arg, SCM args, SCM pred, SCM disp)
3679 if (SCM_UNBNDP (arg))
3680 args = scm_cons (disp, args);
3682 args = scm_cons (arg, args);
3683 if (scm_is_true (scm_call_1 (pred, arg)))
3686 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3687 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3688 SCM_UNBNDP (disp) ? arg : disp);
3689 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3693 SCM loc_on_music (Input loc, SCM arg)
3695 if (Music *m = unsmob_music (arg))
3699 return m->unprotect ();
3705 try_string_variants (SCM pred, SCM str)
3707 // a matching predicate is always ok
3708 if (scm_is_true (scm_call_1 (pred, str)))
3710 // a symbol may be interpreted as a list of symbols if it helps
3711 if (scm_is_symbol (str)) {
3712 str = scm_list_1 (str);
3713 if (scm_is_true (scm_call_1 (pred, str)))
3715 return SCM_UNDEFINED;
3718 // If this cannot be a string representation of a symbol list,
3721 if (!is_regular_identifier (str, true))
3722 return SCM_UNDEFINED;
3724 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3725 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3726 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3728 // Let's attempt the symbol list interpretation first.
3730 if (scm_is_true (scm_call_1 (pred, str)))
3733 // If there is just one symbol in the list, we might interpret
3734 // it as a single symbol
3736 if (scm_is_null (scm_cdr (str)))
3738 str = scm_car (str);
3739 if (scm_is_true (scm_call_1 (pred, str)))
3743 return SCM_UNDEFINED;
3747 is_regular_identifier (SCM id, bool multiple)
3749 if (!scm_is_string (id))
3752 string str = ly_scm2string (id);
3754 bool middle = false;
3756 for (string::iterator it=str.begin(); it != str.end (); it++)
3759 if ((c >= 'a' && c <= 'z')
3760 || (c >= 'A' && c <= 'Z')
3763 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3772 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3774 if (unsmob_music (simple))
3776 if (parser->lexer_->is_note_state ()) {
3777 if (scm_is_symbol (simple)) {
3778 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3779 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3780 n->set_property ("drum-type", simple);
3781 return n->unprotect ();
3783 if (unsmob_pitch (simple)) {
3784 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3785 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3786 n->set_property ("pitch", simple);
3787 return n->unprotect ();
3790 } else if (parser->lexer_->is_lyric_state ()) {
3791 if (Text_interface::is_markup (simple))
3792 return MAKE_SYNTAX ("lyric-event", loc, simple,
3793 parser->default_duration_.smobbed_copy ());
3794 } else if (parser->lexer_->is_chord_state ()) {
3795 if (unsmob_pitch (simple))
3799 make_chord_elements (loc, simple,
3800 parser->default_duration_.smobbed_copy (),
3807 make_music_with_input (SCM name, Input where)
3809 Music *m = make_music_by_name (name);
3810 m->set_spot (where);
3815 make_simple_markup (SCM a)
3821 make_duration (SCM d, int dots)
3823 int t = scm_to_int (d);
3824 if (t > 0 && (t & (t-1)) == 0)
3825 return Duration (intlog2 (t), dots).smobbed_copy ();
3827 return SCM_UNDEFINED;
3831 make_chord_step (SCM step_scm, Rational alter)
3833 int step = scm_to_int (step_scm);
3836 alter += FLAT_ALTERATION;
3840 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3841 return m.smobbed_copy ();
3846 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3848 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3849 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3850 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3852 unsmob_music (scm_car (s))->set_spot (loc);
3858 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3860 Lily_lexer *lex = parser->lexer_;
3864 int tok = lex->pop_extra_token ();
3867 lex->prepare_for_next_token ();
3868 return lex->yylex ();