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 - Don't use lily module, create a new module instead.
191 - delay application of the function
195 syntax_call (void *arg)
197 SCM sarg = reinterpret_cast <SCM> (arg);
198 return scm_apply_0 (scm_car (sarg), scm_cdr (sarg));
201 #define LOWLEVEL_MAKE_SYNTAX(location, args) \
204 parser->lexer_->override_input (location).smobbed_copy (), \
206 reinterpret_cast <void*> (args))
208 /* Syntactic Sugar. */
209 #define MAKE_SYNTAX(name, location, ...) \
210 LOWLEVEL_MAKE_SYNTAX (location, \
211 scm_list_n (Syntax::name, \
212 ##__VA_ARGS__, SCM_UNDEFINED))
214 #define START_MAKE_SYNTAX(name, ...) \
215 scm_list_n (Syntax::name, \
216 ##__VA_ARGS__, SCM_UNDEFINED)
218 #define FINISH_MAKE_SYNTAX(start, location, ...) \
219 LOWLEVEL_MAKE_SYNTAX (location, \
221 (scm_list_2 (start, scm_list_n \
222 (__VA_ARGS__, SCM_UNDEFINED))))
224 SCM get_next_unique_context_id ();
225 SCM get_next_unique_lyrics_context_id ();
232 #define _(x) gettext (x)
236 static Music *make_music_with_input (SCM name, Input where);
237 SCM check_scheme_arg (Lily_parser *parser, Input loc,
238 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
239 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
240 SCM loc_on_music (Input loc, SCM arg);
241 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
242 SCM make_chord_step (SCM step, Rational alter);
243 SCM make_simple_markup (SCM a);
244 SCM make_duration (SCM t, int dots = 0);
245 bool is_regular_identifier (SCM id, bool multiple=false);
246 SCM try_string_variants (SCM pred, SCM str);
247 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
251 /* The third option is an alias that will be used to display the
252 syntax error. Bison CVS now correctly handles backslash escapes.
254 FIXME: Bison needs to translate some of these, eg, STRING.
258 /* Keyword tokens with plain escaped name. */
259 %token END_OF_FILE 0 "end of input"
260 %token ACCEPTS "\\accepts"
261 %token ADDLYRICS "\\addlyrics"
262 %token ALIAS "\\alias"
263 %token ALTERNATIVE "\\alternative"
265 %token BOOKPART "\\bookpart"
266 %token CHANGE "\\change"
267 %token CHORDMODE "\\chordmode"
268 %token CHORDS "\\chords"
269 %token CONSISTS "\\consists"
270 %token CONTEXT "\\context"
271 %token DEFAULT "\\default"
272 %token DEFAULTCHILD "\\defaultchild"
273 %token DENIES "\\denies"
274 %token DESCRIPTION "\\description"
275 %token DRUMMODE "\\drummode"
276 %token DRUMS "\\drums"
277 %token FIGUREMODE "\\figuremode"
278 %token FIGURES "\\figures"
279 %token HEADER "\\header"
280 %token INVALID "\\version-error"
281 %token LAYOUT "\\layout"
282 %token LYRICMODE "\\lyricmode"
283 %token LYRICS "\\lyrics"
284 %token LYRICSTO "\\lyricsto"
285 %token MARKUP "\\markup"
286 %token MARKUPLIST "\\markuplist"
289 %token NOTEMODE "\\notemode"
290 %token OVERRIDE "\\override"
291 %token PAPER "\\paper"
292 %token REMOVE "\\remove"
293 %token REPEAT "\\repeat"
295 %token REVERT "\\revert"
296 %token SCORE "\\score"
297 %token SCORELINES "\\score-lines"
298 %token SEQUENTIAL "\\sequential"
300 %token SIMULTANEOUS "\\simultaneous"
301 %token TEMPO "\\tempo"
303 %token UNSET "\\unset"
306 /* Keyword token exceptions. */
307 %token NEWCONTEXT "\\new"
310 /* Other string tokens. */
312 %token CHORD_BASS "/+"
313 %token CHORD_CARET "^"
314 %token CHORD_COLON ":"
315 %token CHORD_MINUS "-"
316 %token CHORD_SLASH "/"
317 %token ANGLE_OPEN "<"
318 %token ANGLE_CLOSE ">"
319 %token DOUBLE_ANGLE_OPEN "<<"
320 %token DOUBLE_ANGLE_CLOSE ">>"
321 %token E_BACKSLASH "\\"
322 %token E_EXCLAMATION "\\!"
327 If we give names, Bison complains.
329 %token FIGURE_CLOSE /* "\\>" */
330 %token FIGURE_OPEN /* "\\<" */
331 %token FIGURE_SPACE "_"
334 %token MULTI_MEASURE_REST
340 /* Artificial tokens, for more generic function syntax */
341 %token EXPECT_MARKUP "markup?"
342 %token EXPECT_SCM "scheme?"
343 %token BACKUP "(backed-up?)"
344 %token REPARSE "(reparsed?)"
345 %token EXPECT_MARKUP_LIST "markup-list?"
346 %token EXPECT_OPTIONAL "optional?"
347 /* After the last argument. */
348 %token EXPECT_NO_MORE_ARGS;
350 /* An artificial token for parsing embedded Lilypond */
351 %token EMBEDDED_LILY "#{"
353 %token BOOK_IDENTIFIER
354 %token CHORD_MODIFIER
355 %token CHORD_REPETITION
356 %token CONTEXT_MOD_IDENTIFIER
358 %token PITCH_IDENTIFIER
359 %token DURATION_IDENTIFIER
360 %token EVENT_IDENTIFIER
361 %token EVENT_FUNCTION
364 %token MARKUP_FUNCTION
365 %token MARKUP_LIST_FUNCTION
366 %token MARKUP_IDENTIFIER
367 %token MARKUPLIST_IDENTIFIER
368 %token MUSIC_FUNCTION
369 %token MUSIC_IDENTIFIER
370 %token NOTENAME_PITCH
371 %token NUMBER_IDENTIFIER
376 %token SCM_IDENTIFIER
380 %token TONICNAME_PITCH
384 /* We don't assign precedence to / and *, because we might need varied
385 prec levels in different prods */
394 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
395 parser->lexer_->push_note_state (nn);
396 } embedded_lilypond {
397 parser->lexer_->pop_state ();
402 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
403 | lilypond toplevel_expression {
405 | lilypond assignment {
408 parser->error_level_ = 1;
411 parser->error_level_ = 1;
418 parser->lexer_->add_scope (get_header (parser));
420 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
423 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
424 scm_call_1 (proc, $1);
427 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
428 scm_call_1 (proc, $1);
431 SCM proc = parser->lexer_->lookup_identifier
432 (unsmob<Book>($1)->paper_
433 ? "toplevel-book-handler"
434 : "toplevel-bookpart-handler");
435 scm_call_1 (proc, $1);
438 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
439 scm_call_1 (proc, $1);
442 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
443 scm_call_1 (proc, $1);
446 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
447 scm_call_1 (proc, scm_list_1 ($1));
450 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
451 scm_call_1 (proc, $1);
454 // Evaluate and ignore #xxx, as opposed to \xxx
455 parser->lexer_->eval_scm_token ($1, @1);
457 | embedded_scm_active
459 SCM out = SCM_UNDEFINED;
460 if (Text_interface::is_markup ($1))
461 out = scm_list_1 ($1);
462 else if (Text_interface::is_markup_list ($1))
464 if (scm_is_pair (out))
466 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
467 scm_call_1 (proc, out);
468 } else if (unsmob<Score> ($1))
470 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
471 scm_call_1 (proc, $1);
472 } else if (Output_def * od = unsmob<Output_def> ($1)) {
475 if (to_boolean (od->c_variable ("is-paper")))
476 id = ly_symbol2scm ("$defaultpaper");
477 else if (to_boolean (od->c_variable ("is-midi")))
478 id = ly_symbol2scm ("$defaultmidi");
479 else if (to_boolean (od->c_variable ("is-layout")))
480 id = ly_symbol2scm ("$defaultlayout");
482 parser->lexer_->set_identifier (id, $1);
483 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
484 parser->parser_error (@1, _("bad expression type"));
488 Output_def * od = unsmob<Output_def> ($1);
490 if (to_boolean (od->c_variable ("is-paper")))
491 id = ly_symbol2scm ("$defaultpaper");
492 else if (to_boolean (od->c_variable ("is-midi")))
493 id = ly_symbol2scm ("$defaultmidi");
494 else if (to_boolean (od->c_variable ("is-layout")))
495 id = ly_symbol2scm ("$defaultlayout");
497 parser->lexer_->set_identifier (id, $1);
504 $$ = parser->lexer_->eval_scm_token ($1, @1);
514 embedded_scm_bare_arg:
518 $$ = parser->lexer_->eval_scm_token ($1, @1);
522 | context_modification
524 | context_def_spec_block
530 /* The generic version may end in music, or not */
537 /* embedded_scm_arg is _not_ casting pitches to music by default, this
538 * has to be done by the function itself. Note that this may cause
539 * the results of scm_function_call or embedded_scm_bare_arg to be
540 * turned into music from pitches as well. Note that this creates a
541 * distinctly awkward situation for calculated drum pitches. Those
542 * are at the current point of time rejected as music constituents as
543 * they can't be distinguished from "proper" symbols.
547 embedded_scm_bare_arg
553 SCM_FUNCTION function_arglist {
554 $$ = MAKE_SYNTAX (music_function, @$,
559 embedded_lilypond_number:
560 '-' embedded_lilypond_number
562 $$ = scm_difference ($2, SCM_UNDEFINED);
565 | UNSIGNED NUMBER_IDENTIFIER
567 $$ = scm_product ($1, $2);
574 // FIXME: @$ does not contain a useful source location
575 // for empty rules, and the only token in the whole
576 // production, EMBEDDED_LILY, is synthetic and also
577 // contains no source location.
578 $$ = MAKE_SYNTAX (void_music, @$);
580 | identifier_init_nonumber
581 | embedded_lilypond_number
582 | post_event post_events
584 $$ = scm_reverse_x ($2, SCM_EOL);
585 if (Music *m = unsmob<Music> ($1))
587 if (m->is_mus_type ("post-event-wrapper"))
589 (scm_list_2 (m->get_property ("elements"),
592 $$ = scm_cons ($1, $$);
595 && scm_is_null (scm_cdr ($$)))
599 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
600 m->set_property ("elements", $$);
601 $$ = m->unprotect ();
604 | multiplied_duration
605 | music_embedded music_embedded music_list {
606 $3 = scm_reverse_x ($3, SCM_EOL);
607 if (unsmob<Music> ($2))
608 $3 = scm_cons ($2, $3);
609 if (unsmob<Music> ($1))
610 $3 = scm_cons ($1, $3);
611 $$ = MAKE_SYNTAX (sequential_music, @$, $3);
614 parser->error_level_ = 1;
615 $$ = SCM_UNSPECIFIED;
617 | INVALID embedded_lilypond {
618 parser->error_level_ = 1;
624 lilypond_header_body:
625 /* empty */ { $$ = SCM_UNSPECIFIED; }
626 | lilypond_header_body assignment {
629 | lilypond_header_body embedded_scm {
635 HEADER '{' lilypond_header_body '}' {
636 $$ = parser->lexer_->remove_scope ();
648 assignment_id '=' identifier_init {
649 parser->lexer_->set_identifier ($1, $3);
650 $$ = SCM_UNSPECIFIED;
652 | assignment_id property_path '=' identifier_init {
653 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
654 parser->lexer_->set_identifier (path, $4);
655 $$ = SCM_UNSPECIFIED;
657 | assignment_id '.' property_path '=' identifier_init {
658 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
659 parser->lexer_->set_identifier (path, $5);
660 $$ = SCM_UNSPECIFIED;
666 identifier_init_nonumber
668 | post_event_nofinger post_events
670 $$ = scm_reverse_x ($2, SCM_EOL);
671 if (Music *m = unsmob<Music> ($1))
673 if (m->is_mus_type ("post-event-wrapper"))
675 (scm_list_2 (m->get_property ("elements"),
678 $$ = scm_cons ($1, $$);
681 && scm_is_null (scm_cdr ($$)))
685 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
686 m->set_property ("elements", $$);
687 $$ = m->unprotect ();
692 identifier_init_nonumber:
697 | context_def_spec_block
704 | context_modification
707 context_def_spec_block:
708 CONTEXT '{' context_def_spec_body '}'
711 Context_def *td = unsmob<Context_def> ($$);
713 $$ = Context_def::make_scm ();
714 td = unsmob<Context_def> ($$);
716 td->origin ()->set_spot (@$);
724 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
725 parser->lexer_->push_note_state (nn);
729 parser->lexer_->pop_state ();
735 context_def_spec_body:
737 $$ = SCM_UNSPECIFIED;
739 | context_def_spec_body context_mod {
740 if (!SCM_UNBNDP ($2)) {
741 Context_def *td = unsmob<Context_def> ($$);
743 $$ = Context_def::make_scm ();
744 td = unsmob<Context_def> ($$);
746 unsmob<Context_def> ($$)->add_context_mod ($2);
749 | context_def_spec_body context_modification {
750 Context_def *td = unsmob<Context_def> ($$);
752 $$ = Context_def::make_scm ();
753 td = unsmob<Context_def> ($$);
755 SCM new_mods = unsmob<Context_mod> ($2)->get_mods ();
756 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
757 td->add_context_mod (scm_car (m));
760 | context_def_spec_body context_mod_arg {
761 Context_def *td = unsmob<Context_def> ($1);
762 if (scm_is_eq ($2, SCM_UNSPECIFIED))
764 else if (!td && unsmob<Context_def> ($2))
768 $$ = Context_def::make_scm ();
769 td = unsmob<Context_def> ($$);
771 if (unsmob<Music> ($2)) {
772 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
773 $2 = scm_call_1 (proc, $2);
775 if (Context_mod *cm = unsmob<Context_mod> ($2)) {
776 for (SCM m = cm->get_mods (); scm_is_pair (m); m = scm_cdr (m)) {
777 td->add_context_mod (scm_car (m));
780 parser->parser_error (@2, _ ("not a context mod"));
788 BOOK '{' book_body '}' {
790 unsmob<Book> ($$)->origin ()->set_spot (@$);
792 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
797 * Use 'handlers' like for toplevel-* stuff?
798 * grok \layout and \midi? */
801 Book *book = new Book;
802 init_papers (parser);
803 book->paper_ = dynamic_cast<Output_def*> (unsmob<Output_def> (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
804 book->paper_->unprotect ();
805 push_paper (parser, book->paper_);
806 book->header_ = get_header (parser);
807 $$ = book->unprotect ();
808 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
811 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
813 | book_body paper_block {
814 unsmob<Book> ($1)->paper_ = unsmob<Output_def> ($2);
815 set_paper (parser, unsmob<Output_def> ($2));
817 | book_body bookpart_block {
818 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
819 scm_call_2 (proc, $1, $2);
821 | book_body score_block {
822 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
823 scm_call_2 (proc, $1, $2);
825 | book_body composite_music {
826 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
827 scm_call_2 (proc, $1, $2);
829 | book_body full_markup {
830 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
831 scm_call_2 (proc, $1, scm_list_1 ($2));
833 | book_body full_markup_list {
834 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
835 scm_call_2 (proc, $1, $2);
837 | book_body SCM_TOKEN {
838 // Evaluate and ignore #xxx, as opposed to \xxx
839 parser->lexer_->eval_scm_token ($2, @2);
841 | book_body embedded_scm_active
843 SCM out = SCM_UNDEFINED;
844 if (Text_interface::is_markup ($2))
845 out = scm_list_1 ($2);
846 else if (Text_interface::is_markup_list ($2))
848 if (scm_is_pair (out))
850 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
851 scm_call_2 (proc, $1, out);
852 } else if (unsmob<Score> ($2))
854 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
855 scm_call_2 (proc, $1, $2);
856 } else if (Output_def *od = unsmob<Output_def> ($2)) {
859 if (to_boolean (od->c_variable ("is-paper")))
860 id = ly_symbol2scm ("$defaultpaper");
861 else if (to_boolean (od->c_variable ("is-midi")))
862 id = ly_symbol2scm ("$defaultmidi");
863 else if (to_boolean (od->c_variable ("is-layout")))
864 id = ly_symbol2scm ("$defaultlayout");
866 parser->lexer_->set_identifier (id, $2);
867 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
868 parser->parser_error (@2, _("bad expression type"));
872 parser->lexer_->add_scope (unsmob<Book> ($1)->header_);
875 Book *book = unsmob<Book> ($1);
877 book->scores_ = SCM_EOL;
878 book->bookparts_ = SCM_EOL;
883 BOOKPART '{' bookpart_body '}' {
885 unsmob<Book> ($$)->origin ()->set_spot (@$);
886 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
892 Book *book = new Book;
893 $$ = book->unprotect ();
894 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
897 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
899 | bookpart_body paper_block {
900 unsmob<Book> ($$)->paper_ = unsmob<Output_def> ($2);
902 | bookpart_body score_block {
903 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
904 scm_call_2 (proc, $1, $2);
906 | bookpart_body composite_music {
907 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
908 scm_call_2 (proc, $1, $2);
910 | bookpart_body full_markup {
911 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
912 scm_call_2 (proc, $1, scm_list_1 ($2));
914 | bookpart_body full_markup_list {
915 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
916 scm_call_2 (proc, $1, $2);
918 | bookpart_body SCM_TOKEN {
919 // Evaluate and ignore #xxx, as opposed to \xxx
920 parser->lexer_->eval_scm_token ($2, @2);
922 | bookpart_body embedded_scm_active
924 SCM out = SCM_UNDEFINED;
925 if (Text_interface::is_markup ($2))
926 out = scm_list_1 ($2);
927 else if (Text_interface::is_markup_list ($2))
929 if (scm_is_pair (out))
931 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
932 scm_call_2 (proc, $1, out);
933 } else if (unsmob<Score> ($2))
935 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
936 scm_call_2 (proc, $1, $2);
937 } else if (Output_def *od = unsmob<Output_def> ($2)) {
940 if (to_boolean (od->c_variable ("is-paper")))
941 id = ly_symbol2scm ("$defaultpaper");
942 else if (to_boolean (od->c_variable ("is-midi")))
943 id = ly_symbol2scm ("$defaultmidi");
944 else if (to_boolean (od->c_variable ("is-layout")))
945 id = ly_symbol2scm ("$defaultlayout");
947 parser->lexer_->set_identifier (id, $2);
948 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
949 parser->parser_error (@2, _("bad expression type"));
953 Book *book = unsmob<Book> ($1);
954 if (!ly_is_module (book->header_))
955 book->header_ = ly_make_module (false);
956 parser->lexer_->add_scope (book->header_);
958 | bookpart_body error {
959 Book *book = unsmob<Book> ($1);
961 book->scores_ = SCM_EOL;
966 SCORE '{' score_body '}' {
967 unsmob<Score> ($3)->origin ()->set_spot (@$);
974 if (!unsmob<Score> ($1)) {
975 parser->parser_error (@1, _("Missing music in \\score"));
976 $$ = (new Score)->unprotect ();
977 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
979 unsmob<Score> ($$)->set_header (scm_car ($1));
982 for (SCM p = scm_reverse_x ($1, SCM_EOL);
983 scm_is_pair (p); p = scm_cdr (p))
986 add_output_def (unsmob<Output_def> (scm_car (p)));
991 unsmob<Score> ($$)->error_found_ = true;
1006 | score_items score_item
1008 Output_def *od = unsmob<Output_def> ($2);
1010 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1012 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1014 $2 = SCM_UNSPECIFIED;
1016 } else if (!unsmob<Score> ($$)) {
1017 if (unsmob<Music> ($2)) {
1018 $2 = Lily::scorify_music ($2);
1020 if (unsmob<Score> ($2))
1023 $2 = SCM_UNSPECIFIED;
1026 Score *score = unsmob<Score> ($$);
1027 if (score && scm_is_pair ($1)) {
1028 if (ly_is_module (scm_car ($1)))
1030 score->set_header (scm_car ($1));
1033 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1034 scm_is_pair (p); p = scm_cdr (p))
1036 score->add_output_def (unsmob<Output_def> (scm_car (p)));
1041 score->add_output_def (od);
1042 else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1043 scm_set_cdr_x ($$, scm_cons ($2, scm_cdr ($$)));
1045 $$ = scm_cons ($2, $$);
1046 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1047 parser->parser_error (@2, _("Spurious expression in \\score"));
1051 if (Score *score = unsmob<Score> ($1)) {
1052 if (!ly_is_module (score->get_header ()))
1053 score->set_header (ly_make_module (false));
1054 parser->lexer_->add_scope (score->get_header ());
1056 if (!scm_is_pair ($1) || !ly_is_module (scm_car ($1)))
1057 $1 = scm_cons (ly_make_module (false), $1);
1058 parser->lexer_->add_scope (scm_car ($1));
1073 Output_def *od = unsmob<Output_def> ($1);
1075 if (!to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1077 parser->parser_error (@1, _ ("need \\paper for paper block"));
1078 $$ = get_paper (parser)->unprotect ();
1085 output_def_body '}' {
1086 if (scm_is_pair ($1))
1089 parser->lexer_->remove_scope ();
1090 parser->lexer_->pop_state ();
1096 Output_def *p = get_paper (parser);
1097 p->input_origin_ = @$;
1098 parser->lexer_->add_scope (p->scope_);
1099 $$ = p->unprotect ();
1102 Output_def *p = get_midi (parser);
1103 $$ = p->unprotect ();
1104 parser->lexer_->add_scope (p->scope_);
1107 Output_def *p = get_layout (parser);
1109 parser->lexer_->add_scope (p->scope_);
1110 $$ = p->unprotect ();
1114 output_def_head_with_mode_switch:
1116 parser->lexer_->push_initial_state ();
1121 // We need this weird nonterminal because both music as well as a
1122 // context definition can start with \context and the difference is
1123 // only apparent after looking at the next token. If it is '{', there
1124 // is still time to escape from notes mode.
1126 music_or_context_def:
1128 | context_def_spec_block
1132 output_def_head_with_mode_switch '{' {
1133 unsmob<Output_def> ($1)->input_origin_.set_spot (@$);
1134 // This is a stupid trick to mark the beginning of the
1135 // body for deciding whether to allow
1136 // embedded_scm_active to have an output definition
1137 $$ = scm_list_1 ($1);
1139 | output_def_body assignment {
1140 if (scm_is_pair ($1))
1143 | output_def_body embedded_scm_active
1145 // We don't switch into note mode for Scheme functions
1146 // here. Does not seem warranted/required in output
1148 if (scm_is_pair ($1))
1150 Output_def *o = unsmob<Output_def> ($2);
1152 o->input_origin_.set_spot (@$);
1153 $1 = o->self_scm ();
1154 parser->lexer_->remove_scope ();
1155 parser->lexer_->add_scope (o->scope_);
1156 $2 = SCM_UNSPECIFIED;
1160 if (unsmob<Context_def> ($2))
1161 assign_context_def (unsmob<Output_def> ($1), $2);
1162 // Seems unlikely, but let's be complete:
1163 else if (unsmob<Music> ($2))
1165 SCM proc = parser->lexer_->lookup_identifier
1166 ("output-def-music-handler");
1167 scm_call_2 (proc, $1, $2);
1168 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1169 parser->parser_error (@2, _("bad expression type"));
1172 | output_def_body SCM_TOKEN {
1173 if (scm_is_pair ($1))
1175 // Evaluate and ignore #xxx, as opposed to \xxx
1176 parser->lexer_->eval_scm_token ($2, @2);
1180 if (scm_is_pair ($1))
1182 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1183 parser->lexer_->push_note_state (nn);
1184 } music_or_context_def
1186 parser->lexer_->pop_state ();
1187 if (unsmob<Context_def> ($3))
1188 assign_context_def (unsmob<Output_def> ($1), $3);
1191 SCM proc = parser->lexer_->lookup_identifier
1192 ("output-def-music-handler");
1193 scm_call_2 (proc, $1, $3);
1197 | output_def_body error {
1203 TEMPO steno_duration '=' tempo_range {
1204 $$ = MAKE_SYNTAX (tempo, @$, SCM_EOL, $2, $4);
1206 | TEMPO scalar steno_duration '=' tempo_range {
1207 $$ = MAKE_SYNTAX (tempo, @$, $2, $3, $5);
1210 $$ = MAKE_SYNTAX (tempo, @$, $2);
1215 The representation of a list is reversed to have efficient append. */
1221 | music_list music_embedded {
1222 if (unsmob<Music> ($2))
1223 $$ = scm_cons ($2, $1);
1225 | music_list error {
1226 Music *m = MY_MAKE_MUSIC("Music", @$);
1228 m->set_property ("error-found", SCM_BOOL_T);
1229 $$ = scm_cons (m->self_scm (), $1);
1230 m->unprotect (); /* UGH */
1237 $$ = scm_reverse_x ($2, SCM_EOL);
1242 | lyric_element_music
1249 $$ = make_music_from_simple (parser, @1, $1);
1250 if (!unsmob<Music> ($$))
1252 parser->parser_error (@1, _ ("music expected"));
1253 $$ = MAKE_SYNTAX (void_music, @$);
1261 if (unsmob<Music> ($1)->is_mus_type ("post-event")) {
1262 parser->parser_error (@1, _ ("unexpected post-event"));
1263 $$ = SCM_UNSPECIFIED;
1266 | music_embedded_backup
1270 | music_embedded_backup BACKUP lyric_element_music
1274 | multiplied_duration post_events
1276 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1278 parser->default_duration_ = *unsmob<Duration> ($1);
1279 n->set_property ("duration", $1);
1281 if (scm_is_pair ($2))
1282 n->set_property ("articulations",
1283 scm_reverse_x ($2, SCM_EOL));
1284 $$ = n->unprotect ();
1288 music_embedded_backup:
1291 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1293 else if (Music *m = unsmob<Music> ($1)) {
1294 if (m->is_mus_type ("post-event")) {
1295 parser->parser_error
1296 (@1, _ ("unexpected post-event"));
1297 $$ = SCM_UNSPECIFIED;
1300 } else if (parser->lexer_->is_lyric_state ()
1301 && Text_interface::is_markup ($1))
1302 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1304 @$.warning (_ ("Ignoring non-music expression"));
1310 // music_assign does not need to contain lyrics: there are no
1311 // assignments in lyricmode.
1314 | composite_music %prec COMPOSITE
1318 REPEAT simple_string unsigned_number music
1320 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, SCM_EOL);
1322 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1324 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, $6);
1329 SEQUENTIAL braced_music_list {
1330 $$ = MAKE_SYNTAX (sequential_music, @$, $2);
1332 | braced_music_list {
1333 $$ = MAKE_SYNTAX (sequential_music, @$, $1);
1338 SIMULTANEOUS braced_music_list {
1339 $$ = MAKE_SYNTAX (simultaneous_music, @$, $2);
1341 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1342 $$ = MAKE_SYNTAX (simultaneous_music, @$, scm_reverse_x ($2, SCM_EOL));
1348 | music_property_def
1352 context_modification:
1355 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1356 parser->lexer_->push_note_state (nn);
1357 } '{' context_mod_list '}'
1359 parser->lexer_->pop_state ();
1362 | WITH CONTEXT_MOD_IDENTIFIER
1366 | CONTEXT_MOD_IDENTIFIER
1370 | WITH context_modification_arg
1372 if (unsmob<Music> ($2)) {
1373 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1374 $2 = scm_call_1 (proc, $2);
1376 if (unsmob<Context_mod> ($2))
1379 parser->parser_error (@2, _ ("not a context mod"));
1380 $$ = Context_mod ().smobbed_copy ();
1385 context_modification_arg:
1390 optional_context_mod:
1394 | context_modification
1402 $$ = Context_mod ().smobbed_copy ();
1404 | context_mod_list context_mod {
1405 if (!SCM_UNBNDP ($2))
1406 unsmob<Context_mod> ($1)->add_context_mod ($2);
1408 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1409 Context_mod *md = unsmob<Context_mod> ($2);
1411 unsmob<Context_mod> ($1)->add_context_mods (md->get_mods ());
1413 | context_mod_list context_mod_arg {
1414 if (scm_is_eq ($2, SCM_UNSPECIFIED))
1416 else if (unsmob<Music> ($2)) {
1417 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1418 $2 = scm_call_1 (proc, $2);
1420 if (unsmob<Context_mod> ($2))
1421 unsmob<Context_mod> ($$)->add_context_mods
1422 (unsmob<Context_mod> ($2)->get_mods ());
1424 parser->parser_error (@2, _ ("not a context mod"));
1430 CONTEXT symbol optional_id optional_context_mod {
1431 Context_mod *ctxmod = unsmob<Context_mod> ($4);
1434 mods = ctxmod->get_mods ();
1435 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, mods, SCM_BOOL_F);
1437 | NEWCONTEXT symbol optional_id optional_context_mod {
1438 Context_mod *ctxmod = unsmob<Context_mod> ($4);
1441 mods = ctxmod->get_mods ();
1442 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, mods, SCM_BOOL_T);
1447 ADDLYRICS lyric_mode_music {
1448 $$ = scm_list_1 ($2);
1450 | new_lyrics ADDLYRICS lyric_mode_music {
1451 $$ = scm_cons ($3, $1);
1455 /* basic_music is basically the same as composite_music but with
1456 * context-prefixed music and lyricized music explicitly removed. The
1457 * reason is that in a sequence
1459 * \new Staff \new Voice { ... } \addlyrics { ... } \addlyrics { ... }
1461 * we need to group both \addlyrics together (as they go with the same
1462 * voice) but then combine them with \new Voice { ... }, meaning that
1463 * combining \new Voice { ... } needs higher priority than
1464 * { ... } \addlyrics, and *not* have \new Staff \new Voice { ... }
1465 * combine before combining \new Voice { ... } \addlyrics: only one
1466 * layer of context-prefixed music should assemble before \addlyrics
1467 * is integrated. Total mess, and we sort this mess out with explicit
1468 * rules preferring a single context-prefix.
1475 | LYRICSTO simple_string lyric_mode_music {
1476 $$ = MAKE_SYNTAX (lyric_combine, @$, $2, SCM_EOL, $3);
1478 | LYRICSTO symbol '=' simple_string lyric_mode_music
1480 $$ = MAKE_SYNTAX (lyric_combine, @$, $3, $2, $4);
1490 contexted_basic_music:
1491 context_prefix contextable_music new_lyrics
1494 i.set_location (@1, @2);
1495 $$ = FINISH_MAKE_SYNTAX ($1, i, $2);
1496 $$ = MAKE_SYNTAX (add_lyrics, @$, $$, scm_reverse_x ($3, SCM_EOL));
1498 | context_prefix contextable_music
1500 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1502 | context_prefix contexted_basic_music
1504 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1509 basic_music %prec COMPOSITE
1510 | contexted_basic_music
1511 | basic_music new_lyrics
1513 $$ = MAKE_SYNTAX (add_lyrics, @$, $1, scm_reverse_x ($2, SCM_EOL));
1520 | grouped_music_list
1524 simultaneous_music { $$ = $1; }
1525 | sequential_music { $$ = $1; }
1528 /* Function argument lists are arguably the most complex part in the
1529 * parser. They are pretty tricky to understand because of the way
1530 * they are processed, and because of optional arguments that can be
1531 * omitted. When there are several optional arguments in a row,
1532 * omitting one automatically omits all following arguments. Optional
1533 * arguments can only be omitted when either
1535 * a) the omission is explicitly started with \default
1536 * b) the omission is implicitly started by an argument not matching
1537 * its predicate, and there is a mandatory argument later that can
1538 * "catch" the argument that does not fit.
1540 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1541 * (corresponding to mandatory arguments and having a predicate
1542 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1543 * the semantic value of the EXPECT_OPTIONAL token is the default to
1544 * use when the optional argument is omitted, and EXPECT_SCM again has
1545 * the argument predicate as semantic value) in reverse order to the
1546 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1547 * processed inside-out while actual tokens are consumed.
1549 * This means that the argument list tokens determine the actions
1550 * taken as they arrive. The structure of the argument list is known
1551 * to the parser and stored in its parse stack when the first argument
1552 * is being parsed. What the parser does not know is which predicates
1553 * will match and whether or not \default will be appearing in the
1554 * argument list, and where.
1556 * Sequences of 0 or more optional arguments are scanned using either
1557 * function_arglist_backup or function_arglist_nonbackup. The first
1558 * is used when optional arguments are followed by at least one
1559 * mandatory argument: in that case optional arguments may be skipped
1560 * by either a false predicate (in which case the expression will be
1561 * pushed back as one or more tokens, preceded by a BACKUP token) or
1562 * by using \default.
1564 * If optional arguments are at the end of the argument list, they are
1565 * instead scanned using function_arglist_nonbackup: here the only
1566 * manner to enter into skipping of optional arguments is the use of
1569 * The argument list of a normal function call is parsed using
1570 * function_arglist. The part of an argument list before a mandatory
1571 * argument is parsed using function_arglist_optional.
1573 * The difference is that leading optional arguments are scanned using
1574 * function_arglist_nonbackup and function_arglist_backup,
1577 * Most other details are obvious in the rules themselves.
1583 | SYMBOL_LIST '.' symbol_list_rev
1585 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1591 | symbol_list_rev '.' symbol_list_part
1593 $$ = scm_append_x (scm_list_2 ($3, $1));
1597 // symbol_list_part delivers elements in reverse copy.
1602 $$ = try_string_variants (Lily::symbol_list_p, $1);
1603 if (SCM_UNBNDP ($$)) {
1604 parser->parser_error (@1, _("not a symbol"));
1607 $$ = scm_reverse ($$);
1612 symbol_list_element:
1618 function_arglist_nonbackup:
1619 function_arglist_common
1620 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1622 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1624 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1626 SCM n = scm_difference ($5, SCM_UNDEFINED);
1627 if (scm_is_true (scm_call_1 ($2, n)))
1628 $$ = scm_cons (n, $3);
1630 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1631 t->set_property ("digit", $5);
1632 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1636 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1638 $$ = check_scheme_arg (parser, @4,
1639 scm_difference ($5, SCM_UNDEFINED),
1642 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1644 $$ = check_scheme_arg (parser, @4,
1645 scm_difference ($5, SCM_UNDEFINED),
1648 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1650 if (scm_is_true (scm_call_1 ($2, $4)))
1651 $$ = scm_cons ($4, $3);
1653 $$ = check_scheme_arg (parser, @4,
1654 make_music_from_simple
1658 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1660 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1662 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1664 if (scm_is_true (scm_call_1 ($2, $3)))
1665 $$ = scm_cons ($3, $1);
1667 $$ = check_scheme_arg (parser, @3,
1668 make_music_from_simple
1672 | function_arglist_nonbackup_reparse REPARSE duration_length
1674 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1676 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1678 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1680 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1682 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1684 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1686 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1688 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1690 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1694 function_arglist_nonbackup_reparse:
1695 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1698 SCM res = try_string_variants ($2, $4);
1699 if (!SCM_UNBNDP (res))
1700 if (scm_is_pair (res))
1701 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1703 MYREPARSE (@4, $2, SCM_ARG, res);
1704 else if (scm_is_true
1706 ($2, make_music_from_simple
1708 MYREPARSE (@4, $2, STRING, $4);
1710 MYREPARSE (@4, $2, SCM_ARG, $4);
1712 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1717 ($2, make_music_from_simple
1719 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1721 MYREPARSE (@4, $2, SCM_ARG, $4);
1723 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1728 ($2, make_music_from_simple
1730 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1732 MYREPARSE (@4, $2, SCM_ARG, $4);
1734 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1737 SCM res = try_string_variants ($2, $4);
1738 if (!SCM_UNBNDP (res))
1739 if (scm_is_pair (res))
1740 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1742 MYREPARSE (@4, $2, SCM_ARG, res);
1743 else if (scm_is_true
1745 ($2, make_music_from_simple
1747 MYREPARSE (@4, $2, STRING, $4);
1749 MYREPARSE (@4, $2, SCM_ARG, $4);
1751 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1754 if (scm_is_true (scm_call_1 ($2, $4)))
1755 MYREPARSE (@4, $2, SCM_ARG, $4);
1756 else if (scm_is_true
1758 ($2, make_music_from_simple
1760 MYREPARSE (@4, $2, STRING, $4);
1762 MYREPARSE (@4, $2, SCM_ARG, $4);
1764 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1767 if (scm_is_true (scm_call_1 ($2, $4)))
1768 MYREPARSE (@4, $2, REAL, $4);
1770 SCM d = make_duration ($4);
1771 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1772 MYREPARSE (@4, $2, REAL, $4); // trigger error
1774 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1777 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1779 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1784 // function_arglist_backup can't occur at the end of an argument
1786 function_arglist_backup:
1787 function_arglist_common
1788 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1790 if (scm_is_true (scm_call_1 ($2, $4)))
1791 $$ = scm_cons ($4, $3);
1793 $$ = make_music_from_simple (parser, @4, $4);
1794 if (scm_is_true (scm_call_1 ($2, $$)))
1795 $$ = scm_cons ($$, $3);
1798 $$ = scm_cons (loc_on_music (@3, $1), $3);
1799 MYBACKUP (SCM_ARG, $4, @4);
1803 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1805 if (scm_is_true (scm_call_1 ($2, $4)))
1807 $$ = scm_cons ($4, $3);
1809 $$ = scm_cons (loc_on_music (@3, $1), $3);
1810 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1813 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1817 ($2, make_music_from_simple
1821 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1822 } else if (scm_is_true (scm_call_1 ($2, $4)))
1823 $$ = scm_cons ($4, $3);
1825 $$ = scm_cons (loc_on_music (@3, $1), $3);
1826 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1829 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1833 ($2, make_music_from_simple
1837 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1838 } else 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 (TONICNAME_PITCH, $4, @4);
1845 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1847 if (scm_is_true (scm_call_1 ($2, $4)))
1848 $$ = scm_cons ($4, $3);
1850 $$ = scm_cons (loc_on_music (@3, $1), $3);
1851 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1854 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1856 if (scm_is_true (scm_call_1 ($2, $4)))
1858 MYREPARSE (@4, $2, REAL, $4);
1861 SCM d = make_duration ($4);
1862 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1864 $$ = scm_cons (loc_on_music (@3, $1), $3);
1865 MYBACKUP (UNSIGNED, $4, @4);
1867 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1872 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1874 if (scm_is_true (scm_call_1 ($2, $4)))
1877 MYREPARSE (@4, $2, REAL, $4);
1879 $$ = scm_cons (loc_on_music (@3, $1), $3);
1880 MYBACKUP (REAL, $4, @4);
1883 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1885 if (scm_is_true (scm_call_1 ($2, $4)))
1887 $$ = scm_cons ($4, $3);
1889 $$ = scm_cons (loc_on_music (@3, $1), $3);
1890 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1893 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1895 SCM n = scm_difference ($5, SCM_UNDEFINED);
1896 if (scm_is_true (scm_call_1 ($2, n))) {
1898 MYREPARSE (@5, $2, REAL, n);
1900 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1901 t->set_property ("digit", $5);
1902 $$ = t->unprotect ();
1903 if (scm_is_true (scm_call_1 ($2, $$)))
1904 $$ = scm_cons ($$, $3);
1906 $$ = scm_cons (loc_on_music (@3, $1), $3);
1907 MYBACKUP (UNSIGNED, $5, @5);
1908 parser->lexer_->push_extra_token (@4, '-');
1912 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1914 SCM n = scm_difference ($5, SCM_UNDEFINED);
1915 if (scm_is_true (scm_call_1 ($2, n))) {
1916 MYREPARSE (@5, $2, REAL, n);
1919 $$ = scm_cons (loc_on_music (@3, $1), $3);
1920 MYBACKUP (REAL, n, @5);
1923 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1925 SCM n = scm_difference ($5, SCM_UNDEFINED);
1926 if (scm_is_true (scm_call_1 ($2, n))) {
1927 $$ = scm_cons (n, $3);
1929 $$ = scm_cons (loc_on_music (@3, $1), $3);
1930 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1933 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1935 if (scm_is_true (scm_call_1 ($2, $4)))
1937 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1940 $$ = scm_cons (loc_on_music (@3, $1), $3);
1941 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1944 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1946 SCM res = try_string_variants ($2, $4);
1947 if (!SCM_UNBNDP (res))
1948 if (scm_is_pair (res)) {
1950 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1953 $$ = scm_cons (res, $3);
1955 $$ = scm_cons (loc_on_music (@3, $1), $3);
1956 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1959 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1961 SCM res = try_string_variants ($2, $4);
1962 if (!SCM_UNBNDP (res))
1963 if (scm_is_pair (res)) {
1965 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1968 $$ = scm_cons (res, $3);
1970 $$ = scm_cons (loc_on_music (@3, $1), $3);
1971 MYBACKUP (STRING, $4, @4);
1974 | function_arglist_backup REPARSE pitch_or_music
1976 if (scm_is_true (scm_call_1 ($2, $3)))
1977 $$ = scm_cons ($3, $1);
1979 $$ = check_scheme_arg (parser, @3,
1980 make_music_from_simple
1984 | function_arglist_backup REPARSE bare_number_common
1986 $$ = check_scheme_arg (parser, @3,
1989 | function_arglist_backup REPARSE duration_length
1991 $$ = check_scheme_arg (parser, @3,
1994 | function_arglist_backup REPARSE symbol_list_arg
1996 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2001 function_arglist_nonbackup
2002 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2004 $$ = scm_cons (loc_on_music (@4, $1), $3);
2008 function_arglist_skip_nonbackup:
2009 function_arglist_nonbackup
2010 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
2012 $$ = scm_cons (loc_on_music (@3, $1), $3);
2016 function_arglist_common:
2017 EXPECT_NO_MORE_ARGS {
2020 | EXPECT_SCM function_arglist_optional embedded_scm_arg
2022 if (scm_is_true (scm_call_1 ($1, $3)))
2023 $$ = scm_cons ($3, $2);
2025 $$ = check_scheme_arg (parser, @3,
2026 make_music_from_simple
2030 | EXPECT_SCM function_arglist_optional bare_number_common
2032 $$ = check_scheme_arg (parser, @3,
2035 | EXPECT_SCM function_arglist_optional post_event_nofinger
2037 $$ = check_scheme_arg (parser, @3,
2040 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2042 SCM n = scm_difference ($4, SCM_UNDEFINED);
2043 $$ = check_scheme_arg (parser, @4, n, $2, $1);
2045 | function_arglist_common_reparse REPARSE SCM_ARG
2047 $$ = check_scheme_arg (parser, @3,
2050 | function_arglist_common_reparse REPARSE lyric_element_music
2052 $$ = check_scheme_arg (parser, @3,
2055 | function_arglist_common_reparse REPARSE pitch_or_music
2057 if (scm_is_true (scm_call_1 ($2, $3)))
2058 $$ = scm_cons ($3, $1);
2060 $$ = check_scheme_arg (parser, @3,
2061 make_music_from_simple
2065 | function_arglist_common_reparse REPARSE bare_number_common
2067 $$ = check_scheme_arg (parser, @3,
2070 | function_arglist_common_reparse REPARSE duration_length
2072 $$ = check_scheme_arg (parser, @3,
2075 | function_arglist_common_reparse REPARSE symbol_list_arg
2077 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2081 function_arglist_common_reparse:
2082 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2085 SCM res = try_string_variants ($1, $3);
2086 if (!SCM_UNBNDP (res))
2087 if (scm_is_pair (res))
2088 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2090 MYREPARSE (@3, $1, SCM_ARG, res);
2091 else if (scm_is_true
2093 ($1, make_music_from_simple (parser, @3, $3))))
2094 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2096 // This is going to flag a syntax error, we
2097 // know the predicate to be false.
2098 MYREPARSE (@3, $1, SCM_ARG, $3);
2100 | EXPECT_SCM function_arglist_optional pitch
2105 ($1, make_music_from_simple
2107 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2109 MYREPARSE (@3, $1, SCM_ARG, $3);
2111 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2116 ($1, make_music_from_simple
2118 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2120 MYREPARSE (@3, $1, SCM_ARG, $3);
2122 | EXPECT_SCM function_arglist_optional STRING
2125 SCM res = try_string_variants ($1, $3);
2126 if (!SCM_UNBNDP (res))
2127 if (scm_is_pair (res))
2128 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2130 MYREPARSE (@3, $1, SCM_ARG, res);
2131 else if (scm_is_true
2133 ($1, make_music_from_simple (parser, @3, $3))))
2134 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2136 // This is going to flag a syntax error, we
2137 // know the predicate to be false.
2138 MYREPARSE (@3, $1, SCM_ARG, $3);
2140 | EXPECT_SCM function_arglist_optional full_markup
2143 if (scm_is_true (scm_call_1 ($1, $3)))
2144 MYREPARSE (@3, $1, SCM_ARG, $3);
2145 else if (scm_is_true
2147 ($1, make_music_from_simple (parser, @3, $3))))
2148 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2150 // This is going to flag a syntax error, we
2151 // know the predicate to be false.
2152 MYREPARSE (@3, $1, SCM_ARG, $3);
2154 | EXPECT_SCM function_arglist_optional UNSIGNED
2157 if (scm_is_true (scm_call_1 ($1, $3)))
2158 MYREPARSE (@3, $1, REAL, $3);
2160 SCM d = make_duration ($3);
2161 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
2162 MYREPARSE (@3, $1, REAL, $3);
2164 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2167 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2170 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2172 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2175 SCM n = scm_difference ($4, SCM_UNDEFINED);
2176 if (scm_is_true (scm_call_1 ($1, n)))
2177 MYREPARSE (@4, $1, REAL, n);
2179 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2180 t->set_property ("digit", $4);
2181 SCM m = t->unprotect ();
2182 if (scm_is_true (scm_call_1 ($1, m)))
2183 MYREPARSE (@4, $1, SCM_ARG, m);
2185 MYREPARSE (@4, $1, SCM_ARG, $4);
2188 | EXPECT_SCM function_arglist_optional '-' REAL
2191 SCM n = scm_difference ($4, SCM_UNDEFINED);
2192 MYREPARSE (@4, $1, REAL, n);
2196 function_arglist_optional:
2197 function_arglist_backup
2198 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2200 $$ = scm_cons (loc_on_music (@4, $1), $3);
2202 | function_arglist_skip_backup BACKUP
2205 function_arglist_skip_backup:
2206 function_arglist_backup
2207 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2209 $$ = scm_cons (loc_on_music (@3, $1), $3);
2213 music_function_call:
2214 MUSIC_FUNCTION function_arglist {
2215 $$ = MAKE_SYNTAX (music_function, @$,
2222 /**/ { $$ = SCM_EOL; }
2223 | '=' simple_string {
2228 // We must not have lookahead tokens parsed in lyric mode. In order
2229 // to save confusion, we take almost the same set as permitted with
2230 // \lyricmode and/or \lyrics. However, music identifiers are also
2231 // allowed, and they obviously do not require switching into lyrics
2232 // mode for parsing.
2236 parser->lexer_->push_lyric_state ();
2237 } grouped_music_list
2239 parser->lexer_->pop_state ();
2246 mode_changing_head grouped_music_list {
2247 if (scm_is_eq ($1, ly_symbol2scm ("chords")))
2249 $$ = MAKE_SYNTAX (unrelativable_music, @$, $2);
2255 parser->lexer_->pop_state ();
2257 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2258 Context_mod *ctxmod = unsmob<Context_mod> ($2);
2261 mods = ctxmod->get_mods ();
2262 $$ = MAKE_SYNTAX (context_specification, @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2263 if (scm_is_eq ($1, ly_symbol2scm ("ChordNames")))
2265 $$ = MAKE_SYNTAX (unrelativable_music, @$, $$);
2267 parser->lexer_->pop_state ();
2273 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2274 parser->lexer_->push_note_state (nn);
2276 $$ = ly_symbol2scm ("notes");
2280 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2281 parser->lexer_->push_note_state (nn);
2283 $$ = ly_symbol2scm ("drums");
2286 parser->lexer_->push_figuredbass_state ();
2288 $$ = ly_symbol2scm ("figures");
2291 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2292 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2293 nn = parser->lexer_->lookup_identifier ("pitchnames");
2294 parser->lexer_->push_chord_state (nn);
2295 $$ = ly_symbol2scm ("chords");
2299 { parser->lexer_->push_lyric_state ();
2300 $$ = ly_symbol2scm ("lyrics");
2304 mode_changing_head_with_context:
2306 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2307 parser->lexer_->push_note_state (nn);
2309 $$ = ly_symbol2scm ("DrumStaff");
2312 parser->lexer_->push_figuredbass_state ();
2314 $$ = ly_symbol2scm ("FiguredBass");
2317 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2318 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2319 nn = parser->lexer_->lookup_identifier ("pitchnames");
2320 parser->lexer_->push_chord_state (nn);
2321 $$ = ly_symbol2scm ("ChordNames");
2324 { parser->lexer_->push_lyric_state ();
2325 $$ = ly_symbol2scm ("Lyrics");
2330 CHANGE symbol '=' simple_string {
2331 $$ = MAKE_SYNTAX (context_change, @$, $2, $4);
2338 $$ = scm_reverse_x ($1, SCM_EOL);
2340 | symbol_list_rev property_path {
2341 $$ = scm_reverse_x ($1, $2);
2347 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2350 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2352 | OVERRIDE property_path '=' scalar {
2353 if (scm_ilength ($2) < 2) {
2354 parser->parser_error (@2, _("bad grob property path"));
2357 $$ = scm_cons (ly_symbol2scm ("push"),
2358 scm_cons2 (scm_car ($2),
2363 | REVERT revert_arg {
2364 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2368 // This is all quite awkward for the sake of substantial backward
2369 // compatibility while at the same time allowing a more "natural" form
2370 // of specification not separating grob specification from grob
2371 // property path. The purpose of this definition of revert_arg is to
2372 // allow the symbol list which specifies grob and property to revert
2373 // to be optionally be split into two parts after the grob (which in
2374 // this case is just the first element of the list). symbol_list_part
2375 // is only one path component, but it can be parsed without lookahead,
2376 // so we can follow it with a synthetic BACKUP token when needed. If
2377 // the first symbol_list_part already contains multiple elements (only
2378 // possible if a Scheme expression provides them), we just parse for
2379 // additional elements introduced by '.', which is what the
2380 // SYMBOL_LIST backup in connection with the immediately following
2381 // rule using symbol_list_arg does.
2383 // As long as we don't have our coffers filled with both grob and at
2384 // least one grob property specification, the rest of the required
2385 // symbol list chain may be provided either with or without a leading
2386 // dot. This is for both allowing the traditional
2387 // \revert Accidental #'color
2388 // as well as well as the "naive" form
2389 // \revert Accidental.color
2392 revert_arg_backup BACKUP symbol_list_arg
2401 if (scm_is_null ($1)
2402 || scm_is_null (scm_cdr ($1)))
2403 MYBACKUP (SCM_ARG, $1, @1);
2405 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2409 // revert_arg_part delivers results in reverse
2412 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2414 $$ = scm_append_x (scm_list_2 ($5, $3));
2416 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2418 $$ = scm_append_x (scm_list_2 ($4, $3));
2423 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2424 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2426 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2427 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2428 | DENIES { $$ = ly_symbol2scm ("denies"); }
2430 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2431 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2432 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2433 | NAME { $$ = ly_symbol2scm ("context-name"); }
2437 property_operation { $$ = $1; }
2438 | context_def_mod STRING {
2439 $$ = scm_list_2 ($1, $2);
2441 | context_def_mod embedded_scm
2443 if (!scm_is_string ($2)
2444 && ly_symbol2scm ("consists") != $1
2445 && ly_symbol2scm ("remove") != $1)
2448 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2452 $$ = scm_list_2 ($1, $2);
2457 // If defined, at least two members.
2461 SCM l = scm_reverse_x ($1, SCM_EOL);
2464 (scm_object_property (scm_car (l),
2465 ly_symbol2scm ("is-grob?"))))
2466 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2467 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2468 parser->parser_error (@1, _ ("bad grob property path"));
2475 // If defined, at least three members
2479 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2481 parser->parser_error (@1, _ ("bad grob property path"));
2485 | grob_prop_spec property_path
2487 if (!SCM_UNBNDP ($1)) {
2488 $$ = scm_append_x (scm_list_2 ($1, $2));
2489 if (scm_is_null (scm_cddr ($$))) {
2490 parser->parser_error (@$, _ ("bad grob property path"));
2498 // Exactly two elements or undefined
2502 SCM l = scm_reverse_x ($1, SCM_EOL);
2503 switch (scm_ilength (l)) {
2505 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2509 parser->parser_error (@1, _ ("bad context property path"));
2517 // This is all quite awkward for the sake of substantial backward
2518 // compatibility while at the same time allowing a more "natural" form
2519 // of specification not separating grob specification from grob
2520 // property path. The purpose of this definition of
2521 // simple_revert_context is to allow the symbol list which specifies
2522 // grob and property to revert to be optionally be split into two
2523 // parts after the grob (which may be preceded by a context
2524 // specification, a case which we distinguish by checking whether the
2525 // first symbol is a valid grob symbol instead).
2527 // See revert_arg above for the main work horse of this arrangement.
2528 // simple_revert_context just caters for the context and delegates the
2529 // rest of the job to revert_arg.
2531 simple_revert_context:
2534 $1 = scm_reverse_x ($1, SCM_EOL);
2535 if (scm_is_null ($1)
2537 (scm_object_property (scm_car ($1),
2538 ly_symbol2scm ("is-grob?")))) {
2539 $$ = ly_symbol2scm ("Bottom");
2540 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2543 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2550 OVERRIDE grob_prop_path '=' scalar {
2551 if (SCM_UNBNDP ($2))
2552 $$ = MAKE_SYNTAX (void_music, @$);
2554 $$ = MAKE_SYNTAX (property_operation, @$,
2556 ly_symbol2scm ("OverrideProperty"),
2562 | REVERT simple_revert_context revert_arg {
2563 $$ = MAKE_SYNTAX (property_operation, @$,
2565 ly_symbol2scm ("RevertProperty"),
2569 | SET context_prop_spec '=' scalar {
2570 if (SCM_UNBNDP ($2))
2571 $$ = MAKE_SYNTAX (void_music, @$);
2573 $$ = MAKE_SYNTAX (property_operation, @$,
2575 ly_symbol2scm ("PropertySet"),
2579 | UNSET context_prop_spec {
2580 if (SCM_UNBNDP ($2))
2581 $$ = MAKE_SYNTAX (void_music, @$);
2583 $$ = MAKE_SYNTAX (property_operation, @$,
2585 ly_symbol2scm ("PropertyUnset"),
2597 simple_string: STRING {
2602 if (scm_is_string ($1)) {
2605 parser->parser_error (@1, (_ ("simple string expected")));
2606 $$ = scm_string (SCM_EOL);
2613 $$ = scm_string_to_symbol ($1);
2617 // This is a bit of overkill but makes the same
2618 // routine responsible for all symbol interpretations.
2619 $$ = try_string_variants (Guile_user::symbol_p, $1);
2620 if (SCM_UNBNDP ($$))
2622 parser->parser_error (@1, (_ ("symbol expected")));
2623 // Generate a unique symbol in case it is used
2624 // for an assignment or similar
2625 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2635 // The following is a rather defensive variant of admitting
2636 // negative numbers: the grammar would permit number_factor or
2637 // even number_expression. However, function arguments allow
2638 // only this simple kind of negative number, so to have things
2639 // like \tweak and \override behave reasonably similar, it
2640 // makes sense to rule out things like -- which are rather an
2641 // accent in function argument contexts.
2644 $$ = scm_difference ($2, SCM_UNDEFINED);
2650 simple_element post_events {
2651 // Let the rhythmic music iterator sort this mess out.
2652 if (scm_is_pair ($2)) {
2653 unsmob<Music> ($$)->set_property ("articulations",
2654 scm_reverse_x ($2, SCM_EOL));
2657 | CHORD_REPETITION optional_notemode_duration post_events {
2659 i.set_location (@1, @3);
2660 $$ = MAKE_SYNTAX (repetition_chord, i,
2661 $2, scm_reverse_x ($3, SCM_EOL));
2663 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2665 i.set_location (@1, @3);
2666 $$ = MAKE_SYNTAX (multi_measure_rest, i, $2,
2667 scm_reverse_x ($3, SCM_EOL));
2670 | note_chord_element
2675 chord_body optional_notemode_duration post_events
2677 Music *m = unsmob<Music> ($1);
2678 SCM dur = unsmob<Duration> ($2)->smobbed_copy ();
2679 SCM es = m->get_property ("elements");
2680 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2682 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2683 unsmob<Music> (scm_car (s))->set_property ("duration", dur);
2684 es = ly_append2 (es, postevs);
2686 m-> set_property ("elements", es);
2688 $$ = m->self_scm ();
2693 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2695 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2697 | FIGURE_OPEN figure_list FIGURE_CLOSE
2699 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2703 chord_body_elements:
2704 /* empty */ { $$ = SCM_EOL; }
2705 | chord_body_elements chord_body_element {
2706 if (!SCM_UNBNDP ($2))
2707 $$ = scm_cons ($2, $1);
2712 pitch_or_tonic_pitch exclamations questions octave_check post_events
2714 bool q = to_boolean ($3);
2715 bool ex = to_boolean ($2);
2719 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2720 n->set_property ("pitch", $1);
2722 n->set_property ("cautionary", SCM_BOOL_T);
2724 n->set_property ("force-accidental", SCM_BOOL_T);
2726 if (scm_is_pair (post)) {
2727 SCM arts = scm_reverse_x (post, SCM_EOL);
2728 n->set_property ("articulations", arts);
2730 if (scm_is_number (check))
2732 int q = scm_to_int (check);
2733 n->set_property ("absolute-octave", scm_from_int (q-1));
2736 $$ = n->unprotect ();
2738 | DRUM_PITCH post_events {
2739 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2740 n->set_property ("drum-type", $1);
2742 if (scm_is_pair ($2)) {
2743 SCM arts = scm_reverse_x ($2, SCM_EOL);
2744 n->set_property ("articulations", arts);
2746 $$ = n->unprotect ();
2748 | music_function_chord_body
2750 Music *m = unsmob<Music> ($1);
2752 while (m && m->is_mus_type ("music-wrapper-music")) {
2753 $$ = m->get_property ("element");
2754 m = unsmob<Music> ($$);
2757 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2758 parser->parser_error (@$, _ ("not a rhythmic event"));
2764 music_function_chord_body:
2770 event_function_event:
2771 EVENT_FUNCTION function_arglist {
2772 $$ = MAKE_SYNTAX (music_function, @$,
2781 | post_events post_event {
2783 if (Music *m = unsmob<Music> ($2))
2785 if (m->is_mus_type ("post-event-wrapper"))
2787 for (SCM p = m->get_property ("elements");
2791 $$ = scm_cons (scm_car (p), $$);
2795 $$ = scm_cons ($2, $$);
2801 post_event_nofinger:
2802 direction_less_event {
2805 | script_dir music_function_call {
2807 if (!unsmob<Music> ($2)->is_mus_type ("post-event")) {
2808 parser->parser_error (@2, _ ("post-event expected"));
2809 $$ = SCM_UNSPECIFIED;
2810 } else if (!SCM_UNBNDP ($1))
2812 unsmob<Music> ($$)->set_property ("direction", $1);
2816 if (!parser->lexer_->is_lyric_state ())
2817 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2818 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2821 if (!parser->lexer_->is_lyric_state ())
2822 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2823 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2825 | script_dir direction_reqd_event {
2826 if (!SCM_UNBNDP ($1))
2828 Music *m = unsmob<Music> ($2);
2829 m->set_property ("direction", $1);
2833 | script_dir direction_less_event {
2834 if (!SCM_UNBNDP ($1))
2836 Music *m = unsmob<Music> ($2);
2837 m->set_property ("direction", $1);
2844 unsmob<Music> ($$)->set_property ("direction", scm_from_int (UP));
2849 unsmob<Music> ($$)->set_property ("direction", scm_from_int (DOWN));
2860 string_number_event:
2862 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2863 s->set_property ("string-number", $1);
2864 $$ = s->unprotect ();
2868 direction_less_event:
2870 | EVENT_IDENTIFIER {
2874 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2875 a->set_property ("tremolo-type", $1);
2876 $$ = a->unprotect ();
2878 | event_function_event
2881 direction_reqd_event:
2885 | script_abbreviation {
2886 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2887 if (scm_is_string (s)) {
2888 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2889 a->set_property ("articulation-type", s);
2890 $$ = a->unprotect ();
2892 Music *original = unsmob<Music> (s);
2893 if (original && original->is_mus_type ("post-event")) {
2894 Music *a = original->clone ();
2895 a->set_spot (parser->lexer_->override_input (@$));
2896 $$ = a->unprotect ();
2898 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2899 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2906 /**/ { $$ = SCM_EOL; }
2907 | '=' quotes { $$ = $2; }
2921 $$ = scm_from_int (1);
2924 $$ = scm_oneplus ($1);
2930 $$ = scm_from_int (-1);
2933 $$ = scm_oneminus ($1);
2938 NOTENAME_PITCH quotes {
2939 if (!scm_is_eq (SCM_INUM0, $2))
2941 Pitch p = *unsmob<Pitch> ($1);
2942 p = p.transposed (Pitch (scm_to_int ($2), 0));
2943 $$ = p.smobbed_copy ();
2953 TONICNAME_PITCH quotes {
2954 if (!scm_is_eq (SCM_INUM0, $2))
2956 Pitch p = *unsmob<Pitch> ($1);
2957 p = p.transposed (Pitch (scm_to_int ($2), 0));
2958 $$ = p.smobbed_copy ();
2965 | PITCH_IDENTIFIER quotes {
2966 if (!scm_is_eq (SCM_INUM0, $2))
2968 Pitch p = *unsmob<Pitch> ($1);
2969 p = p.transposed (Pitch (scm_to_int ($2), 0));
2970 $$ = p.smobbed_copy ();
2975 pitch_or_tonic_pitch:
2982 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2983 t->set_property ("text", $1);
2984 $$ = t->unprotect ();
2987 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2988 t->set_property ("text",
2989 make_simple_markup ($1));
2990 $$ = t->unprotect ();
2994 Music *m = unsmob<Music> ($1);
2995 if (m && m->is_mus_type ("post-event"))
2997 else if (Text_interface::is_markup ($1)) {
2998 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2999 t->set_property ("text", $1);
3000 $$ = t->unprotect ();
3002 parser->parser_error (@1, _ ("not an articulation"));
3008 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3009 t->set_property ("digit", $1);
3010 $$ = t->unprotect ();
3014 script_abbreviation:
3016 $$ = scm_from_ascii_string ("Hat");
3019 $$ = scm_from_ascii_string ("Plus");
3022 $$ = scm_from_ascii_string ("Dash");
3025 $$ = scm_from_ascii_string ("Bang");
3028 $$ = scm_from_ascii_string ("Larger");
3031 $$ = scm_from_ascii_string ("Dot");
3034 $$ = scm_from_ascii_string ("Underscore");
3039 '_' { $$ = scm_from_int (DOWN); }
3040 | '^' { $$ = scm_from_int (UP); }
3041 | '-' { $$ = SCM_UNDEFINED; }
3045 multiplied_duration {
3050 maybe_notemode_duration:
3054 | multiplied_duration {
3056 parser->default_duration_ = *unsmob<Duration> ($$);
3061 optional_notemode_duration:
3062 maybe_notemode_duration
3064 if (SCM_UNBNDP ($$))
3065 $$ = parser->default_duration_.smobbed_copy ();
3071 $$ = make_duration ($1, scm_to_int ($2));
3072 if (SCM_UNBNDP ($$))
3074 parser->parser_error (@1, _ ("not a duration"));
3075 $$ = Duration ().smobbed_copy ();
3078 | DURATION_IDENTIFIER dots {
3079 Duration *d = unsmob<Duration> ($1);
3080 Duration k (d->duration_log (),
3081 d->dot_count () + scm_to_int ($2));
3082 k = k.compressed (d->factor ());
3083 scm_remember_upto_here_1 ($1);
3084 $$ = k.smobbed_copy ();
3088 multiplied_duration:
3092 | multiplied_duration '*' UNSIGNED {
3093 $$ = unsmob<Duration> ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
3095 | multiplied_duration '*' FRACTION {
3096 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
3098 $$ = unsmob<Duration> ($$)->compressed (m).smobbed_copy ();
3107 $$ = scm_oneplus ($1);
3113 $$ = scm_from_int (parser->default_tremolo_type_);
3116 if (SCM_UNBNDP (make_duration ($2))) {
3117 parser->parser_error (@2, _ ("not a duration"));
3118 $$ = scm_from_int (parser->default_tremolo_type_);
3121 parser->default_tremolo_type_ = scm_to_int ($2);
3127 UNSIGNED { $$ = $1; }
3128 | STRING { $$ = $1; }
3129 | full_markup { $$ = $1; }
3132 // as an integer, it needs to be non-negative, and otherwise
3133 // it needs to be suitable as a markup.
3134 if (scm_is_integer ($1)
3135 ? scm_is_true (scm_negative_p ($1))
3136 : !Text_interface::is_markup ($1))
3138 parser->parser_error (@1, _ ("bass number expected"));
3144 figured_bass_alteration:
3145 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3146 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3147 | '!' { $$ = scm_from_int (0); }
3152 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3153 $$ = bfr->unprotect ();
3156 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3157 $$ = bfr->self_scm ();
3159 if (scm_is_number ($1))
3160 bfr->set_property ("figure", $1);
3161 else if (Text_interface::is_markup ($1))
3162 bfr->set_property ("text", $1);
3168 unsmob<Music> ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3170 | bass_figure figured_bass_alteration {
3171 Music *m = unsmob<Music> ($1);
3172 if (scm_to_double ($2)) {
3173 SCM salter = m->get_property ("alteration");
3174 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3175 m->set_property ("alteration",
3176 scm_sum (alter, $2));
3178 m->set_property ("alteration", scm_from_int (0));
3181 | bass_figure figured_bass_modification {
3182 Music *m = unsmob<Music> ($1);
3183 m->set_property ($2, SCM_BOOL_T);
3188 figured_bass_modification:
3190 $$ = ly_symbol2scm ("augmented");
3193 $$ = ly_symbol2scm ("no-continuation");
3196 $$ = ly_symbol2scm ("diminished");
3199 $$ = ly_symbol2scm ("augmented-slash");
3209 unsmob<Music> ($$)->set_property ("bracket-start", SCM_BOOL_T);
3217 | figure_list br_bass_figure {
3218 $$ = scm_cons ($2, $1);
3223 /**/ { $$ = SCM_BOOL_F; }
3224 | REST { $$ = SCM_BOOL_T; }
3228 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3229 if (!parser->lexer_->is_note_state ())
3230 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3231 if (!SCM_UNBNDP ($2)
3233 || scm_is_number ($4)
3236 || scm_is_pair ($7))
3239 if (scm_is_true ($6))
3240 n = MY_MAKE_MUSIC ("RestEvent", @$);
3242 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3244 n->set_property ("pitch", $1);
3245 if (SCM_UNBNDP ($5))
3246 n->set_property ("duration",
3247 parser->default_duration_.smobbed_copy ());
3249 n->set_property ("duration", $5);
3251 if (scm_is_number ($4))
3253 int q = scm_to_int ($4);
3254 n->set_property ("absolute-octave", scm_from_int (q-1));
3257 if (to_boolean ($3))
3258 n->set_property ("cautionary", SCM_BOOL_T);
3259 if (to_boolean ($2) || to_boolean ($3))
3260 n->set_property ("force-accidental", SCM_BOOL_T);
3261 if (scm_is_pair ($7))
3262 n->set_property ("articulations",
3263 scm_reverse_x ($7, SCM_EOL));
3264 $$ = n->unprotect ();
3267 | new_chord post_events {
3268 if (!parser->lexer_->is_chord_state ())
3269 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3270 if (scm_is_pair ($2)) {
3271 if (unsmob<Pitch> ($1))
3272 $1 = make_chord_elements (@1,
3274 parser->default_duration_.smobbed_copy (),
3277 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3279 $$ = MAKE_SYNTAX (event_chord, @1, elts);
3280 } else if (!unsmob<Pitch> ($1))
3281 $$ = MAKE_SYNTAX (event_chord, @1, $1);
3282 // A mere pitch drops through.
3287 DRUM_PITCH optional_notemode_duration {
3288 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3289 n->set_property ("duration", $2);
3290 n->set_property ("drum-type", $1);
3292 $$ = n->unprotect ();
3294 | RESTNAME optional_notemode_duration {
3296 if (ly_scm2string ($1) == "s") {
3298 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3301 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3304 ev->set_property ("duration", $2);
3305 $$ = ev->unprotect ();
3311 if (!parser->lexer_->is_lyric_state ())
3312 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3316 if (!parser->lexer_->is_lyric_state ())
3317 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3323 lyric_element_music:
3324 lyric_element optional_notemode_duration post_events {
3325 $$ = MAKE_SYNTAX (lyric_event, @$, $1, $2);
3326 if (scm_is_pair ($3))
3327 unsmob<Music> ($$)->set_property
3328 ("articulations", scm_reverse_x ($3, SCM_EOL));
3332 // Can return a single pitch rather than a list.
3334 steno_tonic_pitch maybe_notemode_duration {
3335 if (SCM_UNBNDP ($2))
3338 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3340 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3341 SCM its = scm_reverse_x ($4, SCM_EOL);
3342 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3350 | chord_items chord_item {
3351 $$ = scm_cons ($2, $$);
3357 $$ = ly_symbol2scm ("chord-colon");
3360 $$ = ly_symbol2scm ("chord-caret");
3362 | CHORD_SLASH steno_tonic_pitch {
3363 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3365 | CHORD_BASS steno_tonic_pitch {
3366 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3375 $$ = scm_reverse_x ($1, SCM_EOL);
3383 step_number { $$ = scm_cons ($1, SCM_EOL); }
3384 | step_numbers '.' step_number {
3385 $$ = scm_cons ($3, $$);
3391 $$ = make_chord_step ($1, 0);
3394 $$ = make_chord_step ($1, SHARP_ALTERATION);
3396 | UNSIGNED CHORD_MINUS {
3397 $$ = make_chord_step ($1, FLAT_ALTERATION);
3405 | unsigned_number '-' unsigned_number {
3406 $$ = scm_cons ($1, $3);
3413 TODO: should deprecate in favor of Scheme?
3417 number_expression '+' number_term {
3418 $$ = scm_sum ($1, $3);
3420 | number_expression '-' number_term {
3421 $$ = scm_difference ($1, $3);
3430 | number_factor '*' number_factor {
3431 $$ = scm_product ($1, $3);
3433 | number_factor '/' number_factor {
3434 $$ = scm_divide ($1, $3);
3439 '-' number_factor { /* %prec UNARY_MINUS */
3440 $$ = scm_difference ($2, SCM_UNDEFINED);
3448 | REAL NUMBER_IDENTIFIER
3450 $$ = scm_product ($1, $2);
3457 | UNSIGNED NUMBER_IDENTIFIER {
3458 $$ = scm_product ($1, $2);
3466 if (!scm_is_integer ($1)
3467 || scm_is_true (scm_negative_p ($1)))
3469 parser->parser_error (@1, _("not an unsigned integer"));
3475 if (!scm_is_integer ($1)
3476 || scm_is_true (scm_negative_p ($1)))
3478 parser->parser_error (@1, _("not an unsigned integer"));
3485 { $$ = SCM_UNDEFINED; }
3488 if (SCM_UNBNDP ($1))
3496 // This precedence rule is rather weird. It triggers when '!' is
3497 // encountered after a pitch, and is used for deciding whether to save
3498 // this instead for a figure modification. This should not actually
3499 // occur in practice as pitches and figures are generated in different
3500 // modes. Using a greedy (%right) precedence makes sure that we don't
3501 // get stuck in a wrong interpretation.
3502 { $$ = SCM_UNDEFINED; } %prec ':'
3505 if (SCM_UNBNDP ($1))
3514 { parser->lexer_->push_markup_state (); }
3517 parser->lexer_->pop_state ();
3523 { parser->lexer_->push_markup_state (); }
3526 parser->lexer_->pop_state ();
3532 $$ = scm_list_2 (Lily::line_markup, $1);
3534 | markup_head_1_list simple_markup
3536 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3537 @2, $1, scm_list_1 ($2)));
3547 if (Text_interface::is_markup ($1))
3548 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3549 else if (Text_interface::is_markup_list ($1))
3550 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3552 parser->parser_error (@1, _ ("not a markup"));
3553 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3560 markup_composed_list {
3563 | markup_uncomposed_list
3566 markup_uncomposed_list:
3567 markup_braced_list {
3570 | markup_command_list {
3571 $$ = scm_list_1 ($1);
3573 | markup_scm MARKUPLIST_IDENTIFIER
3578 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3579 parser->lexer_->push_note_state (nn);
3580 } '{' score_body '}' {
3581 Score *sc = unsmob<Score> ($4);
3582 sc->origin ()->set_spot (@$);
3583 if (sc->defs_.empty ()) {
3584 Output_def *od = get_layout (parser);
3585 sc->add_output_def (od);
3588 $$ = scm_list_1 (scm_list_2 (Lily::score_lines_markup_list, $4));
3589 parser->lexer_->pop_state ();
3593 markup_composed_list:
3594 markup_head_1_list markup_uncomposed_list {
3595 $$ = MAKE_SYNTAX (composed_markup_list,
3601 '{' markup_braced_list_body '}' {
3602 $$ = scm_reverse_x ($2, SCM_EOL);
3606 markup_braced_list_body:
3607 /* empty */ { $$ = SCM_EOL; }
3608 | markup_braced_list_body markup {
3609 $$ = scm_cons ($2, $1);
3611 | markup_braced_list_body markup_list {
3612 $$ = scm_reverse_x ($2, $1);
3616 markup_command_list:
3617 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3618 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3622 markup_command_basic_arguments:
3623 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3624 $$ = scm_cons ($3, $2);
3626 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3627 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3629 | EXPECT_NO_MORE_ARGS {
3634 markup_command_list_arguments:
3635 markup_command_basic_arguments { $$ = $1; }
3636 | EXPECT_MARKUP markup_command_list_arguments markup {
3637 $$ = scm_cons ($3, $2);
3642 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3643 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3648 markup_head_1_item {
3649 $$ = scm_list_1 ($1);
3651 | markup_head_1_list markup_head_1_item {
3652 $$ = scm_cons ($2, $1);
3658 $$ = make_simple_markup ($1);
3661 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3662 parser->lexer_->push_note_state (nn);
3663 } '{' score_body '}' {
3664 Score *sc = unsmob<Score> ($4);
3665 sc->origin ()->set_spot (@$);
3666 if (sc->defs_.empty ()) {
3667 Output_def *od = get_layout (parser);
3668 sc->add_output_def (od);
3671 $$ = scm_list_2 (Lily::score_markup, $4);
3672 parser->lexer_->pop_state ();
3674 | MARKUP_FUNCTION markup_command_basic_arguments {
3675 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3677 | markup_scm MARKUP_IDENTIFIER
3684 markup_head_1_list simple_markup
3686 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3687 @2, $1, scm_list_1 ($2)));
3697 Lily_parser::set_yydebug (bool x)
3703 Lily_parser::do_yyparse ()
3705 return scm_c_with_fluid (Lily::f_parser,
3707 do_yyparse_trampoline,
3708 static_cast <void *>(this));
3712 Lily_parser::do_yyparse_trampoline (void *parser)
3714 SCM retval = SCM_UNDEFINED;
3715 yyparse (static_cast <Lily_parser *>(parser), &retval);
3723 It is a little strange to have this function in this file, but
3724 otherwise, we have to import music classes into the lexer.
3728 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3730 if (unsmob<Book> (sid)) {
3731 Book *book = unsmob<Book> (sid)->clone ();
3732 *destination = book->self_scm ();
3735 return BOOK_IDENTIFIER;
3736 } else if (scm_is_number (sid)) {
3738 return NUMBER_IDENTIFIER;
3739 } else if (unsmob<Context_def> (sid))
3741 *destination = unsmob<Context_def> (sid)->clone ()->unprotect ();
3742 return SCM_IDENTIFIER;
3743 } else if (unsmob<Context_mod> (sid)) {
3744 *destination = unsmob<Context_mod> (sid)->smobbed_copy ();
3745 return CONTEXT_MOD_IDENTIFIER;
3746 } else if (Music *mus = unsmob<Music> (sid)) {
3747 mus = mus->clone ();
3748 *destination = mus->self_scm ();
3749 bool is_event = mus->is_mus_type ("post-event");
3751 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3752 } else if (unsmob<Pitch> (sid)) {
3753 *destination = unsmob<Pitch> (sid)->smobbed_copy ();
3754 return PITCH_IDENTIFIER;
3755 } else if (unsmob<Duration> (sid)) {
3756 *destination = unsmob<Duration> (sid)->smobbed_copy ();
3757 return DURATION_IDENTIFIER;
3758 } else if (unsmob<Output_def> (sid)) {
3759 *destination = unsmob<Output_def> (sid)->clone ()->unprotect ();
3760 return SCM_IDENTIFIER;
3761 } else if (unsmob<Score> (sid)) {
3762 *destination = unsmob<Score> (sid)->clone ()->unprotect ();
3763 return SCM_IDENTIFIER;
3770 get_next_unique_context_id ()
3772 return scm_from_ascii_string ("$uniqueContextId");
3777 get_next_unique_lyrics_context_id ()
3779 static int new_context_count;
3781 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3782 return scm_from_ascii_string (s);
3785 // check_scheme_arg checks one argument with a given predicate for use
3786 // in an argument list and throws a syntax error if it is unusable.
3787 // The argument is prepended to the argument list in any case. After
3788 // throwing a syntax error, the argument list is terminated with #f as
3789 // its last cdr in order to mark it as uncallable while not losing
3790 // track of its total length.
3792 // There are a few special considerations: if optional argument disp
3793 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3794 // instead of arg in a prospective error message. This is useful if
3795 // arg is not the actual argument but rather a transformation of it.
3797 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3798 // and an error message using disp is produced unconditionally.
3800 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3801 SCM arg, SCM args, SCM pred, SCM disp)
3803 if (SCM_UNBNDP (arg))
3804 args = scm_cons (disp, args);
3806 args = scm_cons (arg, args);
3807 if (scm_is_true (scm_call_1 (pred, arg)))
3810 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3811 MAKE_SYNTAX (argument_error, loc, scm_length (args), pred,
3812 SCM_UNBNDP (disp) ? arg : disp);
3813 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3817 SCM loc_on_music (Input loc, SCM arg)
3819 if (Music *m = unsmob<Music> (arg))
3823 return m->unprotect ();
3829 try_string_variants (SCM pred, SCM str)
3831 // a matching predicate is always ok
3832 if (scm_is_true (scm_call_1 (pred, str)))
3834 // a symbol may be interpreted as a list of symbols if it helps
3835 if (scm_is_symbol (str)) {
3836 str = scm_list_1 (str);
3837 if (scm_is_true (scm_call_1 (pred, str)))
3839 return SCM_UNDEFINED;
3842 // If this cannot be a string representation of a symbol list,
3845 if (!is_regular_identifier (str, true))
3846 return SCM_UNDEFINED;
3848 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3849 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3850 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3852 // Let's attempt the symbol list interpretation first.
3854 if (scm_is_true (scm_call_1 (pred, str)))
3857 // If there is just one symbol in the list, we might interpret
3858 // it as a single symbol
3860 if (scm_is_null (scm_cdr (str)))
3862 str = scm_car (str);
3863 if (scm_is_true (scm_call_1 (pred, str)))
3867 return SCM_UNDEFINED;
3871 is_regular_identifier (SCM id, bool multiple)
3873 if (!scm_is_string (id))
3876 string str = ly_scm2string (id);
3878 bool middle = false;
3880 for (string::iterator it=str.begin(); it != str.end (); it++)
3883 if ((c >= 'a' && c <= 'z')
3884 || (c >= 'A' && c <= 'Z')
3887 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3896 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3898 if (unsmob<Music> (simple))
3900 if (parser->lexer_->is_note_state ()) {
3901 if (scm_is_symbol (simple)) {
3902 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3903 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3904 n->set_property ("drum-type", simple);
3905 return n->unprotect ();
3907 if (unsmob<Pitch> (simple)) {
3908 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3909 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3910 n->set_property ("pitch", simple);
3911 return n->unprotect ();
3914 } else if (parser->lexer_->is_lyric_state ()) {
3915 if (Text_interface::is_markup (simple))
3916 return MAKE_SYNTAX (lyric_event, loc, simple,
3917 parser->default_duration_.smobbed_copy ());
3918 } else if (parser->lexer_->is_chord_state ()) {
3919 if (unsmob<Pitch> (simple))
3923 make_chord_elements (loc, simple,
3924 parser->default_duration_.smobbed_copy (),
3931 make_music_with_input (SCM name, Input where)
3933 Music *m = make_music_by_name (name);
3934 m->set_spot (where);
3939 make_simple_markup (SCM a)
3945 make_duration (SCM d, int dots)
3947 int t = scm_to_int (d);
3948 if (t > 0 && (t & (t-1)) == 0)
3949 return Duration (intlog2 (t), dots).smobbed_copy ();
3951 return SCM_UNDEFINED;
3955 make_chord_step (SCM step_scm, Rational alter)
3957 int step = scm_to_int (step_scm);
3960 alter += FLAT_ALTERATION;
3964 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3965 return m.smobbed_copy ();
3970 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3972 SCM res = Lily::construct_chord_elements (pitch, dur, modification_list);
3973 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3975 unsmob<Music> (scm_car (s))->set_spot (loc);
3981 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3983 Lily_lexer *lex = parser->lexer_;
3987 int tok = lex->pop_extra_token ();
3990 lex->prepare_for_next_token ();
3991 return lex->yylex ();