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--2015 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 = Display::value_to_lily_string (value); \
45 char *p = scm_to_locale_string (s); \
52 %parse-param {Lily_parser *parser}
53 %parse-param {SCM *retval}
54 %lex-param {Lily_parser *parser}
58 /* We use SCMs to do strings, because it saves us the trouble of
59 deleting them. Let's hope that a stack overflow doesn't trigger a move
60 of the parse stack onto the heap. */
66 /* The above precedences tackle the shift/reduce problem
69 \repeat .. \alternative
71 \repeat { \repeat .. \alternative }
75 \repeat { \repeat } \alternative
81 %right ':' UNSIGNED REAL E_UNSIGNED EVENT_IDENTIFIER EVENT_FUNCTION '^' '_'
82 HYPHEN EXTENDER DURATION_IDENTIFIER '!'
84 /* The above are needed for collecting tremoli and other items (that
85 could otherwise be interpreted as belonging to the next function
86 argument) greedily, and together with the next rule will serve to
87 join numbers and units greedily instead of allowing them into
88 separate function arguments
91 %nonassoc NUMBER_IDENTIFIER
103 %{ // -*-Fundamental-*-
108 * The rules for who is protecting what are very shady. Uniformise
111 * There are too many lexical modes?
122 #include "context-def.hh"
123 #include "context-mod.hh"
124 #include "dimensions.hh"
125 #include "file-path.hh"
127 #include "international.hh"
128 #include "lily-guile.hh"
129 #include "lily-lexer.hh"
130 #include "lily-parser.hh"
131 #include "ly-module.hh"
135 #include "output-def.hh"
136 #include "paper-book.hh"
137 #include "scm-hash.hh"
139 #include "text-interface.hh"
141 #include "lily-imports.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 - delay application of the function
193 #define LOWLEVEL_MAKE_SYNTAX(location, proc, ...) \
195 (parser->lexer_->override_input (location).smobbed_copy (), \
199 /* Syntactic Sugar. */
200 #define MAKE_SYNTAX(name, location, ...) \
201 LOWLEVEL_MAKE_SYNTAX (location, Syntax::name, ##__VA_ARGS__)
203 #define START_MAKE_SYNTAX(name, ...) \
204 scm_list_n (Syntax::name, ##__VA_ARGS__, SCM_UNDEFINED)
206 #define FINISH_MAKE_SYNTAX(start, location, ...) \
207 LOWLEVEL_MAKE_SYNTAX \
212 (scm_list_2 (scm_cdr (start), \
213 scm_list_n (__VA_ARGS__, SCM_UNDEFINED))))
215 SCM get_next_unique_context_id ();
216 SCM get_next_unique_lyrics_context_id ();
223 #define _(x) gettext (x)
227 static Music *make_music_with_input (SCM name, Input where);
228 SCM check_scheme_arg (Lily_parser *parser, Input loc,
229 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
230 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
231 SCM loc_on_music (Input loc, SCM arg);
232 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
233 SCM make_chord_step (SCM step, Rational alter);
234 SCM make_simple_markup (SCM a);
235 SCM make_duration (SCM t, int dots = 0);
236 bool is_regular_identifier (SCM id, bool multiple=false);
237 SCM try_string_variants (SCM pred, SCM str);
238 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
242 /* The third option is an alias that will be used to display the
243 syntax error. Bison CVS now correctly handles backslash escapes.
245 FIXME: Bison needs to translate some of these, eg, STRING.
249 /* Keyword tokens with plain escaped name. */
250 %token END_OF_FILE 0 "end of input"
251 %token ACCEPTS "\\accepts"
252 %token ADDLYRICS "\\addlyrics"
253 %token ALIAS "\\alias"
254 %token ALTERNATIVE "\\alternative"
256 %token BOOKPART "\\bookpart"
257 %token CHANGE "\\change"
258 %token CHORDMODE "\\chordmode"
259 %token CHORDS "\\chords"
260 %token CONSISTS "\\consists"
261 %token CONTEXT "\\context"
262 %token DEFAULT "\\default"
263 %token DEFAULTCHILD "\\defaultchild"
264 %token DENIES "\\denies"
265 %token DESCRIPTION "\\description"
266 %token DRUMMODE "\\drummode"
267 %token DRUMS "\\drums"
268 %token FIGUREMODE "\\figuremode"
269 %token FIGURES "\\figures"
270 %token HEADER "\\header"
271 %token INVALID "\\version-error"
272 %token LAYOUT "\\layout"
273 %token LYRICMODE "\\lyricmode"
274 %token LYRICS "\\lyrics"
275 %token LYRICSTO "\\lyricsto"
276 %token MARKUP "\\markup"
277 %token MARKUPLIST "\\markuplist"
280 %token NOTEMODE "\\notemode"
281 %token OVERRIDE "\\override"
282 %token PAPER "\\paper"
283 %token REMOVE "\\remove"
284 %token REPEAT "\\repeat"
286 %token REVERT "\\revert"
287 %token SCORE "\\score"
288 %token SCORELINES "\\score-lines"
289 %token SEQUENTIAL "\\sequential"
291 %token SIMULTANEOUS "\\simultaneous"
292 %token TEMPO "\\tempo"
294 %token UNSET "\\unset"
297 /* Keyword token exceptions. */
298 %token NEWCONTEXT "\\new"
301 /* Other string tokens. */
303 %token CHORD_BASS "/+"
304 %token CHORD_CARET "^"
305 %token CHORD_COLON ":"
306 %token CHORD_MINUS "-"
307 %token CHORD_SLASH "/"
308 %token ANGLE_OPEN "<"
309 %token ANGLE_CLOSE ">"
310 %token DOUBLE_ANGLE_OPEN "<<"
311 %token DOUBLE_ANGLE_CLOSE ">>"
312 %token E_BACKSLASH "\\"
313 %token E_EXCLAMATION "\\!"
318 If we give names, Bison complains.
320 %token FIGURE_CLOSE /* "\\>" */
321 %token FIGURE_OPEN /* "\\<" */
322 %token FIGURE_SPACE "_"
325 %token MULTI_MEASURE_REST
331 /* Artificial tokens, for more generic function syntax */
332 %token EXPECT_MARKUP "markup?"
333 %token EXPECT_SCM "scheme?"
334 %token BACKUP "(backed-up?)"
335 %token REPARSE "(reparsed?)"
336 %token EXPECT_MARKUP_LIST "markup-list?"
337 %token EXPECT_OPTIONAL "optional?"
338 /* After the last argument. */
339 %token EXPECT_NO_MORE_ARGS;
341 /* An artificial token for parsing embedded Lilypond */
342 %token EMBEDDED_LILY "#{"
344 %token BOOK_IDENTIFIER
345 %token CHORD_MODIFIER
346 %token CHORD_REPETITION
347 %token CONTEXT_MOD_IDENTIFIER
349 %token PITCH_IDENTIFIER
350 %token DURATION_IDENTIFIER
351 %token EVENT_IDENTIFIER
352 %token EVENT_FUNCTION
355 %token MARKUP_FUNCTION
356 %token MARKUP_LIST_FUNCTION
357 %token MARKUP_IDENTIFIER
358 %token MARKUPLIST_IDENTIFIER
359 %token MUSIC_FUNCTION
360 %token MUSIC_IDENTIFIER
361 %token NOTENAME_PITCH
362 %token NUMBER_IDENTIFIER
367 %token SCM_IDENTIFIER
371 %token TONICNAME_PITCH
375 /* We don't assign precedence to / and *, because we might need varied
376 prec levels in different prods */
385 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
386 parser->lexer_->push_note_state (nn);
387 } embedded_lilypond {
388 parser->lexer_->pop_state ();
393 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
394 | lilypond toplevel_expression {
396 | lilypond assignment {
399 parser->error_level_ = 1;
402 parser->error_level_ = 1;
409 parser->lexer_->add_scope (get_header (parser));
411 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
414 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
415 scm_call_1 (proc, $1);
418 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
419 scm_call_1 (proc, $1);
422 SCM proc = parser->lexer_->lookup_identifier
423 (unsmob<Book>($1)->paper_
424 ? "toplevel-book-handler"
425 : "toplevel-bookpart-handler");
426 scm_call_1 (proc, $1);
429 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
430 scm_call_1 (proc, $1);
433 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
434 scm_call_1 (proc, $1);
437 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
438 scm_call_1 (proc, scm_list_1 ($1));
441 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
442 scm_call_1 (proc, $1);
445 // Evaluate and ignore #xxx, as opposed to \xxx
446 parser->lexer_->eval_scm_token ($1, @1);
448 | embedded_scm_active
450 SCM out = SCM_UNDEFINED;
451 if (Text_interface::is_markup ($1))
452 out = scm_list_1 ($1);
453 else if (Text_interface::is_markup_list ($1))
455 if (scm_is_pair (out))
457 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
458 scm_call_1 (proc, out);
459 } else if (unsmob<Score> ($1))
461 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
462 scm_call_1 (proc, $1);
463 } else if (Output_def * od = unsmob<Output_def> ($1)) {
466 if (to_boolean (od->c_variable ("is-paper")))
467 id = ly_symbol2scm ("$defaultpaper");
468 else if (to_boolean (od->c_variable ("is-midi")))
469 id = ly_symbol2scm ("$defaultmidi");
470 else if (to_boolean (od->c_variable ("is-layout")))
471 id = ly_symbol2scm ("$defaultlayout");
473 parser->lexer_->set_identifier (id, $1);
474 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
475 parser->parser_error (@1, _("bad expression type"));
479 Output_def * od = unsmob<Output_def> ($1);
481 if (to_boolean (od->c_variable ("is-paper")))
482 id = ly_symbol2scm ("$defaultpaper");
483 else if (to_boolean (od->c_variable ("is-midi")))
484 id = ly_symbol2scm ("$defaultmidi");
485 else if (to_boolean (od->c_variable ("is-layout")))
486 id = ly_symbol2scm ("$defaultlayout");
488 parser->lexer_->set_identifier (id, $1);
495 $$ = parser->lexer_->eval_scm_token ($1, @1);
505 embedded_scm_bare_arg:
509 $$ = parser->lexer_->eval_scm_token ($1, @1);
513 | context_modification
515 | context_def_spec_block
521 /* The generic version may end in music, or not */
528 /* embedded_scm_arg is _not_ casting pitches to music by default, this
529 * has to be done by the function itself. Note that this may cause
530 * the results of scm_function_call or embedded_scm_bare_arg to be
531 * turned into music from pitches as well. Note that this creates a
532 * distinctly awkward situation for calculated drum pitches. Those
533 * are at the current point of time rejected as music constituents as
534 * they can't be distinguished from "proper" symbols.
538 embedded_scm_bare_arg
544 SCM_FUNCTION function_arglist {
545 $$ = MAKE_SYNTAX (music_function, @$,
550 embedded_lilypond_number:
551 '-' embedded_lilypond_number
553 $$ = scm_difference ($2, SCM_UNDEFINED);
556 | UNSIGNED NUMBER_IDENTIFIER
558 $$ = scm_product ($1, $2);
565 // FIXME: @$ does not contain a useful source location
566 // for empty rules, and the only token in the whole
567 // production, EMBEDDED_LILY, is synthetic and also
568 // contains no source location.
569 $$ = MAKE_SYNTAX (void_music, @$);
571 | identifier_init_nonumber
572 | embedded_lilypond_number
573 | post_event post_events
575 $$ = scm_reverse_x ($2, SCM_EOL);
576 if (Music *m = unsmob<Music> ($1))
578 if (m->is_mus_type ("post-event-wrapper"))
580 (scm_list_2 (m->get_property ("elements"),
583 $$ = scm_cons ($1, $$);
586 && scm_is_null (scm_cdr ($$)))
590 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
591 m->set_property ("elements", $$);
592 $$ = m->unprotect ();
595 | multiplied_duration
596 | music_embedded music_embedded music_list {
597 $3 = scm_reverse_x ($3, SCM_EOL);
598 if (unsmob<Music> ($2))
599 $3 = scm_cons ($2, $3);
600 if (unsmob<Music> ($1))
601 $3 = scm_cons ($1, $3);
602 $$ = MAKE_SYNTAX (sequential_music, @$, $3);
605 parser->error_level_ = 1;
606 $$ = SCM_UNSPECIFIED;
608 | INVALID embedded_lilypond {
609 parser->error_level_ = 1;
615 lilypond_header_body:
616 /* empty */ { $$ = SCM_UNSPECIFIED; }
617 | lilypond_header_body assignment {
620 | lilypond_header_body embedded_scm {
626 HEADER '{' lilypond_header_body '}' {
627 $$ = parser->lexer_->remove_scope ();
639 assignment_id '=' identifier_init {
640 parser->lexer_->set_identifier ($1, $3);
641 $$ = SCM_UNSPECIFIED;
643 | assignment_id property_path '=' identifier_init {
644 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
645 parser->lexer_->set_identifier (path, $4);
646 $$ = SCM_UNSPECIFIED;
648 | assignment_id '.' property_path '=' identifier_init {
649 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
650 parser->lexer_->set_identifier (path, $5);
651 $$ = SCM_UNSPECIFIED;
657 identifier_init_nonumber
659 | post_event_nofinger post_events
661 $$ = scm_reverse_x ($2, SCM_EOL);
662 if (Music *m = unsmob<Music> ($1))
664 if (m->is_mus_type ("post-event-wrapper"))
666 (scm_list_2 (m->get_property ("elements"),
669 $$ = scm_cons ($1, $$);
672 && scm_is_null (scm_cdr ($$)))
676 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
677 m->set_property ("elements", $$);
678 $$ = m->unprotect ();
683 identifier_init_nonumber:
688 | context_def_spec_block
695 | context_modification
698 context_def_spec_block:
699 CONTEXT '{' context_def_spec_body '}'
702 Context_def *td = unsmob<Context_def> ($$);
704 $$ = Context_def::make_scm ();
705 td = unsmob<Context_def> ($$);
707 td->origin ()->set_spot (@$);
715 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
716 parser->lexer_->push_note_state (nn);
720 parser->lexer_->pop_state ();
726 context_def_spec_body:
728 $$ = SCM_UNSPECIFIED;
730 | context_def_spec_body context_mod {
731 if (!SCM_UNBNDP ($2)) {
732 Context_def *td = unsmob<Context_def> ($$);
734 $$ = Context_def::make_scm ();
735 td = unsmob<Context_def> ($$);
737 unsmob<Context_def> ($$)->add_context_mod ($2);
740 | context_def_spec_body context_modification {
741 Context_def *td = unsmob<Context_def> ($$);
743 $$ = Context_def::make_scm ();
744 td = unsmob<Context_def> ($$);
746 SCM new_mods = unsmob<Context_mod> ($2)->get_mods ();
747 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
748 td->add_context_mod (scm_car (m));
751 | context_def_spec_body context_mod_arg {
752 Context_def *td = unsmob<Context_def> ($1);
753 if (scm_is_eq ($2, SCM_UNSPECIFIED))
755 else if (!td && unsmob<Context_def> ($2))
759 $$ = Context_def::make_scm ();
760 td = unsmob<Context_def> ($$);
762 if (unsmob<Music> ($2)) {
763 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
764 $2 = scm_call_1 (proc, $2);
766 if (Context_mod *cm = unsmob<Context_mod> ($2)) {
767 for (SCM m = cm->get_mods (); scm_is_pair (m); m = scm_cdr (m)) {
768 td->add_context_mod (scm_car (m));
771 parser->parser_error (@2, _ ("not a context mod"));
779 BOOK '{' book_body '}' {
781 unsmob<Book> ($$)->origin ()->set_spot (@$);
783 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
788 * Use 'handlers' like for toplevel-* stuff?
789 * grok \layout and \midi? */
792 Book *book = new Book;
793 init_papers (parser);
794 book->paper_ = dynamic_cast<Output_def*> (unsmob<Output_def> (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
795 book->paper_->unprotect ();
796 push_paper (parser, book->paper_);
797 book->header_ = get_header (parser);
798 $$ = book->unprotect ();
799 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
802 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
804 | book_body paper_block {
805 unsmob<Book> ($1)->paper_ = unsmob<Output_def> ($2);
806 set_paper (parser, unsmob<Output_def> ($2));
808 | book_body bookpart_block {
809 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
810 scm_call_2 (proc, $1, $2);
812 | book_body score_block {
813 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
814 scm_call_2 (proc, $1, $2);
816 | book_body composite_music {
817 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
818 scm_call_2 (proc, $1, $2);
820 | book_body full_markup {
821 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
822 scm_call_2 (proc, $1, scm_list_1 ($2));
824 | book_body full_markup_list {
825 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
826 scm_call_2 (proc, $1, $2);
828 | book_body SCM_TOKEN {
829 // Evaluate and ignore #xxx, as opposed to \xxx
830 parser->lexer_->eval_scm_token ($2, @2);
832 | book_body embedded_scm_active
834 SCM out = SCM_UNDEFINED;
835 if (Text_interface::is_markup ($2))
836 out = scm_list_1 ($2);
837 else if (Text_interface::is_markup_list ($2))
839 if (scm_is_pair (out))
841 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
842 scm_call_2 (proc, $1, out);
843 } else if (unsmob<Score> ($2))
845 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
846 scm_call_2 (proc, $1, $2);
847 } else if (Output_def *od = unsmob<Output_def> ($2)) {
850 if (to_boolean (od->c_variable ("is-paper")))
851 id = ly_symbol2scm ("$defaultpaper");
852 else if (to_boolean (od->c_variable ("is-midi")))
853 id = ly_symbol2scm ("$defaultmidi");
854 else if (to_boolean (od->c_variable ("is-layout")))
855 id = ly_symbol2scm ("$defaultlayout");
857 parser->lexer_->set_identifier (id, $2);
858 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
859 parser->parser_error (@2, _("bad expression type"));
863 parser->lexer_->add_scope (unsmob<Book> ($1)->header_);
866 Book *book = unsmob<Book> ($1);
868 book->scores_ = SCM_EOL;
869 book->bookparts_ = SCM_EOL;
874 BOOKPART '{' bookpart_body '}' {
876 unsmob<Book> ($$)->origin ()->set_spot (@$);
877 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
883 Book *book = new Book;
884 $$ = book->unprotect ();
885 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
888 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
890 | bookpart_body paper_block {
891 unsmob<Book> ($$)->paper_ = unsmob<Output_def> ($2);
893 | bookpart_body score_block {
894 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
895 scm_call_2 (proc, $1, $2);
897 | bookpart_body composite_music {
898 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
899 scm_call_2 (proc, $1, $2);
901 | bookpart_body full_markup {
902 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
903 scm_call_2 (proc, $1, scm_list_1 ($2));
905 | bookpart_body full_markup_list {
906 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
907 scm_call_2 (proc, $1, $2);
909 | bookpart_body SCM_TOKEN {
910 // Evaluate and ignore #xxx, as opposed to \xxx
911 parser->lexer_->eval_scm_token ($2, @2);
913 | bookpart_body embedded_scm_active
915 SCM out = SCM_UNDEFINED;
916 if (Text_interface::is_markup ($2))
917 out = scm_list_1 ($2);
918 else if (Text_interface::is_markup_list ($2))
920 if (scm_is_pair (out))
922 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
923 scm_call_2 (proc, $1, out);
924 } else if (unsmob<Score> ($2))
926 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
927 scm_call_2 (proc, $1, $2);
928 } else if (Output_def *od = unsmob<Output_def> ($2)) {
931 if (to_boolean (od->c_variable ("is-paper")))
932 id = ly_symbol2scm ("$defaultpaper");
933 else if (to_boolean (od->c_variable ("is-midi")))
934 id = ly_symbol2scm ("$defaultmidi");
935 else if (to_boolean (od->c_variable ("is-layout")))
936 id = ly_symbol2scm ("$defaultlayout");
938 parser->lexer_->set_identifier (id, $2);
939 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
940 parser->parser_error (@2, _("bad expression type"));
944 Book *book = unsmob<Book> ($1);
945 if (!ly_is_module (book->header_))
946 book->header_ = ly_make_module (false);
947 parser->lexer_->add_scope (book->header_);
949 | bookpart_body error {
950 Book *book = unsmob<Book> ($1);
952 book->scores_ = SCM_EOL;
957 SCORE '{' score_body '}' {
958 unsmob<Score> ($3)->origin ()->set_spot (@$);
965 if (!unsmob<Score> ($1)) {
966 parser->parser_error (@1, _("Missing music in \\score"));
967 $$ = (new Score)->unprotect ();
968 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
970 unsmob<Score> ($$)->set_header (scm_car ($1));
973 for (SCM p = scm_reverse_x ($1, SCM_EOL);
974 scm_is_pair (p); p = scm_cdr (p))
977 add_output_def (unsmob<Output_def> (scm_car (p)));
982 unsmob<Score> ($$)->error_found_ = true;
997 | score_items score_item
999 Output_def *od = unsmob<Output_def> ($2);
1001 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1003 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1005 $2 = SCM_UNSPECIFIED;
1007 } else if (!unsmob<Score> ($$)) {
1008 if (unsmob<Music> ($2)) {
1009 $2 = Lily::scorify_music ($2);
1011 if (unsmob<Score> ($2))
1014 $2 = SCM_UNSPECIFIED;
1017 Score *score = unsmob<Score> ($$);
1018 if (score && scm_is_pair ($1)) {
1019 if (ly_is_module (scm_car ($1)))
1021 score->set_header (scm_car ($1));
1024 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1025 scm_is_pair (p); p = scm_cdr (p))
1027 score->add_output_def (unsmob<Output_def> (scm_car (p)));
1032 score->add_output_def (od);
1033 else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1034 scm_set_cdr_x ($$, scm_cons ($2, scm_cdr ($$)));
1036 $$ = scm_cons ($2, $$);
1037 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1038 parser->parser_error (@2, _("Spurious expression in \\score"));
1042 if (Score *score = unsmob<Score> ($1)) {
1043 if (!ly_is_module (score->get_header ()))
1044 score->set_header (ly_make_module (false));
1045 parser->lexer_->add_scope (score->get_header ());
1047 if (!scm_is_pair ($1) || !ly_is_module (scm_car ($1)))
1048 $1 = scm_cons (ly_make_module (false), $1);
1049 parser->lexer_->add_scope (scm_car ($1));
1064 Output_def *od = unsmob<Output_def> ($1);
1066 if (!to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1068 parser->parser_error (@1, _ ("need \\paper for paper block"));
1069 $$ = get_paper (parser)->unprotect ();
1076 output_def_body '}' {
1077 if (scm_is_pair ($1))
1080 parser->lexer_->remove_scope ();
1081 parser->lexer_->pop_state ();
1087 Output_def *p = get_paper (parser);
1088 p->input_origin_ = @$;
1089 parser->lexer_->add_scope (p->scope_);
1090 $$ = p->unprotect ();
1093 Output_def *p = get_midi (parser);
1094 $$ = p->unprotect ();
1095 parser->lexer_->add_scope (p->scope_);
1098 Output_def *p = get_layout (parser);
1100 parser->lexer_->add_scope (p->scope_);
1101 $$ = p->unprotect ();
1105 output_def_head_with_mode_switch:
1107 parser->lexer_->push_initial_state ();
1112 // We need this weird nonterminal because both music as well as a
1113 // context definition can start with \context and the difference is
1114 // only apparent after looking at the next token. If it is '{', there
1115 // is still time to escape from notes mode.
1117 music_or_context_def:
1119 | context_def_spec_block
1123 output_def_head_with_mode_switch '{' {
1124 unsmob<Output_def> ($1)->input_origin_.set_spot (@$);
1125 // This is a stupid trick to mark the beginning of the
1126 // body for deciding whether to allow
1127 // embedded_scm_active to have an output definition
1128 $$ = scm_list_1 ($1);
1130 | output_def_body assignment {
1131 if (scm_is_pair ($1))
1134 | output_def_body embedded_scm_active
1136 // We don't switch into note mode for Scheme functions
1137 // here. Does not seem warranted/required in output
1139 if (scm_is_pair ($1))
1141 Output_def *o = unsmob<Output_def> ($2);
1143 o->input_origin_.set_spot (@$);
1144 $1 = o->self_scm ();
1145 parser->lexer_->remove_scope ();
1146 parser->lexer_->add_scope (o->scope_);
1147 $2 = SCM_UNSPECIFIED;
1151 if (unsmob<Context_def> ($2))
1152 assign_context_def (unsmob<Output_def> ($1), $2);
1153 // Seems unlikely, but let's be complete:
1154 else if (unsmob<Music> ($2))
1156 SCM proc = parser->lexer_->lookup_identifier
1157 ("output-def-music-handler");
1158 scm_call_2 (proc, $1, $2);
1159 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1160 parser->parser_error (@2, _("bad expression type"));
1163 | output_def_body SCM_TOKEN {
1164 if (scm_is_pair ($1))
1166 // Evaluate and ignore #xxx, as opposed to \xxx
1167 parser->lexer_->eval_scm_token ($2, @2);
1171 if (scm_is_pair ($1))
1173 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1174 parser->lexer_->push_note_state (nn);
1175 } music_or_context_def
1177 parser->lexer_->pop_state ();
1178 if (unsmob<Context_def> ($3))
1179 assign_context_def (unsmob<Output_def> ($1), $3);
1182 SCM proc = parser->lexer_->lookup_identifier
1183 ("output-def-music-handler");
1184 scm_call_2 (proc, $1, $3);
1188 | output_def_body error {
1194 TEMPO steno_duration '=' tempo_range {
1195 $$ = MAKE_SYNTAX (tempo, @$, SCM_EOL, $2, $4);
1197 | TEMPO scalar steno_duration '=' tempo_range {
1198 $$ = MAKE_SYNTAX (tempo, @$, $2, $3, $5);
1201 $$ = MAKE_SYNTAX (tempo, @$, $2);
1206 The representation of a list is reversed to have efficient append. */
1212 | music_list music_embedded {
1213 if (unsmob<Music> ($2))
1214 $$ = scm_cons ($2, $1);
1216 | music_list error {
1217 Music *m = MY_MAKE_MUSIC("Music", @$);
1219 m->set_property ("error-found", SCM_BOOL_T);
1220 $$ = scm_cons (m->self_scm (), $1);
1221 m->unprotect (); /* UGH */
1228 $$ = scm_reverse_x ($2, SCM_EOL);
1233 | lyric_element_music
1240 $$ = make_music_from_simple (parser, @1, $1);
1241 if (!unsmob<Music> ($$))
1243 parser->parser_error (@1, _ ("music expected"));
1244 $$ = MAKE_SYNTAX (void_music, @$);
1252 if (unsmob<Music> ($1)->is_mus_type ("post-event")) {
1253 parser->parser_error (@1, _ ("unexpected post-event"));
1254 $$ = SCM_UNSPECIFIED;
1257 | music_embedded_backup
1261 | music_embedded_backup BACKUP lyric_element_music
1265 | multiplied_duration post_events
1267 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1269 parser->default_duration_ = *unsmob<Duration> ($1);
1270 n->set_property ("duration", $1);
1272 if (scm_is_pair ($2))
1273 n->set_property ("articulations",
1274 scm_reverse_x ($2, SCM_EOL));
1275 $$ = n->unprotect ();
1279 music_embedded_backup:
1282 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1284 else if (Music *m = unsmob<Music> ($1)) {
1285 if (m->is_mus_type ("post-event")) {
1286 parser->parser_error
1287 (@1, _ ("unexpected post-event"));
1288 $$ = SCM_UNSPECIFIED;
1291 } else if (parser->lexer_->is_lyric_state ()
1292 && Text_interface::is_markup ($1))
1293 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1295 @$.warning (_ ("Ignoring non-music expression"));
1301 // music_assign does not need to contain lyrics: there are no
1302 // assignments in lyricmode.
1305 | composite_music %prec COMPOSITE
1309 REPEAT simple_string unsigned_number music
1311 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, SCM_EOL);
1313 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1315 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, $6);
1320 SEQUENTIAL braced_music_list {
1321 $$ = MAKE_SYNTAX (sequential_music, @$, $2);
1323 | braced_music_list {
1324 $$ = MAKE_SYNTAX (sequential_music, @$, $1);
1329 SIMULTANEOUS braced_music_list {
1330 $$ = MAKE_SYNTAX (simultaneous_music, @$, $2);
1332 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1333 $$ = MAKE_SYNTAX (simultaneous_music, @$, scm_reverse_x ($2, SCM_EOL));
1339 | music_property_def
1343 context_modification:
1346 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1347 parser->lexer_->push_note_state (nn);
1348 } '{' context_mod_list '}'
1350 parser->lexer_->pop_state ();
1353 | WITH CONTEXT_MOD_IDENTIFIER
1357 | CONTEXT_MOD_IDENTIFIER
1361 | WITH context_modification_arg
1363 if (unsmob<Music> ($2)) {
1364 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1365 $2 = scm_call_1 (proc, $2);
1367 if (unsmob<Context_mod> ($2))
1370 parser->parser_error (@2, _ ("not a context mod"));
1371 $$ = Context_mod ().smobbed_copy ();
1376 context_modification_arg:
1381 optional_context_mod:
1385 | context_modification
1393 $$ = Context_mod ().smobbed_copy ();
1395 | context_mod_list context_mod {
1396 if (!SCM_UNBNDP ($2))
1397 unsmob<Context_mod> ($1)->add_context_mod ($2);
1399 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1400 Context_mod *md = unsmob<Context_mod> ($2);
1402 unsmob<Context_mod> ($1)->add_context_mods (md->get_mods ());
1404 | context_mod_list context_mod_arg {
1405 if (scm_is_eq ($2, SCM_UNSPECIFIED))
1407 else if (unsmob<Music> ($2)) {
1408 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1409 $2 = scm_call_1 (proc, $2);
1411 if (unsmob<Context_mod> ($2))
1412 unsmob<Context_mod> ($$)->add_context_mods
1413 (unsmob<Context_mod> ($2)->get_mods ());
1415 parser->parser_error (@2, _ ("not a context mod"));
1421 CONTEXT symbol optional_id optional_context_mod {
1422 Context_mod *ctxmod = unsmob<Context_mod> ($4);
1425 mods = ctxmod->get_mods ();
1426 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, mods, SCM_BOOL_F);
1428 | NEWCONTEXT symbol optional_id optional_context_mod {
1429 Context_mod *ctxmod = unsmob<Context_mod> ($4);
1432 mods = ctxmod->get_mods ();
1433 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, mods, SCM_BOOL_T);
1438 ADDLYRICS lyric_mode_music {
1439 $$ = scm_list_1 ($2);
1441 | new_lyrics ADDLYRICS lyric_mode_music {
1442 $$ = scm_cons ($3, $1);
1446 /* basic_music is basically the same as composite_music but with
1447 * context-prefixed music and lyricized music explicitly removed. The
1448 * reason is that in a sequence
1450 * \new Staff \new Voice { ... } \addlyrics { ... } \addlyrics { ... }
1452 * we need to group both \addlyrics together (as they go with the same
1453 * voice) but then combine them with \new Voice { ... }, meaning that
1454 * combining \new Voice { ... } needs higher priority than
1455 * { ... } \addlyrics, and *not* have \new Staff \new Voice { ... }
1456 * combine before combining \new Voice { ... } \addlyrics: only one
1457 * layer of context-prefixed music should assemble before \addlyrics
1458 * is integrated. Total mess, and we sort this mess out with explicit
1459 * rules preferring a single context-prefix.
1466 | LYRICSTO simple_string lyric_mode_music {
1467 $$ = MAKE_SYNTAX (lyric_combine, @$, $2, SCM_EOL, $3);
1469 | LYRICSTO symbol '=' simple_string lyric_mode_music
1471 $$ = MAKE_SYNTAX (lyric_combine, @$, $3, $2, $4);
1481 contexted_basic_music:
1482 context_prefix contextable_music new_lyrics
1485 i.set_location (@1, @2);
1486 $$ = FINISH_MAKE_SYNTAX ($1, i, $2);
1487 $$ = MAKE_SYNTAX (add_lyrics, @$, $$, scm_reverse_x ($3, SCM_EOL));
1489 | context_prefix contextable_music
1491 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1493 | context_prefix contexted_basic_music
1495 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1500 basic_music %prec COMPOSITE
1501 | contexted_basic_music
1502 | basic_music new_lyrics
1504 $$ = MAKE_SYNTAX (add_lyrics, @$, $1, scm_reverse_x ($2, SCM_EOL));
1511 | grouped_music_list
1515 simultaneous_music { $$ = $1; }
1516 | sequential_music { $$ = $1; }
1519 /* Function argument lists are arguably the most complex part in the
1520 * parser. They are pretty tricky to understand because of the way
1521 * they are processed, and because of optional arguments that can be
1522 * omitted. When there are several optional arguments in a row,
1523 * omitting one automatically omits all following arguments. Optional
1524 * arguments can only be omitted when either
1526 * a) the omission is explicitly started with \default
1527 * b) the omission is implicitly started by an argument not matching
1528 * its predicate, and there is a mandatory argument later that can
1529 * "catch" the argument that does not fit.
1531 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1532 * (corresponding to mandatory arguments and having a predicate
1533 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1534 * the semantic value of the EXPECT_OPTIONAL token is the default to
1535 * use when the optional argument is omitted, and EXPECT_SCM again has
1536 * the argument predicate as semantic value) in reverse order to the
1537 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1538 * processed inside-out while actual tokens are consumed.
1540 * This means that the argument list tokens determine the actions
1541 * taken as they arrive. The structure of the argument list is known
1542 * to the parser and stored in its parse stack when the first argument
1543 * is being parsed. What the parser does not know is which predicates
1544 * will match and whether or not \default will be appearing in the
1545 * argument list, and where.
1547 * Sequences of 0 or more optional arguments are scanned using either
1548 * function_arglist_backup or function_arglist_nonbackup. The first
1549 * is used when optional arguments are followed by at least one
1550 * mandatory argument: in that case optional arguments may be skipped
1551 * by either a false predicate (in which case the expression will be
1552 * pushed back as one or more tokens, preceded by a BACKUP token) or
1553 * by using \default.
1555 * If optional arguments are at the end of the argument list, they are
1556 * instead scanned using function_arglist_nonbackup: here the only
1557 * manner to enter into skipping of optional arguments is the use of
1560 * The argument list of a normal function call is parsed using
1561 * function_arglist. The part of an argument list before a mandatory
1562 * argument is parsed using function_arglist_optional.
1564 * The difference is that leading optional arguments are scanned using
1565 * function_arglist_nonbackup and function_arglist_backup,
1568 * Most other details are obvious in the rules themselves.
1574 | SYMBOL_LIST '.' symbol_list_rev
1576 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1582 | symbol_list_rev '.' symbol_list_part
1584 $$ = scm_append_x (scm_list_2 ($3, $1));
1588 // symbol_list_part delivers elements in reverse copy.
1593 $$ = try_string_variants (Lily::symbol_list_p, $1);
1594 if (SCM_UNBNDP ($$)) {
1595 parser->parser_error (@1, _("not a symbol"));
1598 $$ = scm_reverse ($$);
1603 symbol_list_element:
1609 function_arglist_nonbackup:
1610 function_arglist_common
1611 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1613 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1615 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1617 SCM n = scm_difference ($5, SCM_UNDEFINED);
1618 if (scm_is_true (scm_call_1 ($2, n)))
1619 $$ = scm_cons (n, $3);
1621 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1622 t->set_property ("digit", $5);
1623 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1627 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1629 $$ = check_scheme_arg (parser, @4,
1630 scm_difference ($5, SCM_UNDEFINED),
1633 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1635 $$ = check_scheme_arg (parser, @4,
1636 scm_difference ($5, SCM_UNDEFINED),
1639 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1641 if (scm_is_true (scm_call_1 ($2, $4)))
1642 $$ = scm_cons ($4, $3);
1644 $$ = check_scheme_arg (parser, @4,
1645 make_music_from_simple
1649 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1651 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1653 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1655 if (scm_is_true (scm_call_1 ($2, $3)))
1656 $$ = scm_cons ($3, $1);
1658 $$ = check_scheme_arg (parser, @3,
1659 make_music_from_simple
1663 | function_arglist_nonbackup_reparse REPARSE duration_length
1665 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1667 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1669 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1671 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1673 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1675 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1677 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1679 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1681 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1685 function_arglist_nonbackup_reparse:
1686 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1689 SCM res = try_string_variants ($2, $4);
1690 if (!SCM_UNBNDP (res))
1691 if (scm_is_pair (res))
1692 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1694 MYREPARSE (@4, $2, SCM_ARG, res);
1695 else if (scm_is_true
1697 ($2, make_music_from_simple
1699 MYREPARSE (@4, $2, STRING, $4);
1701 MYREPARSE (@4, $2, SCM_ARG, $4);
1703 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1708 ($2, make_music_from_simple
1710 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1712 MYREPARSE (@4, $2, SCM_ARG, $4);
1714 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1719 ($2, make_music_from_simple
1721 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1723 MYREPARSE (@4, $2, SCM_ARG, $4);
1725 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1728 SCM res = try_string_variants ($2, $4);
1729 if (!SCM_UNBNDP (res))
1730 if (scm_is_pair (res))
1731 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1733 MYREPARSE (@4, $2, SCM_ARG, res);
1734 else if (scm_is_true
1736 ($2, make_music_from_simple
1738 MYREPARSE (@4, $2, STRING, $4);
1740 MYREPARSE (@4, $2, SCM_ARG, $4);
1742 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1745 if (scm_is_true (scm_call_1 ($2, $4)))
1746 MYREPARSE (@4, $2, SCM_ARG, $4);
1747 else if (scm_is_true
1749 ($2, make_music_from_simple
1751 MYREPARSE (@4, $2, STRING, $4);
1753 MYREPARSE (@4, $2, SCM_ARG, $4);
1755 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1758 if (scm_is_true (scm_call_1 ($2, $4)))
1759 MYREPARSE (@4, $2, REAL, $4);
1761 SCM d = make_duration ($4);
1762 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1763 MYREPARSE (@4, $2, REAL, $4); // trigger error
1765 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1768 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1770 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1775 // function_arglist_backup can't occur at the end of an argument
1777 function_arglist_backup:
1778 function_arglist_common
1779 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1781 if (scm_is_true (scm_call_1 ($2, $4)))
1782 $$ = scm_cons ($4, $3);
1784 $$ = make_music_from_simple (parser, @4, $4);
1785 if (scm_is_true (scm_call_1 ($2, $$)))
1786 $$ = scm_cons ($$, $3);
1789 $$ = scm_cons (loc_on_music (@3, $1), $3);
1790 MYBACKUP (SCM_ARG, $4, @4);
1794 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1796 if (scm_is_true (scm_call_1 ($2, $4)))
1798 $$ = scm_cons ($4, $3);
1800 $$ = scm_cons (loc_on_music (@3, $1), $3);
1801 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1804 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1808 ($2, make_music_from_simple
1812 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1813 } else if (scm_is_true (scm_call_1 ($2, $4)))
1814 $$ = scm_cons ($4, $3);
1816 $$ = scm_cons (loc_on_music (@3, $1), $3);
1817 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1820 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1824 ($2, make_music_from_simple
1828 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1829 } else if (scm_is_true (scm_call_1 ($2, $4)))
1830 $$ = scm_cons ($4, $3);
1832 $$ = scm_cons (loc_on_music (@3, $1), $3);
1833 MYBACKUP (TONICNAME_PITCH, $4, @4);
1836 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1838 if (scm_is_true (scm_call_1 ($2, $4)))
1839 $$ = scm_cons ($4, $3);
1841 $$ = scm_cons (loc_on_music (@3, $1), $3);
1842 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1845 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1847 if (scm_is_true (scm_call_1 ($2, $4)))
1849 MYREPARSE (@4, $2, REAL, $4);
1852 SCM d = make_duration ($4);
1853 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1855 $$ = scm_cons (loc_on_music (@3, $1), $3);
1856 MYBACKUP (UNSIGNED, $4, @4);
1858 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1863 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1865 if (scm_is_true (scm_call_1 ($2, $4)))
1868 MYREPARSE (@4, $2, REAL, $4);
1870 $$ = scm_cons (loc_on_music (@3, $1), $3);
1871 MYBACKUP (REAL, $4, @4);
1874 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1876 if (scm_is_true (scm_call_1 ($2, $4)))
1878 $$ = scm_cons ($4, $3);
1880 $$ = scm_cons (loc_on_music (@3, $1), $3);
1881 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1884 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1886 SCM n = scm_difference ($5, SCM_UNDEFINED);
1887 if (scm_is_true (scm_call_1 ($2, n))) {
1889 MYREPARSE (@5, $2, REAL, n);
1891 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1892 t->set_property ("digit", $5);
1893 $$ = t->unprotect ();
1894 if (scm_is_true (scm_call_1 ($2, $$)))
1895 $$ = scm_cons ($$, $3);
1897 $$ = scm_cons (loc_on_music (@3, $1), $3);
1898 MYBACKUP (UNSIGNED, $5, @5);
1899 parser->lexer_->push_extra_token (@4, '-');
1903 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1905 SCM n = scm_difference ($5, SCM_UNDEFINED);
1906 if (scm_is_true (scm_call_1 ($2, n))) {
1907 MYREPARSE (@5, $2, REAL, n);
1910 $$ = scm_cons (loc_on_music (@3, $1), $3);
1911 MYBACKUP (REAL, n, @5);
1914 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1916 SCM n = scm_difference ($5, SCM_UNDEFINED);
1917 if (scm_is_true (scm_call_1 ($2, n))) {
1918 $$ = scm_cons (n, $3);
1920 $$ = scm_cons (loc_on_music (@3, $1), $3);
1921 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1924 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1926 if (scm_is_true (scm_call_1 ($2, $4)))
1928 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1931 $$ = scm_cons (loc_on_music (@3, $1), $3);
1932 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1935 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1937 SCM res = try_string_variants ($2, $4);
1938 if (!SCM_UNBNDP (res))
1939 if (scm_is_pair (res)) {
1941 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1944 $$ = scm_cons (res, $3);
1946 $$ = scm_cons (loc_on_music (@3, $1), $3);
1947 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1950 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1952 SCM res = try_string_variants ($2, $4);
1953 if (!SCM_UNBNDP (res))
1954 if (scm_is_pair (res)) {
1956 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1959 $$ = scm_cons (res, $3);
1961 $$ = scm_cons (loc_on_music (@3, $1), $3);
1962 MYBACKUP (STRING, $4, @4);
1965 | function_arglist_backup REPARSE pitch_or_music
1967 if (scm_is_true (scm_call_1 ($2, $3)))
1968 $$ = scm_cons ($3, $1);
1970 $$ = check_scheme_arg (parser, @3,
1971 make_music_from_simple
1975 | function_arglist_backup REPARSE bare_number_common
1977 $$ = check_scheme_arg (parser, @3,
1980 | function_arglist_backup REPARSE duration_length
1982 $$ = check_scheme_arg (parser, @3,
1985 | function_arglist_backup REPARSE symbol_list_arg
1987 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1992 function_arglist_nonbackup
1993 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1995 $$ = scm_cons (loc_on_music (@4, $1), $3);
1999 function_arglist_skip_nonbackup:
2000 function_arglist_nonbackup
2001 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
2003 $$ = scm_cons (loc_on_music (@3, $1), $3);
2007 function_arglist_common:
2008 EXPECT_NO_MORE_ARGS {
2011 | EXPECT_SCM function_arglist_optional embedded_scm_arg
2013 if (scm_is_true (scm_call_1 ($1, $3)))
2014 $$ = scm_cons ($3, $2);
2016 $$ = check_scheme_arg (parser, @3,
2017 make_music_from_simple
2021 | EXPECT_SCM function_arglist_optional bare_number_common
2023 $$ = check_scheme_arg (parser, @3,
2026 | EXPECT_SCM function_arglist_optional post_event_nofinger
2028 $$ = check_scheme_arg (parser, @3,
2031 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2033 SCM n = scm_difference ($4, SCM_UNDEFINED);
2034 $$ = check_scheme_arg (parser, @4, n, $2, $1);
2036 | function_arglist_common_reparse REPARSE SCM_ARG
2038 $$ = check_scheme_arg (parser, @3,
2041 | function_arglist_common_reparse REPARSE lyric_element_music
2043 $$ = check_scheme_arg (parser, @3,
2046 | function_arglist_common_reparse REPARSE pitch_or_music
2048 if (scm_is_true (scm_call_1 ($2, $3)))
2049 $$ = scm_cons ($3, $1);
2051 $$ = check_scheme_arg (parser, @3,
2052 make_music_from_simple
2056 | function_arglist_common_reparse REPARSE bare_number_common
2058 $$ = check_scheme_arg (parser, @3,
2061 | function_arglist_common_reparse REPARSE duration_length
2063 $$ = check_scheme_arg (parser, @3,
2066 | function_arglist_common_reparse REPARSE symbol_list_arg
2068 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2072 function_arglist_common_reparse:
2073 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2076 SCM res = try_string_variants ($1, $3);
2077 if (!SCM_UNBNDP (res))
2078 if (scm_is_pair (res))
2079 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2081 MYREPARSE (@3, $1, SCM_ARG, res);
2082 else if (scm_is_true
2084 ($1, make_music_from_simple (parser, @3, $3))))
2085 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2087 // This is going to flag a syntax error, we
2088 // know the predicate to be false.
2089 MYREPARSE (@3, $1, SCM_ARG, $3);
2091 | EXPECT_SCM function_arglist_optional pitch
2096 ($1, make_music_from_simple
2098 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2100 MYREPARSE (@3, $1, SCM_ARG, $3);
2102 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2107 ($1, make_music_from_simple
2109 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2111 MYREPARSE (@3, $1, SCM_ARG, $3);
2113 | EXPECT_SCM function_arglist_optional STRING
2116 SCM res = try_string_variants ($1, $3);
2117 if (!SCM_UNBNDP (res))
2118 if (scm_is_pair (res))
2119 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2121 MYREPARSE (@3, $1, SCM_ARG, res);
2122 else if (scm_is_true
2124 ($1, make_music_from_simple (parser, @3, $3))))
2125 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2127 // This is going to flag a syntax error, we
2128 // know the predicate to be false.
2129 MYREPARSE (@3, $1, SCM_ARG, $3);
2131 | EXPECT_SCM function_arglist_optional full_markup
2134 if (scm_is_true (scm_call_1 ($1, $3)))
2135 MYREPARSE (@3, $1, SCM_ARG, $3);
2136 else if (scm_is_true
2138 ($1, make_music_from_simple (parser, @3, $3))))
2139 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2141 // This is going to flag a syntax error, we
2142 // know the predicate to be false.
2143 MYREPARSE (@3, $1, SCM_ARG, $3);
2145 | EXPECT_SCM function_arglist_optional UNSIGNED
2148 if (scm_is_true (scm_call_1 ($1, $3)))
2149 MYREPARSE (@3, $1, REAL, $3);
2151 SCM d = make_duration ($3);
2152 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
2153 MYREPARSE (@3, $1, REAL, $3);
2155 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2158 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2161 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2163 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2166 SCM n = scm_difference ($4, SCM_UNDEFINED);
2167 if (scm_is_true (scm_call_1 ($1, n)))
2168 MYREPARSE (@4, $1, REAL, n);
2170 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2171 t->set_property ("digit", $4);
2172 SCM m = t->unprotect ();
2173 if (scm_is_true (scm_call_1 ($1, m)))
2174 MYREPARSE (@4, $1, SCM_ARG, m);
2176 MYREPARSE (@4, $1, SCM_ARG, $4);
2179 | EXPECT_SCM function_arglist_optional '-' REAL
2182 SCM n = scm_difference ($4, SCM_UNDEFINED);
2183 MYREPARSE (@4, $1, REAL, n);
2187 function_arglist_optional:
2188 function_arglist_backup
2189 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2191 $$ = scm_cons (loc_on_music (@4, $1), $3);
2193 | function_arglist_skip_backup BACKUP
2196 function_arglist_skip_backup:
2197 function_arglist_backup
2198 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2200 $$ = scm_cons (loc_on_music (@3, $1), $3);
2204 music_function_call:
2205 MUSIC_FUNCTION function_arglist {
2206 $$ = MAKE_SYNTAX (music_function, @$,
2213 /**/ { $$ = SCM_EOL; }
2214 | '=' simple_string {
2219 // We must not have lookahead tokens parsed in lyric mode. In order
2220 // to save confusion, we take almost the same set as permitted with
2221 // \lyricmode and/or \lyrics. However, music identifiers are also
2222 // allowed, and they obviously do not require switching into lyrics
2223 // mode for parsing.
2227 parser->lexer_->push_lyric_state ();
2228 } grouped_music_list
2230 parser->lexer_->pop_state ();
2237 mode_changing_head grouped_music_list {
2238 if (scm_is_eq ($1, ly_symbol2scm ("chords")))
2240 $$ = MAKE_SYNTAX (unrelativable_music, @$, $2);
2246 parser->lexer_->pop_state ();
2248 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2249 Context_mod *ctxmod = unsmob<Context_mod> ($2);
2252 mods = ctxmod->get_mods ();
2253 $$ = MAKE_SYNTAX (context_specification, @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2254 if (scm_is_eq ($1, ly_symbol2scm ("ChordNames")))
2256 $$ = MAKE_SYNTAX (unrelativable_music, @$, $$);
2258 parser->lexer_->pop_state ();
2264 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2265 parser->lexer_->push_note_state (nn);
2267 $$ = ly_symbol2scm ("notes");
2271 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2272 parser->lexer_->push_note_state (nn);
2274 $$ = ly_symbol2scm ("drums");
2277 parser->lexer_->push_figuredbass_state ();
2279 $$ = ly_symbol2scm ("figures");
2282 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2283 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2284 nn = parser->lexer_->lookup_identifier ("pitchnames");
2285 parser->lexer_->push_chord_state (nn);
2286 $$ = ly_symbol2scm ("chords");
2290 { parser->lexer_->push_lyric_state ();
2291 $$ = ly_symbol2scm ("lyrics");
2295 mode_changing_head_with_context:
2297 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2298 parser->lexer_->push_note_state (nn);
2300 $$ = ly_symbol2scm ("DrumStaff");
2303 parser->lexer_->push_figuredbass_state ();
2305 $$ = ly_symbol2scm ("FiguredBass");
2308 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2309 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2310 nn = parser->lexer_->lookup_identifier ("pitchnames");
2311 parser->lexer_->push_chord_state (nn);
2312 $$ = ly_symbol2scm ("ChordNames");
2315 { parser->lexer_->push_lyric_state ();
2316 $$ = ly_symbol2scm ("Lyrics");
2321 CHANGE symbol '=' simple_string {
2322 $$ = MAKE_SYNTAX (context_change, @$, $2, $4);
2329 $$ = scm_reverse_x ($1, SCM_EOL);
2331 | symbol_list_rev property_path {
2332 $$ = scm_reverse_x ($1, $2);
2338 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2341 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2343 | OVERRIDE property_path '=' scalar {
2344 if (scm_ilength ($2) < 2) {
2345 parser->parser_error (@2, _("bad grob property path"));
2348 $$ = scm_cons (ly_symbol2scm ("push"),
2349 scm_cons2 (scm_car ($2),
2354 | REVERT revert_arg {
2355 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2359 // This is all quite awkward for the sake of substantial backward
2360 // compatibility while at the same time allowing a more "natural" form
2361 // of specification not separating grob specification from grob
2362 // property path. The purpose of this definition of revert_arg is to
2363 // allow the symbol list which specifies grob and property to revert
2364 // to be optionally be split into two parts after the grob (which in
2365 // this case is just the first element of the list). symbol_list_part
2366 // is only one path component, but it can be parsed without lookahead,
2367 // so we can follow it with a synthetic BACKUP token when needed. If
2368 // the first symbol_list_part already contains multiple elements (only
2369 // possible if a Scheme expression provides them), we just parse for
2370 // additional elements introduced by '.', which is what the
2371 // SYMBOL_LIST backup in connection with the immediately following
2372 // rule using symbol_list_arg does.
2374 // As long as we don't have our coffers filled with both grob and at
2375 // least one grob property specification, the rest of the required
2376 // symbol list chain may be provided either with or without a leading
2377 // dot. This is for both allowing the traditional
2378 // \revert Accidental #'color
2379 // as well as well as the "naive" form
2380 // \revert Accidental.color
2383 revert_arg_backup BACKUP symbol_list_arg
2392 if (scm_is_null ($1)
2393 || scm_is_null (scm_cdr ($1)))
2394 MYBACKUP (SCM_ARG, $1, @1);
2396 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2400 // revert_arg_part delivers results in reverse
2403 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2405 $$ = scm_append_x (scm_list_2 ($5, $3));
2407 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2409 $$ = scm_append_x (scm_list_2 ($4, $3));
2414 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2415 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2417 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2418 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2419 | DENIES { $$ = ly_symbol2scm ("denies"); }
2421 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2422 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2423 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2424 | NAME { $$ = ly_symbol2scm ("context-name"); }
2428 property_operation { $$ = $1; }
2429 | context_def_mod STRING {
2430 $$ = scm_list_2 ($1, $2);
2432 | context_def_mod embedded_scm
2434 if (!scm_is_string ($2)
2435 && ly_symbol2scm ("consists") != $1
2436 && ly_symbol2scm ("remove") != $1)
2439 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2443 $$ = scm_list_2 ($1, $2);
2448 // If defined, at least two members.
2452 SCM l = scm_reverse_x ($1, SCM_EOL);
2455 (scm_object_property (scm_car (l),
2456 ly_symbol2scm ("is-grob?"))))
2457 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2458 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2459 parser->parser_error (@1, _ ("bad grob property path"));
2466 // If defined, at least three members
2470 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2472 parser->parser_error (@1, _ ("bad grob property path"));
2476 | grob_prop_spec property_path
2478 if (!SCM_UNBNDP ($1)) {
2479 $$ = scm_append_x (scm_list_2 ($1, $2));
2480 if (scm_is_null (scm_cddr ($$))) {
2481 parser->parser_error (@$, _ ("bad grob property path"));
2489 // Exactly two elements or undefined
2493 SCM l = scm_reverse_x ($1, SCM_EOL);
2494 switch (scm_ilength (l)) {
2496 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2500 parser->parser_error (@1, _ ("bad context property path"));
2508 // This is all quite awkward for the sake of substantial backward
2509 // compatibility while at the same time allowing a more "natural" form
2510 // of specification not separating grob specification from grob
2511 // property path. The purpose of this definition of
2512 // simple_revert_context is to allow the symbol list which specifies
2513 // grob and property to revert to be optionally be split into two
2514 // parts after the grob (which may be preceded by a context
2515 // specification, a case which we distinguish by checking whether the
2516 // first symbol is a valid grob symbol instead).
2518 // See revert_arg above for the main work horse of this arrangement.
2519 // simple_revert_context just caters for the context and delegates the
2520 // rest of the job to revert_arg.
2522 simple_revert_context:
2525 $1 = scm_reverse_x ($1, SCM_EOL);
2526 if (scm_is_null ($1)
2528 (scm_object_property (scm_car ($1),
2529 ly_symbol2scm ("is-grob?")))) {
2530 $$ = ly_symbol2scm ("Bottom");
2531 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2534 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2541 OVERRIDE grob_prop_path '=' scalar {
2542 if (SCM_UNBNDP ($2))
2543 $$ = MAKE_SYNTAX (void_music, @$);
2545 $$ = MAKE_SYNTAX (property_operation, @$,
2547 ly_symbol2scm ("OverrideProperty"),
2553 | REVERT simple_revert_context revert_arg {
2554 $$ = MAKE_SYNTAX (property_operation, @$,
2556 ly_symbol2scm ("RevertProperty"),
2560 | SET context_prop_spec '=' scalar {
2561 if (SCM_UNBNDP ($2))
2562 $$ = MAKE_SYNTAX (void_music, @$);
2564 $$ = MAKE_SYNTAX (property_operation, @$,
2566 ly_symbol2scm ("PropertySet"),
2570 | UNSET context_prop_spec {
2571 if (SCM_UNBNDP ($2))
2572 $$ = MAKE_SYNTAX (void_music, @$);
2574 $$ = MAKE_SYNTAX (property_operation, @$,
2576 ly_symbol2scm ("PropertyUnset"),
2588 simple_string: STRING {
2593 if (scm_is_string ($1)) {
2596 parser->parser_error (@1, (_ ("simple string expected")));
2597 $$ = scm_string (SCM_EOL);
2604 $$ = scm_string_to_symbol ($1);
2608 // This is a bit of overkill but makes the same
2609 // routine responsible for all symbol interpretations.
2610 $$ = try_string_variants (Guile_user::symbol_p, $1);
2611 if (SCM_UNBNDP ($$))
2613 parser->parser_error (@1, (_ ("symbol expected")));
2614 // Generate a unique symbol in case it is used
2615 // for an assignment or similar
2616 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2626 // The following is a rather defensive variant of admitting
2627 // negative numbers: the grammar would permit number_factor or
2628 // even number_expression. However, function arguments allow
2629 // only this simple kind of negative number, so to have things
2630 // like \tweak and \override behave reasonably similar, it
2631 // makes sense to rule out things like -- which are rather an
2632 // accent in function argument contexts.
2635 $$ = scm_difference ($2, SCM_UNDEFINED);
2641 simple_element post_events {
2642 // Let the rhythmic music iterator sort this mess out.
2643 if (scm_is_pair ($2)) {
2644 unsmob<Music> ($$)->set_property ("articulations",
2645 scm_reverse_x ($2, SCM_EOL));
2648 | CHORD_REPETITION optional_notemode_duration post_events {
2650 i.set_location (@1, @3);
2651 $$ = MAKE_SYNTAX (repetition_chord, i,
2652 $2, scm_reverse_x ($3, SCM_EOL));
2654 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2656 i.set_location (@1, @3);
2657 $$ = MAKE_SYNTAX (multi_measure_rest, i, $2,
2658 scm_reverse_x ($3, SCM_EOL));
2661 | note_chord_element
2666 chord_body optional_notemode_duration post_events
2668 Music *m = unsmob<Music> ($1);
2669 SCM dur = unsmob<Duration> ($2)->smobbed_copy ();
2670 SCM es = m->get_property ("elements");
2671 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2673 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2674 unsmob<Music> (scm_car (s))->set_property ("duration", dur);
2675 es = ly_append2 (es, postevs);
2677 m-> set_property ("elements", es);
2679 $$ = m->self_scm ();
2684 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2686 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2688 | FIGURE_OPEN figure_list FIGURE_CLOSE
2690 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2694 chord_body_elements:
2695 /* empty */ { $$ = SCM_EOL; }
2696 | chord_body_elements chord_body_element {
2697 if (!SCM_UNBNDP ($2))
2698 $$ = scm_cons ($2, $1);
2703 pitch_or_tonic_pitch exclamations questions octave_check post_events
2705 bool q = to_boolean ($3);
2706 bool ex = to_boolean ($2);
2710 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2711 n->set_property ("pitch", $1);
2713 n->set_property ("cautionary", SCM_BOOL_T);
2715 n->set_property ("force-accidental", SCM_BOOL_T);
2717 if (scm_is_pair (post)) {
2718 SCM arts = scm_reverse_x (post, SCM_EOL);
2719 n->set_property ("articulations", arts);
2721 if (scm_is_number (check))
2723 int q = scm_to_int (check);
2724 n->set_property ("absolute-octave", scm_from_int (q-1));
2727 $$ = n->unprotect ();
2729 | DRUM_PITCH post_events {
2730 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2731 n->set_property ("drum-type", $1);
2733 if (scm_is_pair ($2)) {
2734 SCM arts = scm_reverse_x ($2, SCM_EOL);
2735 n->set_property ("articulations", arts);
2737 $$ = n->unprotect ();
2739 | music_function_chord_body
2741 Music *m = unsmob<Music> ($1);
2743 while (m && m->is_mus_type ("music-wrapper-music")) {
2744 $$ = m->get_property ("element");
2745 m = unsmob<Music> ($$);
2748 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2749 parser->parser_error (@$, _ ("not a rhythmic event"));
2755 music_function_chord_body:
2761 event_function_event:
2762 EVENT_FUNCTION function_arglist {
2763 $$ = MAKE_SYNTAX (music_function, @$,
2772 | post_events post_event {
2774 if (Music *m = unsmob<Music> ($2))
2776 if (m->is_mus_type ("post-event-wrapper"))
2778 for (SCM p = m->get_property ("elements");
2782 $$ = scm_cons (scm_car (p), $$);
2786 $$ = scm_cons ($2, $$);
2792 post_event_nofinger:
2793 direction_less_event {
2796 | script_dir music_function_call {
2798 if (!unsmob<Music> ($2)->is_mus_type ("post-event")) {
2799 parser->parser_error (@2, _ ("post-event expected"));
2800 $$ = SCM_UNSPECIFIED;
2801 } else if (!SCM_UNBNDP ($1))
2803 unsmob<Music> ($$)->set_property ("direction", $1);
2807 if (!parser->lexer_->is_lyric_state ())
2808 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2809 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2812 if (!parser->lexer_->is_lyric_state ())
2813 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2814 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2816 | script_dir direction_reqd_event {
2817 if (!SCM_UNBNDP ($1))
2819 Music *m = unsmob<Music> ($2);
2820 m->set_property ("direction", $1);
2824 | script_dir direction_less_event {
2825 if (!SCM_UNBNDP ($1))
2827 Music *m = unsmob<Music> ($2);
2828 m->set_property ("direction", $1);
2835 unsmob<Music> ($$)->set_property ("direction", scm_from_int (UP));
2840 unsmob<Music> ($$)->set_property ("direction", scm_from_int (DOWN));
2851 string_number_event:
2853 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2854 s->set_property ("string-number", $1);
2855 $$ = s->unprotect ();
2859 direction_less_event:
2861 | EVENT_IDENTIFIER {
2865 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2866 a->set_property ("tremolo-type", $1);
2867 $$ = a->unprotect ();
2869 | event_function_event
2872 direction_reqd_event:
2876 | script_abbreviation {
2877 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2878 if (scm_is_string (s)) {
2879 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2880 a->set_property ("articulation-type", s);
2881 $$ = a->unprotect ();
2883 Music *original = unsmob<Music> (s);
2884 if (original && original->is_mus_type ("post-event")) {
2885 Music *a = original->clone ();
2886 a->set_spot (parser->lexer_->override_input (@$));
2887 $$ = a->unprotect ();
2889 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2890 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2897 /**/ { $$ = SCM_EOL; }
2898 | '=' quotes { $$ = $2; }
2912 $$ = scm_from_int (1);
2915 $$ = scm_oneplus ($1);
2921 $$ = scm_from_int (-1);
2924 $$ = scm_oneminus ($1);
2929 NOTENAME_PITCH quotes {
2930 if (!scm_is_eq (SCM_INUM0, $2))
2932 Pitch p = *unsmob<Pitch> ($1);
2933 p = p.transposed (Pitch (scm_to_int ($2), 0));
2934 $$ = p.smobbed_copy ();
2944 TONICNAME_PITCH quotes {
2945 if (!scm_is_eq (SCM_INUM0, $2))
2947 Pitch p = *unsmob<Pitch> ($1);
2948 p = p.transposed (Pitch (scm_to_int ($2), 0));
2949 $$ = p.smobbed_copy ();
2956 | PITCH_IDENTIFIER quotes {
2957 if (!scm_is_eq (SCM_INUM0, $2))
2959 Pitch p = *unsmob<Pitch> ($1);
2960 p = p.transposed (Pitch (scm_to_int ($2), 0));
2961 $$ = p.smobbed_copy ();
2966 pitch_or_tonic_pitch:
2973 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2974 t->set_property ("text", $1);
2975 $$ = t->unprotect ();
2978 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2979 t->set_property ("text",
2980 make_simple_markup ($1));
2981 $$ = t->unprotect ();
2985 Music *m = unsmob<Music> ($1);
2986 if (m && m->is_mus_type ("post-event"))
2988 else if (Text_interface::is_markup ($1)) {
2989 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2990 t->set_property ("text", $1);
2991 $$ = t->unprotect ();
2993 parser->parser_error (@1, _ ("not an articulation"));
2999 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3000 t->set_property ("digit", $1);
3001 $$ = t->unprotect ();
3005 script_abbreviation:
3007 $$ = scm_from_ascii_string ("Hat");
3010 $$ = scm_from_ascii_string ("Plus");
3013 $$ = scm_from_ascii_string ("Dash");
3016 $$ = scm_from_ascii_string ("Bang");
3019 $$ = scm_from_ascii_string ("Larger");
3022 $$ = scm_from_ascii_string ("Dot");
3025 $$ = scm_from_ascii_string ("Underscore");
3030 '_' { $$ = scm_from_int (DOWN); }
3031 | '^' { $$ = scm_from_int (UP); }
3032 | '-' { $$ = SCM_UNDEFINED; }
3036 multiplied_duration {
3041 maybe_notemode_duration:
3045 | multiplied_duration {
3047 parser->default_duration_ = *unsmob<Duration> ($$);
3052 optional_notemode_duration:
3053 maybe_notemode_duration
3055 if (SCM_UNBNDP ($$))
3056 $$ = parser->default_duration_.smobbed_copy ();
3062 $$ = make_duration ($1, scm_to_int ($2));
3063 if (SCM_UNBNDP ($$))
3065 parser->parser_error (@1, _ ("not a duration"));
3066 $$ = Duration ().smobbed_copy ();
3069 | DURATION_IDENTIFIER dots {
3070 Duration *d = unsmob<Duration> ($1);
3071 Duration k (d->duration_log (),
3072 d->dot_count () + scm_to_int ($2));
3073 k = k.compressed (d->factor ());
3074 scm_remember_upto_here_1 ($1);
3075 $$ = k.smobbed_copy ();
3079 multiplied_duration:
3083 | multiplied_duration '*' UNSIGNED {
3084 $$ = unsmob<Duration> ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
3086 | multiplied_duration '*' FRACTION {
3087 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
3089 $$ = unsmob<Duration> ($$)->compressed (m).smobbed_copy ();
3098 $$ = scm_oneplus ($1);
3104 $$ = scm_from_int (parser->default_tremolo_type_);
3107 if (SCM_UNBNDP (make_duration ($2))) {
3108 parser->parser_error (@2, _ ("not a duration"));
3109 $$ = scm_from_int (parser->default_tremolo_type_);
3112 parser->default_tremolo_type_ = scm_to_int ($2);
3118 UNSIGNED { $$ = $1; }
3119 | STRING { $$ = $1; }
3120 | full_markup { $$ = $1; }
3123 // as an integer, it needs to be non-negative, and otherwise
3124 // it needs to be suitable as a markup.
3125 if (scm_is_integer ($1)
3126 ? scm_is_true (scm_negative_p ($1))
3127 : !Text_interface::is_markup ($1))
3129 parser->parser_error (@1, _ ("bass number expected"));
3135 figured_bass_alteration:
3136 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3137 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3138 | '!' { $$ = scm_from_int (0); }
3143 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3144 $$ = bfr->unprotect ();
3147 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3148 $$ = bfr->self_scm ();
3150 if (scm_is_number ($1))
3151 bfr->set_property ("figure", $1);
3152 else if (Text_interface::is_markup ($1))
3153 bfr->set_property ("text", $1);
3159 unsmob<Music> ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3161 | bass_figure figured_bass_alteration {
3162 Music *m = unsmob<Music> ($1);
3163 if (scm_to_double ($2)) {
3164 SCM salter = m->get_property ("alteration");
3165 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3166 m->set_property ("alteration",
3167 scm_sum (alter, $2));
3169 m->set_property ("alteration", scm_from_int (0));
3172 | bass_figure figured_bass_modification {
3173 Music *m = unsmob<Music> ($1);
3174 m->set_property ($2, SCM_BOOL_T);
3179 figured_bass_modification:
3181 $$ = ly_symbol2scm ("augmented");
3184 $$ = ly_symbol2scm ("no-continuation");
3187 $$ = ly_symbol2scm ("diminished");
3190 $$ = ly_symbol2scm ("augmented-slash");
3200 unsmob<Music> ($$)->set_property ("bracket-start", SCM_BOOL_T);
3208 | figure_list br_bass_figure {
3209 $$ = scm_cons ($2, $1);
3214 /**/ { $$ = SCM_BOOL_F; }
3215 | REST { $$ = SCM_BOOL_T; }
3219 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3220 if (!parser->lexer_->is_note_state ())
3221 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3222 if (!SCM_UNBNDP ($2)
3224 || scm_is_number ($4)
3227 || scm_is_pair ($7))
3230 if (scm_is_true ($6))
3231 n = MY_MAKE_MUSIC ("RestEvent", @$);
3233 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3235 n->set_property ("pitch", $1);
3236 if (SCM_UNBNDP ($5))
3237 n->set_property ("duration",
3238 parser->default_duration_.smobbed_copy ());
3240 n->set_property ("duration", $5);
3242 if (scm_is_number ($4))
3244 int q = scm_to_int ($4);
3245 n->set_property ("absolute-octave", scm_from_int (q-1));
3248 if (to_boolean ($3))
3249 n->set_property ("cautionary", SCM_BOOL_T);
3250 if (to_boolean ($2) || to_boolean ($3))
3251 n->set_property ("force-accidental", SCM_BOOL_T);
3252 if (scm_is_pair ($7))
3253 n->set_property ("articulations",
3254 scm_reverse_x ($7, SCM_EOL));
3255 $$ = n->unprotect ();
3258 | new_chord post_events {
3259 if (!parser->lexer_->is_chord_state ())
3260 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3261 if (scm_is_pair ($2)) {
3262 if (unsmob<Pitch> ($1))
3263 $1 = make_chord_elements (@1,
3265 parser->default_duration_.smobbed_copy (),
3268 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3270 $$ = MAKE_SYNTAX (event_chord, @1, elts);
3271 } else if (!unsmob<Pitch> ($1))
3272 $$ = MAKE_SYNTAX (event_chord, @1, $1);
3273 // A mere pitch drops through.
3278 DRUM_PITCH optional_notemode_duration {
3279 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3280 n->set_property ("duration", $2);
3281 n->set_property ("drum-type", $1);
3283 $$ = n->unprotect ();
3285 | RESTNAME optional_notemode_duration {
3287 if (ly_scm2string ($1) == "s") {
3289 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3292 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3295 ev->set_property ("duration", $2);
3296 $$ = ev->unprotect ();
3302 if (!parser->lexer_->is_lyric_state ())
3303 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3307 if (!parser->lexer_->is_lyric_state ())
3308 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3314 lyric_element_music:
3315 lyric_element optional_notemode_duration post_events {
3316 $$ = MAKE_SYNTAX (lyric_event, @$, $1, $2);
3317 if (scm_is_pair ($3))
3318 unsmob<Music> ($$)->set_property
3319 ("articulations", scm_reverse_x ($3, SCM_EOL));
3323 // Can return a single pitch rather than a list.
3325 steno_tonic_pitch maybe_notemode_duration {
3326 if (SCM_UNBNDP ($2))
3329 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3331 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3332 SCM its = scm_reverse_x ($4, SCM_EOL);
3333 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3341 | chord_items chord_item {
3342 $$ = scm_cons ($2, $$);
3348 $$ = ly_symbol2scm ("chord-colon");
3351 $$ = ly_symbol2scm ("chord-caret");
3353 | CHORD_SLASH steno_tonic_pitch {
3354 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3356 | CHORD_BASS steno_tonic_pitch {
3357 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3366 $$ = scm_reverse_x ($1, SCM_EOL);
3374 step_number { $$ = scm_cons ($1, SCM_EOL); }
3375 | step_numbers '.' step_number {
3376 $$ = scm_cons ($3, $$);
3382 $$ = make_chord_step ($1, 0);
3385 $$ = make_chord_step ($1, SHARP_ALTERATION);
3387 | UNSIGNED CHORD_MINUS {
3388 $$ = make_chord_step ($1, FLAT_ALTERATION);
3396 | unsigned_number '-' unsigned_number {
3397 $$ = scm_cons ($1, $3);
3404 TODO: should deprecate in favor of Scheme?
3408 number_expression '+' number_term {
3409 $$ = scm_sum ($1, $3);
3411 | number_expression '-' number_term {
3412 $$ = scm_difference ($1, $3);
3421 | number_factor '*' number_factor {
3422 $$ = scm_product ($1, $3);
3424 | number_factor '/' number_factor {
3425 $$ = scm_divide ($1, $3);
3430 '-' number_factor { /* %prec UNARY_MINUS */
3431 $$ = scm_difference ($2, SCM_UNDEFINED);
3439 | REAL NUMBER_IDENTIFIER
3441 $$ = scm_product ($1, $2);
3448 | UNSIGNED NUMBER_IDENTIFIER {
3449 $$ = scm_product ($1, $2);
3457 if (!scm_is_integer ($1)
3458 || scm_is_true (scm_negative_p ($1)))
3460 parser->parser_error (@1, _("not an unsigned integer"));
3466 if (!scm_is_integer ($1)
3467 || scm_is_true (scm_negative_p ($1)))
3469 parser->parser_error (@1, _("not an unsigned integer"));
3476 { $$ = SCM_UNDEFINED; }
3479 if (SCM_UNBNDP ($1))
3487 // This precedence rule is rather weird. It triggers when '!' is
3488 // encountered after a pitch, and is used for deciding whether to save
3489 // this instead for a figure modification. This should not actually
3490 // occur in practice as pitches and figures are generated in different
3491 // modes. Using a greedy (%right) precedence makes sure that we don't
3492 // get stuck in a wrong interpretation.
3493 { $$ = SCM_UNDEFINED; } %prec ':'
3496 if (SCM_UNBNDP ($1))
3505 { parser->lexer_->push_markup_state (); }
3508 parser->lexer_->pop_state ();
3514 { parser->lexer_->push_markup_state (); }
3517 parser->lexer_->pop_state ();
3523 $$ = scm_list_2 (Lily::line_markup, $1);
3525 | markup_head_1_list simple_markup
3527 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3528 @2, $1, scm_list_1 ($2)));
3538 if (Text_interface::is_markup ($1))
3539 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3540 else if (Text_interface::is_markup_list ($1))
3541 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3543 parser->parser_error (@1, _ ("not a markup"));
3544 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3551 markup_composed_list {
3554 | markup_uncomposed_list
3557 markup_uncomposed_list:
3558 markup_braced_list {
3561 | markup_command_list {
3562 $$ = scm_list_1 ($1);
3564 | markup_scm MARKUPLIST_IDENTIFIER
3569 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3570 parser->lexer_->push_note_state (nn);
3571 } '{' score_body '}' {
3572 Score *sc = unsmob<Score> ($4);
3573 sc->origin ()->set_spot (@$);
3574 if (sc->defs_.empty ()) {
3575 Output_def *od = get_layout (parser);
3576 sc->add_output_def (od);
3579 $$ = scm_list_1 (scm_list_2 (Lily::score_lines_markup_list, $4));
3580 parser->lexer_->pop_state ();
3584 markup_composed_list:
3585 markup_head_1_list markup_uncomposed_list {
3586 $$ = MAKE_SYNTAX (composed_markup_list,
3592 '{' markup_braced_list_body '}' {
3593 $$ = scm_reverse_x ($2, SCM_EOL);
3597 markup_braced_list_body:
3598 /* empty */ { $$ = SCM_EOL; }
3599 | markup_braced_list_body markup {
3600 $$ = scm_cons ($2, $1);
3602 | markup_braced_list_body markup_list {
3603 $$ = scm_reverse_x ($2, $1);
3607 markup_command_list:
3608 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3609 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3613 markup_command_basic_arguments:
3614 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3615 $$ = scm_cons ($3, $2);
3617 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3618 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3620 | EXPECT_NO_MORE_ARGS {
3625 markup_command_list_arguments:
3626 markup_command_basic_arguments { $$ = $1; }
3627 | EXPECT_MARKUP markup_command_list_arguments markup {
3628 $$ = scm_cons ($3, $2);
3633 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3634 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3639 markup_head_1_item {
3640 $$ = scm_list_1 ($1);
3642 | markup_head_1_list markup_head_1_item {
3643 $$ = scm_cons ($2, $1);
3649 $$ = make_simple_markup ($1);
3652 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3653 parser->lexer_->push_note_state (nn);
3654 } '{' score_body '}' {
3655 Score *sc = unsmob<Score> ($4);
3656 sc->origin ()->set_spot (@$);
3657 if (sc->defs_.empty ()) {
3658 Output_def *od = get_layout (parser);
3659 sc->add_output_def (od);
3662 $$ = scm_list_2 (Lily::score_markup, $4);
3663 parser->lexer_->pop_state ();
3665 | MARKUP_FUNCTION markup_command_basic_arguments {
3666 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3668 | markup_scm MARKUP_IDENTIFIER
3675 markup_head_1_list simple_markup
3677 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3678 @2, $1, scm_list_1 ($2)));
3688 Lily_parser::set_yydebug (bool x)
3694 Lily_parser::do_yyparse ()
3696 return scm_c_with_fluid (Lily::f_parser,
3698 do_yyparse_trampoline,
3699 static_cast <void *>(this));
3703 Lily_parser::do_yyparse_trampoline (void *parser)
3705 SCM retval = SCM_UNDEFINED;
3706 yyparse (static_cast <Lily_parser *>(parser), &retval);
3714 It is a little strange to have this function in this file, but
3715 otherwise, we have to import music classes into the lexer.
3719 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3721 if (unsmob<Book> (sid)) {
3722 Book *book = unsmob<Book> (sid)->clone ();
3723 *destination = book->self_scm ();
3726 return BOOK_IDENTIFIER;
3727 } else if (scm_is_number (sid)) {
3729 return NUMBER_IDENTIFIER;
3730 } else if (unsmob<Context_def> (sid))
3732 *destination = unsmob<Context_def> (sid)->clone ()->unprotect ();
3733 return SCM_IDENTIFIER;
3734 } else if (unsmob<Context_mod> (sid)) {
3735 *destination = unsmob<Context_mod> (sid)->smobbed_copy ();
3736 return CONTEXT_MOD_IDENTIFIER;
3737 } else if (Music *mus = unsmob<Music> (sid)) {
3738 mus = mus->clone ();
3739 *destination = mus->self_scm ();
3740 bool is_event = mus->is_mus_type ("post-event");
3742 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3743 } else if (unsmob<Pitch> (sid)) {
3744 *destination = unsmob<Pitch> (sid)->smobbed_copy ();
3745 return PITCH_IDENTIFIER;
3746 } else if (unsmob<Duration> (sid)) {
3747 *destination = unsmob<Duration> (sid)->smobbed_copy ();
3748 return DURATION_IDENTIFIER;
3749 } else if (unsmob<Output_def> (sid)) {
3750 *destination = unsmob<Output_def> (sid)->clone ()->unprotect ();
3751 return SCM_IDENTIFIER;
3752 } else if (unsmob<Score> (sid)) {
3753 *destination = unsmob<Score> (sid)->clone ()->unprotect ();
3754 return SCM_IDENTIFIER;
3761 get_next_unique_context_id ()
3763 return scm_from_ascii_string ("$uniqueContextId");
3768 get_next_unique_lyrics_context_id ()
3770 static int new_context_count;
3772 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3773 return scm_from_ascii_string (s);
3776 // check_scheme_arg checks one argument with a given predicate for use
3777 // in an argument list and throws a syntax error if it is unusable.
3778 // The argument is prepended to the argument list in any case. After
3779 // throwing a syntax error, the argument list is terminated with #f as
3780 // its last cdr in order to mark it as uncallable while not losing
3781 // track of its total length.
3783 // There are a few special considerations: if optional argument disp
3784 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3785 // instead of arg in a prospective error message. This is useful if
3786 // arg is not the actual argument but rather a transformation of it.
3788 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3789 // and an error message using disp is produced unconditionally.
3791 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3792 SCM arg, SCM args, SCM pred, SCM disp)
3794 if (SCM_UNBNDP (arg))
3795 args = scm_cons (disp, args);
3797 args = scm_cons (arg, args);
3798 if (scm_is_true (scm_call_1 (pred, arg)))
3801 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3802 MAKE_SYNTAX (argument_error, loc, scm_length (args), pred,
3803 SCM_UNBNDP (disp) ? arg : disp);
3804 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3808 SCM loc_on_music (Input loc, SCM arg)
3810 if (Music *m = unsmob<Music> (arg))
3814 return m->unprotect ();
3820 try_string_variants (SCM pred, SCM str)
3822 // a matching predicate is always ok
3823 if (scm_is_true (scm_call_1 (pred, str)))
3825 // a symbol may be interpreted as a list of symbols if it helps
3826 if (scm_is_symbol (str)) {
3827 str = scm_list_1 (str);
3828 if (scm_is_true (scm_call_1 (pred, str)))
3830 return SCM_UNDEFINED;
3833 // If this cannot be a string representation of a symbol list,
3836 if (!is_regular_identifier (str, true))
3837 return SCM_UNDEFINED;
3839 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3840 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3841 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3843 // Let's attempt the symbol list interpretation first.
3845 if (scm_is_true (scm_call_1 (pred, str)))
3848 // If there is just one symbol in the list, we might interpret
3849 // it as a single symbol
3851 if (scm_is_null (scm_cdr (str)))
3853 str = scm_car (str);
3854 if (scm_is_true (scm_call_1 (pred, str)))
3858 return SCM_UNDEFINED;
3862 is_regular_identifier (SCM id, bool multiple)
3864 if (!scm_is_string (id))
3867 string str = ly_scm2string (id);
3869 bool middle = false;
3871 for (string::iterator it=str.begin(); it != str.end (); it++)
3874 if ((c >= 'a' && c <= 'z')
3875 || (c >= 'A' && c <= 'Z')
3878 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3887 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3889 if (unsmob<Music> (simple))
3891 if (parser->lexer_->is_note_state ()) {
3892 if (scm_is_symbol (simple)) {
3893 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3894 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3895 n->set_property ("drum-type", simple);
3896 return n->unprotect ();
3898 if (unsmob<Pitch> (simple)) {
3899 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3900 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3901 n->set_property ("pitch", simple);
3902 return n->unprotect ();
3905 } else if (parser->lexer_->is_lyric_state ()) {
3906 if (Text_interface::is_markup (simple))
3907 return MAKE_SYNTAX (lyric_event, loc, simple,
3908 parser->default_duration_.smobbed_copy ());
3909 } else if (parser->lexer_->is_chord_state ()) {
3910 if (unsmob<Pitch> (simple))
3914 make_chord_elements (loc, simple,
3915 parser->default_duration_.smobbed_copy (),
3922 make_music_with_input (SCM name, Input where)
3924 Music *m = make_music_by_name (name);
3925 m->set_spot (where);
3930 make_simple_markup (SCM a)
3936 make_duration (SCM d, int dots)
3938 int t = scm_to_int (d);
3939 if (t > 0 && (t & (t-1)) == 0)
3940 return Duration (intlog2 (t), dots).smobbed_copy ();
3942 return SCM_UNDEFINED;
3946 make_chord_step (SCM step_scm, Rational alter)
3948 int step = scm_to_int (step_scm);
3951 alter += FLAT_ALTERATION;
3955 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3956 return m.smobbed_copy ();
3961 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3963 SCM res = Lily::construct_chord_elements (pitch, dur, modification_list);
3964 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3966 unsmob<Music> (scm_car (s))->set_spot (loc);
3972 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3974 Lily_lexer *lex = parser->lexer_;
3978 int tok = lex->pop_extra_token ();
3981 lex->prepare_for_next_token ();
3982 return lex->yylex ();