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 = scm_call_1 (ly_lily_module_constant ("value->lily-string"), \
46 char *p = scm_to_locale_string (s); \
53 %parse-param {Lily_parser *parser}
54 %parse-param {SCM *retval}
55 %lex-param {Lily_parser *parser}
59 /* We use SCMs to do strings, because it saves us the trouble of
60 deleting them. Let's hope that a stack overflow doesn't trigger a move
61 of the parse stack onto the heap. */
67 /* The above precedences tackle the shift/reduce problem
70 \repeat .. \alternative
72 \repeat { \repeat .. \alternative }
76 \repeat { \repeat } \alternative
82 %right ':' UNSIGNED REAL E_UNSIGNED EVENT_IDENTIFIER EVENT_FUNCTION '^' '_'
83 HYPHEN EXTENDER DURATION_IDENTIFIER '!'
85 /* The above are needed for collecting tremoli and other items (that
86 could otherwise be interpreted as belonging to the next function
87 argument) greedily, and together with the next rule will serve to
88 join numbers and units greedily instead of allowing them into
89 separate function arguments
92 %nonassoc NUMBER_IDENTIFIER
104 %{ // -*-Fundamental-*-
109 * The rules for who is protecting what are very shady. Uniformise
112 * There are too many lexical modes?
123 #include "context-def.hh"
124 #include "context-mod.hh"
125 #include "dimensions.hh"
126 #include "file-path.hh"
128 #include "international.hh"
129 #include "lily-guile.hh"
130 #include "lily-lexer.hh"
131 #include "lily-parser.hh"
132 #include "ly-module.hh"
136 #include "output-def.hh"
137 #include "paper-book.hh"
138 #include "scm-hash.hh"
140 #include "text-interface.hh"
144 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
146 parser->parser_error (*i, s);
149 // The following are somewhat precarious constructs as they may change
150 // the value of the lookahead token. That implies that the lookahead
151 // token must not yet have made an impact on the state stack other
152 // than causing the reduction of the current rule, or switching the
153 // lookahead token while Bison is mulling it over will cause trouble.
155 #define MYBACKUP(Token, Value, Location) \
157 if (yychar != YYEMPTY) \
158 parser->lexer_->push_extra_token \
159 (yylloc, yychar, yylval); \
161 parser->lexer_->push_extra_token \
162 (Location, Token, Value); \
163 parser->lexer_->push_extra_token (Location, BACKUP); \
168 #define MYREPARSE(Location, Pred, Token, Value) \
170 if (yychar != YYEMPTY) \
171 parser->lexer_->push_extra_token \
172 (yylloc, yychar, yylval); \
173 parser->lexer_->push_extra_token \
174 (Location, Token, Value); \
175 parser->lexer_->push_extra_token \
176 (Location, REPARSE, Pred); \
185 #define MY_MAKE_MUSIC(x, spot) \
186 make_music_with_input (ly_symbol2scm (x), \
187 parser->lexer_->override_input (spot))
190 - Don't use lily module, create a new module instead.
191 - delay application of the function
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) \
203 (ly_lily_module_constant ("%location"), \
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 (ly_lily_module_constant (name), \
212 ##__VA_ARGS__, SCM_UNDEFINED))
214 #define START_MAKE_SYNTAX(name, ...) \
215 scm_list_n (ly_lily_module_constant (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 SCM scorify = ly_lily_module_constant ("scorify-music");
1019 $2 = scm_call_1 (scorify, $2);
1021 if (unsmob<Score> ($2))
1024 $2 = SCM_UNSPECIFIED;
1027 Score *score = unsmob<Score> ($$);
1028 if (score && scm_is_pair ($1)) {
1029 if (ly_is_module (scm_car ($1)))
1031 score->set_header (scm_car ($1));
1034 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1035 scm_is_pair (p); p = scm_cdr (p))
1037 score->add_output_def (unsmob<Output_def> (scm_car (p)));
1042 score->add_output_def (od);
1043 else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1044 scm_set_cdr_x ($$, scm_cons ($2, scm_cdr ($$)));
1046 $$ = scm_cons ($2, $$);
1047 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1048 parser->parser_error (@2, _("Spurious expression in \\score"));
1052 if (Score *score = unsmob<Score> ($1)) {
1053 if (!ly_is_module (score->get_header ()))
1054 score->set_header (ly_make_module (false));
1055 parser->lexer_->add_scope (score->get_header ());
1057 if (!scm_is_pair ($1) || !ly_is_module (scm_car ($1)))
1058 $1 = scm_cons (ly_make_module (false), $1);
1059 parser->lexer_->add_scope (scm_car ($1));
1074 Output_def *od = unsmob<Output_def> ($1);
1076 if (!to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1078 parser->parser_error (@1, _ ("need \\paper for paper block"));
1079 $$ = get_paper (parser)->unprotect ();
1086 output_def_body '}' {
1087 if (scm_is_pair ($1))
1090 parser->lexer_->remove_scope ();
1091 parser->lexer_->pop_state ();
1097 Output_def *p = get_paper (parser);
1098 p->input_origin_ = @$;
1099 parser->lexer_->add_scope (p->scope_);
1100 $$ = p->unprotect ();
1103 Output_def *p = get_midi (parser);
1104 $$ = p->unprotect ();
1105 parser->lexer_->add_scope (p->scope_);
1108 Output_def *p = get_layout (parser);
1110 parser->lexer_->add_scope (p->scope_);
1111 $$ = p->unprotect ();
1115 output_def_head_with_mode_switch:
1117 parser->lexer_->push_initial_state ();
1122 // We need this weird nonterminal because both music as well as a
1123 // context definition can start with \context and the difference is
1124 // only apparent after looking at the next token. If it is '{', there
1125 // is still time to escape from notes mode.
1127 music_or_context_def:
1129 | context_def_spec_block
1133 output_def_head_with_mode_switch '{' {
1134 unsmob<Output_def> ($1)->input_origin_.set_spot (@$);
1135 // This is a stupid trick to mark the beginning of the
1136 // body for deciding whether to allow
1137 // embedded_scm_active to have an output definition
1138 $$ = scm_list_1 ($1);
1140 | output_def_body assignment {
1141 if (scm_is_pair ($1))
1144 | output_def_body embedded_scm_active
1146 // We don't switch into note mode for Scheme functions
1147 // here. Does not seem warranted/required in output
1149 if (scm_is_pair ($1))
1151 Output_def *o = unsmob<Output_def> ($2);
1153 o->input_origin_.set_spot (@$);
1154 $1 = o->self_scm ();
1155 parser->lexer_->remove_scope ();
1156 parser->lexer_->add_scope (o->scope_);
1157 $2 = SCM_UNSPECIFIED;
1161 if (unsmob<Context_def> ($2))
1162 assign_context_def (unsmob<Output_def> ($1), $2);
1163 // Seems unlikely, but let's be complete:
1164 else if (unsmob<Music> ($2))
1166 SCM proc = parser->lexer_->lookup_identifier
1167 ("output-def-music-handler");
1168 scm_call_2 (proc, $1, $2);
1169 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1170 parser->parser_error (@2, _("bad expression type"));
1173 | output_def_body SCM_TOKEN {
1174 if (scm_is_pair ($1))
1176 // Evaluate and ignore #xxx, as opposed to \xxx
1177 parser->lexer_->eval_scm_token ($2, @2);
1181 if (scm_is_pair ($1))
1183 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1184 parser->lexer_->push_note_state (nn);
1185 } music_or_context_def
1187 parser->lexer_->pop_state ();
1188 if (unsmob<Context_def> ($3))
1189 assign_context_def (unsmob<Output_def> ($1), $3);
1192 SCM proc = parser->lexer_->lookup_identifier
1193 ("output-def-music-handler");
1194 scm_call_2 (proc, $1, $3);
1198 | output_def_body error {
1204 TEMPO steno_duration '=' tempo_range {
1205 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1207 | TEMPO scalar steno_duration '=' tempo_range {
1208 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1211 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1216 The representation of a list is reversed to have efficient append. */
1222 | music_list music_embedded {
1223 if (unsmob<Music> ($2))
1224 $$ = scm_cons ($2, $1);
1226 | music_list error {
1227 Music *m = MY_MAKE_MUSIC("Music", @$);
1229 m->set_property ("error-found", SCM_BOOL_T);
1230 $$ = scm_cons (m->self_scm (), $1);
1231 m->unprotect (); /* UGH */
1238 $$ = scm_reverse_x ($2, SCM_EOL);
1243 | lyric_element_music
1250 $$ = make_music_from_simple (parser, @1, $1);
1251 if (!unsmob<Music> ($$))
1253 parser->parser_error (@1, _ ("music expected"));
1254 $$ = MAKE_SYNTAX ("void-music", @$);
1262 if (unsmob<Music> ($1)->is_mus_type ("post-event")) {
1263 parser->parser_error (@1, _ ("unexpected post-event"));
1264 $$ = SCM_UNSPECIFIED;
1267 | music_embedded_backup
1271 | music_embedded_backup BACKUP lyric_element_music
1275 | multiplied_duration post_events
1277 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1279 parser->default_duration_ = *unsmob<Duration> ($1);
1280 n->set_property ("duration", $1);
1282 if (scm_is_pair ($2))
1283 n->set_property ("articulations",
1284 scm_reverse_x ($2, SCM_EOL));
1285 $$ = n->unprotect ();
1289 music_embedded_backup:
1292 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1294 else if (Music *m = unsmob<Music> ($1)) {
1295 if (m->is_mus_type ("post-event")) {
1296 parser->parser_error
1297 (@1, _ ("unexpected post-event"));
1298 $$ = SCM_UNSPECIFIED;
1301 } else if (parser->lexer_->is_lyric_state ()
1302 && Text_interface::is_markup ($1))
1303 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1305 @$.warning (_ ("Ignoring non-music expression"));
1311 // music_assign does not need to contain lyrics: there are no
1312 // assignments in lyricmode.
1315 | composite_music %prec COMPOSITE
1319 REPEAT simple_string unsigned_number music
1321 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1323 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1325 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1330 SEQUENTIAL braced_music_list {
1331 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1333 | braced_music_list {
1334 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1339 SIMULTANEOUS braced_music_list {
1340 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1342 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1343 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1349 | music_property_def
1353 context_modification:
1356 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1357 parser->lexer_->push_note_state (nn);
1358 } '{' context_mod_list '}'
1360 parser->lexer_->pop_state ();
1363 | WITH CONTEXT_MOD_IDENTIFIER
1367 | CONTEXT_MOD_IDENTIFIER
1371 | WITH context_modification_arg
1373 if (unsmob<Music> ($2)) {
1374 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1375 $2 = scm_call_1 (proc, $2);
1377 if (unsmob<Context_mod> ($2))
1380 parser->parser_error (@2, _ ("not a context mod"));
1381 $$ = Context_mod ().smobbed_copy ();
1386 context_modification_arg:
1391 optional_context_mod:
1395 | context_modification
1403 $$ = Context_mod ().smobbed_copy ();
1405 | context_mod_list context_mod {
1406 if (!SCM_UNBNDP ($2))
1407 unsmob<Context_mod> ($1)->add_context_mod ($2);
1409 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1410 Context_mod *md = unsmob<Context_mod> ($2);
1412 unsmob<Context_mod> ($1)->add_context_mods (md->get_mods ());
1414 | context_mod_list context_mod_arg {
1415 if (scm_is_eq ($2, SCM_UNSPECIFIED))
1417 else if (unsmob<Music> ($2)) {
1418 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1419 $2 = scm_call_1 (proc, $2);
1421 if (unsmob<Context_mod> ($2))
1422 unsmob<Context_mod> ($$)->add_context_mods
1423 (unsmob<Context_mod> ($2)->get_mods ());
1425 parser->parser_error (@2, _ ("not a context mod"));
1431 CONTEXT symbol optional_id optional_context_mod {
1432 Context_mod *ctxmod = unsmob<Context_mod> ($4);
1435 mods = ctxmod->get_mods ();
1436 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1438 | NEWCONTEXT symbol optional_id optional_context_mod {
1439 Context_mod *ctxmod = unsmob<Context_mod> ($4);
1442 mods = ctxmod->get_mods ();
1443 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1448 ADDLYRICS lyric_mode_music {
1449 $$ = scm_list_1 ($2);
1451 | new_lyrics ADDLYRICS lyric_mode_music {
1452 $$ = scm_cons ($3, $1);
1456 /* basic_music is basically the same as composite_music but with
1457 * context-prefixed music and lyricized music explicitly removed. The
1458 * reason is that in a sequence
1460 * \new Staff \new Voice { ... } \addlyrics { ... } \addlyrics { ... }
1462 * we need to group both \addlyrics together (as they go with the same
1463 * voice) but then combine them with \new Voice { ... }, meaning that
1464 * combining \new Voice { ... } needs higher priority than
1465 * { ... } \addlyrics, and *not* have \new Staff \new Voice { ... }
1466 * combine before combining \new Voice { ... } \addlyrics: only one
1467 * layer of context-prefixed music should assemble before \addlyrics
1468 * is integrated. Total mess, and we sort this mess out with explicit
1469 * rules preferring a single context-prefix.
1476 | LYRICSTO simple_string lyric_mode_music {
1477 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, SCM_EOL, $3);
1479 | LYRICSTO symbol '=' simple_string lyric_mode_music
1481 $$ = MAKE_SYNTAX ("lyric_combine", @$, $3, $2, $4);
1491 contexted_basic_music:
1492 context_prefix contextable_music new_lyrics
1495 i.set_location (@1, @2);
1496 $$ = FINISH_MAKE_SYNTAX ($1, i, $2);
1497 $$ = MAKE_SYNTAX ("add-lyrics", @$, $$, scm_reverse_x ($3, SCM_EOL));
1499 | context_prefix contextable_music
1501 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1503 | context_prefix contexted_basic_music
1505 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1510 basic_music %prec COMPOSITE
1511 | contexted_basic_music
1512 | basic_music new_lyrics
1514 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1521 | grouped_music_list
1525 simultaneous_music { $$ = $1; }
1526 | sequential_music { $$ = $1; }
1529 /* Function argument lists are arguably the most complex part in the
1530 * parser. They are pretty tricky to understand because of the way
1531 * they are processed, and because of optional arguments that can be
1532 * omitted. When there are several optional arguments in a row,
1533 * omitting one automatically omits all following arguments. Optional
1534 * arguments can only be omitted when either
1536 * a) the omission is explicitly started with \default
1537 * b) the omission is implicitly started by an argument not matching
1538 * its predicate, and there is a mandatory argument later that can
1539 * "catch" the argument that does not fit.
1541 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1542 * (corresponding to mandatory arguments and having a predicate
1543 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1544 * the semantic value of the EXPECT_OPTIONAL token is the default to
1545 * use when the optional argument is omitted, and EXPECT_SCM again has
1546 * the argument predicate as semantic value) in reverse order to the
1547 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1548 * processed inside-out while actual tokens are consumed.
1550 * This means that the argument list tokens determine the actions
1551 * taken as they arrive. The structure of the argument list is known
1552 * to the parser and stored in its parse stack when the first argument
1553 * is being parsed. What the parser does not know is which predicates
1554 * will match and whether or not \default will be appearing in the
1555 * argument list, and where.
1557 * Sequences of 0 or more optional arguments are scanned using either
1558 * function_arglist_backup or function_arglist_nonbackup. The first
1559 * is used when optional arguments are followed by at least one
1560 * mandatory argument: in that case optional arguments may be skipped
1561 * by either a false predicate (in which case the expression will be
1562 * pushed back as one or more tokens, preceded by a BACKUP token) or
1563 * by using \default.
1565 * If optional arguments are at the end of the argument list, they are
1566 * instead scanned using function_arglist_nonbackup: here the only
1567 * manner to enter into skipping of optional arguments is the use of
1570 * The argument list of a normal function call is parsed using
1571 * function_arglist. The part of an argument list before a mandatory
1572 * argument is parsed using function_arglist_optional.
1574 * The difference is that leading optional arguments are scanned using
1575 * function_arglist_nonbackup and function_arglist_backup,
1578 * Most other details are obvious in the rules themselves.
1584 | SYMBOL_LIST '.' symbol_list_rev
1586 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1592 | symbol_list_rev '.' symbol_list_part
1594 $$ = scm_append_x (scm_list_2 ($3, $1));
1598 // symbol_list_part delivers elements in reverse copy.
1603 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1604 $$ = try_string_variants (sym_l_p, $1);
1605 if (SCM_UNBNDP ($$)) {
1606 parser->parser_error (@1, _("not a symbol"));
1609 $$ = scm_reverse ($$);
1614 symbol_list_element:
1620 function_arglist_nonbackup:
1621 function_arglist_common
1622 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1624 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1626 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1628 SCM n = scm_difference ($5, SCM_UNDEFINED);
1629 if (scm_is_true (scm_call_1 ($2, n)))
1630 $$ = scm_cons (n, $3);
1632 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1633 t->set_property ("digit", $5);
1634 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1638 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1640 $$ = check_scheme_arg (parser, @4,
1641 scm_difference ($5, SCM_UNDEFINED),
1644 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1646 $$ = check_scheme_arg (parser, @4,
1647 scm_difference ($5, SCM_UNDEFINED),
1650 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1652 if (scm_is_true (scm_call_1 ($2, $4)))
1653 $$ = scm_cons ($4, $3);
1655 $$ = check_scheme_arg (parser, @4,
1656 make_music_from_simple
1660 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1662 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1664 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1666 if (scm_is_true (scm_call_1 ($2, $3)))
1667 $$ = scm_cons ($3, $1);
1669 $$ = check_scheme_arg (parser, @3,
1670 make_music_from_simple
1674 | function_arglist_nonbackup_reparse REPARSE duration_length
1676 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1678 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1680 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1682 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1684 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1686 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1688 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1690 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1692 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1696 function_arglist_nonbackup_reparse:
1697 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1700 SCM res = try_string_variants ($2, $4);
1701 if (!SCM_UNBNDP (res))
1702 if (scm_is_pair (res))
1703 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1705 MYREPARSE (@4, $2, SCM_ARG, res);
1706 else if (scm_is_true
1708 ($2, make_music_from_simple
1710 MYREPARSE (@4, $2, STRING, $4);
1712 MYREPARSE (@4, $2, SCM_ARG, $4);
1714 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1719 ($2, make_music_from_simple
1721 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1723 MYREPARSE (@4, $2, SCM_ARG, $4);
1725 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1730 ($2, make_music_from_simple
1732 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1734 MYREPARSE (@4, $2, SCM_ARG, $4);
1736 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1739 SCM res = try_string_variants ($2, $4);
1740 if (!SCM_UNBNDP (res))
1741 if (scm_is_pair (res))
1742 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1744 MYREPARSE (@4, $2, SCM_ARG, res);
1745 else if (scm_is_true
1747 ($2, make_music_from_simple
1749 MYREPARSE (@4, $2, STRING, $4);
1751 MYREPARSE (@4, $2, SCM_ARG, $4);
1753 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1756 if (scm_is_true (scm_call_1 ($2, $4)))
1757 MYREPARSE (@4, $2, SCM_ARG, $4);
1758 else if (scm_is_true
1760 ($2, make_music_from_simple
1762 MYREPARSE (@4, $2, STRING, $4);
1764 MYREPARSE (@4, $2, SCM_ARG, $4);
1766 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1769 if (scm_is_true (scm_call_1 ($2, $4)))
1770 MYREPARSE (@4, $2, REAL, $4);
1772 SCM d = make_duration ($4);
1773 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1774 MYREPARSE (@4, $2, REAL, $4); // trigger error
1776 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1779 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1781 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1786 // function_arglist_backup can't occur at the end of an argument
1788 function_arglist_backup:
1789 function_arglist_common
1790 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1792 if (scm_is_true (scm_call_1 ($2, $4)))
1793 $$ = scm_cons ($4, $3);
1795 $$ = make_music_from_simple (parser, @4, $4);
1796 if (scm_is_true (scm_call_1 ($2, $$)))
1797 $$ = scm_cons ($$, $3);
1800 $$ = scm_cons (loc_on_music (@3, $1), $3);
1801 MYBACKUP (SCM_ARG, $4, @4);
1805 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1807 if (scm_is_true (scm_call_1 ($2, $4)))
1809 $$ = scm_cons ($4, $3);
1811 $$ = scm_cons (loc_on_music (@3, $1), $3);
1812 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1815 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1819 ($2, make_music_from_simple
1823 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1824 } else if (scm_is_true (scm_call_1 ($2, $4)))
1825 $$ = scm_cons ($4, $3);
1827 $$ = scm_cons (loc_on_music (@3, $1), $3);
1828 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1831 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1835 ($2, make_music_from_simple
1839 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1840 } else if (scm_is_true (scm_call_1 ($2, $4)))
1841 $$ = scm_cons ($4, $3);
1843 $$ = scm_cons (loc_on_music (@3, $1), $3);
1844 MYBACKUP (TONICNAME_PITCH, $4, @4);
1847 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1849 if (scm_is_true (scm_call_1 ($2, $4)))
1850 $$ = scm_cons ($4, $3);
1852 $$ = scm_cons (loc_on_music (@3, $1), $3);
1853 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1856 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1858 if (scm_is_true (scm_call_1 ($2, $4)))
1860 MYREPARSE (@4, $2, REAL, $4);
1863 SCM d = make_duration ($4);
1864 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1866 $$ = scm_cons (loc_on_music (@3, $1), $3);
1867 MYBACKUP (UNSIGNED, $4, @4);
1869 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1874 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1876 if (scm_is_true (scm_call_1 ($2, $4)))
1879 MYREPARSE (@4, $2, REAL, $4);
1881 $$ = scm_cons (loc_on_music (@3, $1), $3);
1882 MYBACKUP (REAL, $4, @4);
1885 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1887 if (scm_is_true (scm_call_1 ($2, $4)))
1889 $$ = scm_cons ($4, $3);
1891 $$ = scm_cons (loc_on_music (@3, $1), $3);
1892 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1895 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1897 SCM n = scm_difference ($5, SCM_UNDEFINED);
1898 if (scm_is_true (scm_call_1 ($2, n))) {
1900 MYREPARSE (@5, $2, REAL, n);
1902 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1903 t->set_property ("digit", $5);
1904 $$ = t->unprotect ();
1905 if (scm_is_true (scm_call_1 ($2, $$)))
1906 $$ = scm_cons ($$, $3);
1908 $$ = scm_cons (loc_on_music (@3, $1), $3);
1909 MYBACKUP (UNSIGNED, $5, @5);
1910 parser->lexer_->push_extra_token (@4, '-');
1914 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1916 SCM n = scm_difference ($5, SCM_UNDEFINED);
1917 if (scm_is_true (scm_call_1 ($2, n))) {
1918 MYREPARSE (@5, $2, REAL, n);
1921 $$ = scm_cons (loc_on_music (@3, $1), $3);
1922 MYBACKUP (REAL, n, @5);
1925 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1927 SCM n = scm_difference ($5, SCM_UNDEFINED);
1928 if (scm_is_true (scm_call_1 ($2, n))) {
1929 $$ = scm_cons (n, $3);
1931 $$ = scm_cons (loc_on_music (@3, $1), $3);
1932 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1935 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1937 if (scm_is_true (scm_call_1 ($2, $4)))
1939 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1942 $$ = scm_cons (loc_on_music (@3, $1), $3);
1943 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1946 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1948 SCM res = try_string_variants ($2, $4);
1949 if (!SCM_UNBNDP (res))
1950 if (scm_is_pair (res)) {
1952 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1955 $$ = scm_cons (res, $3);
1957 $$ = scm_cons (loc_on_music (@3, $1), $3);
1958 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1961 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1963 SCM res = try_string_variants ($2, $4);
1964 if (!SCM_UNBNDP (res))
1965 if (scm_is_pair (res)) {
1967 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1970 $$ = scm_cons (res, $3);
1972 $$ = scm_cons (loc_on_music (@3, $1), $3);
1973 MYBACKUP (STRING, $4, @4);
1976 | function_arglist_backup REPARSE pitch_or_music
1978 if (scm_is_true (scm_call_1 ($2, $3)))
1979 $$ = scm_cons ($3, $1);
1981 $$ = check_scheme_arg (parser, @3,
1982 make_music_from_simple
1986 | function_arglist_backup REPARSE bare_number_common
1988 $$ = check_scheme_arg (parser, @3,
1991 | function_arglist_backup REPARSE duration_length
1993 $$ = check_scheme_arg (parser, @3,
1996 | function_arglist_backup REPARSE symbol_list_arg
1998 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2003 function_arglist_nonbackup
2004 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2006 $$ = scm_cons (loc_on_music (@4, $1), $3);
2010 function_arglist_skip_nonbackup:
2011 function_arglist_nonbackup
2012 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
2014 $$ = scm_cons (loc_on_music (@3, $1), $3);
2018 function_arglist_common:
2019 EXPECT_NO_MORE_ARGS {
2022 | EXPECT_SCM function_arglist_optional embedded_scm_arg
2024 if (scm_is_true (scm_call_1 ($1, $3)))
2025 $$ = scm_cons ($3, $2);
2027 $$ = check_scheme_arg (parser, @3,
2028 make_music_from_simple
2032 | EXPECT_SCM function_arglist_optional bare_number_common
2034 $$ = check_scheme_arg (parser, @3,
2037 | EXPECT_SCM function_arglist_optional post_event_nofinger
2039 $$ = check_scheme_arg (parser, @3,
2042 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2044 SCM n = scm_difference ($4, SCM_UNDEFINED);
2045 $$ = check_scheme_arg (parser, @4, n, $2, $1);
2047 | function_arglist_common_reparse REPARSE SCM_ARG
2049 $$ = check_scheme_arg (parser, @3,
2052 | function_arglist_common_reparse REPARSE lyric_element_music
2054 $$ = check_scheme_arg (parser, @3,
2057 | function_arglist_common_reparse REPARSE pitch_or_music
2059 if (scm_is_true (scm_call_1 ($2, $3)))
2060 $$ = scm_cons ($3, $1);
2062 $$ = check_scheme_arg (parser, @3,
2063 make_music_from_simple
2067 | function_arglist_common_reparse REPARSE bare_number_common
2069 $$ = check_scheme_arg (parser, @3,
2072 | function_arglist_common_reparse REPARSE duration_length
2074 $$ = check_scheme_arg (parser, @3,
2077 | function_arglist_common_reparse REPARSE symbol_list_arg
2079 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2083 function_arglist_common_reparse:
2084 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2087 SCM res = try_string_variants ($1, $3);
2088 if (!SCM_UNBNDP (res))
2089 if (scm_is_pair (res))
2090 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2092 MYREPARSE (@3, $1, SCM_ARG, res);
2093 else if (scm_is_true
2095 ($1, make_music_from_simple (parser, @3, $3))))
2096 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2098 // This is going to flag a syntax error, we
2099 // know the predicate to be false.
2100 MYREPARSE (@3, $1, SCM_ARG, $3);
2102 | EXPECT_SCM function_arglist_optional pitch
2107 ($1, make_music_from_simple
2109 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2111 MYREPARSE (@3, $1, SCM_ARG, $3);
2113 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2118 ($1, make_music_from_simple
2120 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2122 MYREPARSE (@3, $1, SCM_ARG, $3);
2124 | EXPECT_SCM function_arglist_optional STRING
2127 SCM res = try_string_variants ($1, $3);
2128 if (!SCM_UNBNDP (res))
2129 if (scm_is_pair (res))
2130 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2132 MYREPARSE (@3, $1, SCM_ARG, res);
2133 else if (scm_is_true
2135 ($1, make_music_from_simple (parser, @3, $3))))
2136 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2138 // This is going to flag a syntax error, we
2139 // know the predicate to be false.
2140 MYREPARSE (@3, $1, SCM_ARG, $3);
2142 | EXPECT_SCM function_arglist_optional full_markup
2145 if (scm_is_true (scm_call_1 ($1, $3)))
2146 MYREPARSE (@3, $1, SCM_ARG, $3);
2147 else if (scm_is_true
2149 ($1, make_music_from_simple (parser, @3, $3))))
2150 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2152 // This is going to flag a syntax error, we
2153 // know the predicate to be false.
2154 MYREPARSE (@3, $1, SCM_ARG, $3);
2156 | EXPECT_SCM function_arglist_optional UNSIGNED
2159 if (scm_is_true (scm_call_1 ($1, $3)))
2160 MYREPARSE (@3, $1, REAL, $3);
2162 SCM d = make_duration ($3);
2163 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
2164 MYREPARSE (@3, $1, REAL, $3);
2166 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2169 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2172 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2174 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2177 SCM n = scm_difference ($4, SCM_UNDEFINED);
2178 if (scm_is_true (scm_call_1 ($1, n)))
2179 MYREPARSE (@4, $1, REAL, n);
2181 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2182 t->set_property ("digit", $4);
2183 SCM m = t->unprotect ();
2184 if (scm_is_true (scm_call_1 ($1, m)))
2185 MYREPARSE (@4, $1, SCM_ARG, m);
2187 MYREPARSE (@4, $1, SCM_ARG, $4);
2190 | EXPECT_SCM function_arglist_optional '-' REAL
2193 SCM n = scm_difference ($4, SCM_UNDEFINED);
2194 MYREPARSE (@4, $1, REAL, n);
2198 function_arglist_optional:
2199 function_arglist_backup
2200 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2202 $$ = scm_cons (loc_on_music (@4, $1), $3);
2204 | function_arglist_skip_backup BACKUP
2207 function_arglist_skip_backup:
2208 function_arglist_backup
2209 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2211 $$ = scm_cons (loc_on_music (@3, $1), $3);
2215 music_function_call:
2216 MUSIC_FUNCTION function_arglist {
2217 $$ = MAKE_SYNTAX ("music-function", @$,
2224 /**/ { $$ = SCM_EOL; }
2225 | '=' simple_string {
2230 // We must not have lookahead tokens parsed in lyric mode. In order
2231 // to save confusion, we take almost the same set as permitted with
2232 // \lyricmode and/or \lyrics. However, music identifiers are also
2233 // allowed, and they obviously do not require switching into lyrics
2234 // mode for parsing.
2238 parser->lexer_->push_lyric_state ();
2239 } grouped_music_list
2241 parser->lexer_->pop_state ();
2248 mode_changing_head grouped_music_list {
2249 if (scm_is_eq ($1, ly_symbol2scm ("chords")))
2251 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2257 parser->lexer_->pop_state ();
2259 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2260 Context_mod *ctxmod = unsmob<Context_mod> ($2);
2263 mods = ctxmod->get_mods ();
2264 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2265 if (scm_is_eq ($1, ly_symbol2scm ("ChordNames")))
2267 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2269 parser->lexer_->pop_state ();
2275 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2276 parser->lexer_->push_note_state (nn);
2278 $$ = ly_symbol2scm ("notes");
2282 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2283 parser->lexer_->push_note_state (nn);
2285 $$ = ly_symbol2scm ("drums");
2288 parser->lexer_->push_figuredbass_state ();
2290 $$ = ly_symbol2scm ("figures");
2293 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2294 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2295 nn = parser->lexer_->lookup_identifier ("pitchnames");
2296 parser->lexer_->push_chord_state (nn);
2297 $$ = ly_symbol2scm ("chords");
2301 { parser->lexer_->push_lyric_state ();
2302 $$ = ly_symbol2scm ("lyrics");
2306 mode_changing_head_with_context:
2308 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2309 parser->lexer_->push_note_state (nn);
2311 $$ = ly_symbol2scm ("DrumStaff");
2314 parser->lexer_->push_figuredbass_state ();
2316 $$ = ly_symbol2scm ("FiguredBass");
2319 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2320 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2321 nn = parser->lexer_->lookup_identifier ("pitchnames");
2322 parser->lexer_->push_chord_state (nn);
2323 $$ = ly_symbol2scm ("ChordNames");
2326 { parser->lexer_->push_lyric_state ();
2327 $$ = ly_symbol2scm ("Lyrics");
2332 CHANGE symbol '=' simple_string {
2333 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2340 $$ = scm_reverse_x ($1, SCM_EOL);
2342 | symbol_list_rev property_path {
2343 $$ = scm_reverse_x ($1, $2);
2349 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2352 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2354 | OVERRIDE property_path '=' scalar {
2355 if (scm_ilength ($2) < 2) {
2356 parser->parser_error (@2, _("bad grob property path"));
2359 $$ = scm_cons (ly_symbol2scm ("push"),
2360 scm_cons2 (scm_car ($2),
2365 | REVERT revert_arg {
2366 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2370 // This is all quite awkward for the sake of substantial backward
2371 // compatibility while at the same time allowing a more "natural" form
2372 // of specification not separating grob specification from grob
2373 // property path. The purpose of this definition of revert_arg is to
2374 // allow the symbol list which specifies grob and property to revert
2375 // to be optionally be split into two parts after the grob (which in
2376 // this case is just the first element of the list). symbol_list_part
2377 // is only one path component, but it can be parsed without lookahead,
2378 // so we can follow it with a synthetic BACKUP token when needed. If
2379 // the first symbol_list_part already contains multiple elements (only
2380 // possible if a Scheme expression provides them), we just parse for
2381 // additional elements introduced by '.', which is what the
2382 // SYMBOL_LIST backup in connection with the immediately following
2383 // rule using symbol_list_arg does.
2385 // As long as we don't have our coffers filled with both grob and at
2386 // least one grob property specification, the rest of the required
2387 // symbol list chain may be provided either with or without a leading
2388 // dot. This is for both allowing the traditional
2389 // \revert Accidental #'color
2390 // as well as well as the "naive" form
2391 // \revert Accidental.color
2394 revert_arg_backup BACKUP symbol_list_arg
2403 if (scm_is_null ($1)
2404 || scm_is_null (scm_cdr ($1)))
2405 MYBACKUP (SCM_ARG, $1, @1);
2407 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2411 // revert_arg_part delivers results in reverse
2414 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2416 $$ = scm_append_x (scm_list_2 ($5, $3));
2418 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2420 $$ = scm_append_x (scm_list_2 ($4, $3));
2425 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2426 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2428 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2429 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2430 | DENIES { $$ = ly_symbol2scm ("denies"); }
2432 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2433 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2434 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2435 | NAME { $$ = ly_symbol2scm ("context-name"); }
2439 property_operation { $$ = $1; }
2440 | context_def_mod STRING {
2441 $$ = scm_list_2 ($1, $2);
2443 | context_def_mod embedded_scm
2445 if (!scm_is_string ($2)
2446 && ly_symbol2scm ("consists") != $1
2447 && ly_symbol2scm ("remove") != $1)
2450 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2454 $$ = scm_list_2 ($1, $2);
2459 // If defined, at least two members.
2463 SCM l = scm_reverse_x ($1, SCM_EOL);
2466 (scm_object_property (scm_car (l),
2467 ly_symbol2scm ("is-grob?"))))
2468 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2469 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2470 parser->parser_error (@1, _ ("bad grob property path"));
2477 // If defined, at least three members
2481 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2483 parser->parser_error (@1, _ ("bad grob property path"));
2487 | grob_prop_spec property_path
2489 if (!SCM_UNBNDP ($1)) {
2490 $$ = scm_append_x (scm_list_2 ($1, $2));
2491 if (scm_is_null (scm_cddr ($$))) {
2492 parser->parser_error (@$, _ ("bad grob property path"));
2500 // Exactly two elements or undefined
2504 SCM l = scm_reverse_x ($1, SCM_EOL);
2505 switch (scm_ilength (l)) {
2507 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2511 parser->parser_error (@1, _ ("bad context property path"));
2519 // This is all quite awkward for the sake of substantial backward
2520 // compatibility while at the same time allowing a more "natural" form
2521 // of specification not separating grob specification from grob
2522 // property path. The purpose of this definition of
2523 // simple_revert_context is to allow the symbol list which specifies
2524 // grob and property to revert to be optionally be split into two
2525 // parts after the grob (which may be preceded by a context
2526 // specification, a case which we distinguish by checking whether the
2527 // first symbol is a valid grob symbol instead).
2529 // See revert_arg above for the main work horse of this arrangement.
2530 // simple_revert_context just caters for the context and delegates the
2531 // rest of the job to revert_arg.
2533 simple_revert_context:
2536 $1 = scm_reverse_x ($1, SCM_EOL);
2537 if (scm_is_null ($1)
2539 (scm_object_property (scm_car ($1),
2540 ly_symbol2scm ("is-grob?")))) {
2541 $$ = ly_symbol2scm ("Bottom");
2542 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2545 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2552 OVERRIDE grob_prop_path '=' scalar {
2553 if (SCM_UNBNDP ($2))
2554 $$ = MAKE_SYNTAX ("void-music", @$);
2556 $$ = MAKE_SYNTAX ("property-operation", @$,
2558 ly_symbol2scm ("OverrideProperty"),
2564 | REVERT simple_revert_context revert_arg {
2565 $$ = MAKE_SYNTAX ("property-operation", @$,
2567 ly_symbol2scm ("RevertProperty"),
2571 | SET context_prop_spec '=' scalar {
2572 if (SCM_UNBNDP ($2))
2573 $$ = MAKE_SYNTAX ("void-music", @$);
2575 $$ = MAKE_SYNTAX ("property-operation", @$,
2577 ly_symbol2scm ("PropertySet"),
2581 | UNSET context_prop_spec {
2582 if (SCM_UNBNDP ($2))
2583 $$ = MAKE_SYNTAX ("void-music", @$);
2585 $$ = MAKE_SYNTAX ("property-operation", @$,
2587 ly_symbol2scm ("PropertyUnset"),
2599 simple_string: STRING {
2604 if (scm_is_string ($1)) {
2607 parser->parser_error (@1, (_ ("simple string expected")));
2608 $$ = scm_string (SCM_EOL);
2615 $$ = scm_string_to_symbol ($1);
2619 // This is a bit of overkill but makes the same
2620 // routine responsible for all symbol interpretations.
2621 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2623 if (SCM_UNBNDP ($$))
2625 parser->parser_error (@1, (_ ("symbol expected")));
2626 // Generate a unique symbol in case it is used
2627 // for an assignment or similar
2628 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2638 // The following is a rather defensive variant of admitting
2639 // negative numbers: the grammar would permit number_factor or
2640 // even number_expression. However, function arguments allow
2641 // only this simple kind of negative number, so to have things
2642 // like \tweak and \override behave reasonably similar, it
2643 // makes sense to rule out things like -- which are rather an
2644 // accent in function argument contexts.
2647 $$ = scm_difference ($2, SCM_UNDEFINED);
2653 simple_element post_events {
2654 // Let the rhythmic music iterator sort this mess out.
2655 if (scm_is_pair ($2)) {
2656 unsmob<Music> ($$)->set_property ("articulations",
2657 scm_reverse_x ($2, SCM_EOL));
2660 | CHORD_REPETITION optional_notemode_duration post_events {
2662 i.set_location (@1, @3);
2663 $$ = MAKE_SYNTAX ("repetition-chord", i,
2664 $2, scm_reverse_x ($3, SCM_EOL));
2666 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2668 i.set_location (@1, @3);
2669 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2670 scm_reverse_x ($3, SCM_EOL));
2673 | note_chord_element
2678 chord_body optional_notemode_duration post_events
2680 Music *m = unsmob<Music> ($1);
2681 SCM dur = unsmob<Duration> ($2)->smobbed_copy ();
2682 SCM es = m->get_property ("elements");
2683 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2685 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2686 unsmob<Music> (scm_car (s))->set_property ("duration", dur);
2687 es = ly_append2 (es, postevs);
2689 m-> set_property ("elements", es);
2691 $$ = m->self_scm ();
2696 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2698 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2700 | FIGURE_OPEN figure_list FIGURE_CLOSE
2702 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2706 chord_body_elements:
2707 /* empty */ { $$ = SCM_EOL; }
2708 | chord_body_elements chord_body_element {
2709 if (!SCM_UNBNDP ($2))
2710 $$ = scm_cons ($2, $1);
2715 pitch_or_tonic_pitch exclamations questions octave_check post_events
2717 bool q = to_boolean ($3);
2718 bool ex = to_boolean ($2);
2722 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2723 n->set_property ("pitch", $1);
2725 n->set_property ("cautionary", SCM_BOOL_T);
2727 n->set_property ("force-accidental", SCM_BOOL_T);
2729 if (scm_is_pair (post)) {
2730 SCM arts = scm_reverse_x (post, SCM_EOL);
2731 n->set_property ("articulations", arts);
2733 if (scm_is_number (check))
2735 int q = scm_to_int (check);
2736 n->set_property ("absolute-octave", scm_from_int (q-1));
2739 $$ = n->unprotect ();
2741 | DRUM_PITCH post_events {
2742 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2743 n->set_property ("drum-type", $1);
2745 if (scm_is_pair ($2)) {
2746 SCM arts = scm_reverse_x ($2, SCM_EOL);
2747 n->set_property ("articulations", arts);
2749 $$ = n->unprotect ();
2751 | music_function_chord_body
2753 Music *m = unsmob<Music> ($1);
2755 while (m && m->is_mus_type ("music-wrapper-music")) {
2756 $$ = m->get_property ("element");
2757 m = unsmob<Music> ($$);
2760 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2761 parser->parser_error (@$, _ ("not a rhythmic event"));
2767 music_function_chord_body:
2773 event_function_event:
2774 EVENT_FUNCTION function_arglist {
2775 $$ = MAKE_SYNTAX ("music-function", @$,
2784 | post_events post_event {
2786 if (Music *m = unsmob<Music> ($2))
2788 if (m->is_mus_type ("post-event-wrapper"))
2790 for (SCM p = m->get_property ("elements");
2794 $$ = scm_cons (scm_car (p), $$);
2798 $$ = scm_cons ($2, $$);
2804 post_event_nofinger:
2805 direction_less_event {
2808 | script_dir music_function_call {
2810 if (!unsmob<Music> ($2)->is_mus_type ("post-event")) {
2811 parser->parser_error (@2, _ ("post-event expected"));
2812 $$ = SCM_UNSPECIFIED;
2813 } else if (!SCM_UNBNDP ($1))
2815 unsmob<Music> ($$)->set_property ("direction", $1);
2819 if (!parser->lexer_->is_lyric_state ())
2820 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2821 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2824 if (!parser->lexer_->is_lyric_state ())
2825 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2826 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2828 | script_dir direction_reqd_event {
2829 if (!SCM_UNBNDP ($1))
2831 Music *m = unsmob<Music> ($2);
2832 m->set_property ("direction", $1);
2836 | script_dir direction_less_event {
2837 if (!SCM_UNBNDP ($1))
2839 Music *m = unsmob<Music> ($2);
2840 m->set_property ("direction", $1);
2847 unsmob<Music> ($$)->set_property ("direction", scm_from_int (UP));
2852 unsmob<Music> ($$)->set_property ("direction", scm_from_int (DOWN));
2863 string_number_event:
2865 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2866 s->set_property ("string-number", $1);
2867 $$ = s->unprotect ();
2871 direction_less_event:
2873 | EVENT_IDENTIFIER {
2877 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2878 a->set_property ("tremolo-type", $1);
2879 $$ = a->unprotect ();
2881 | event_function_event
2884 direction_reqd_event:
2888 | script_abbreviation {
2889 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2890 if (scm_is_string (s)) {
2891 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2892 a->set_property ("articulation-type", s);
2893 $$ = a->unprotect ();
2895 Music *original = unsmob<Music> (s);
2896 if (original && original->is_mus_type ("post-event")) {
2897 Music *a = original->clone ();
2898 a->set_spot (parser->lexer_->override_input (@$));
2899 $$ = a->unprotect ();
2901 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2902 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2909 /**/ { $$ = SCM_EOL; }
2910 | '=' quotes { $$ = $2; }
2924 $$ = scm_from_int (1);
2927 $$ = scm_oneplus ($1);
2933 $$ = scm_from_int (-1);
2936 $$ = scm_oneminus ($1);
2941 NOTENAME_PITCH quotes {
2942 if (!scm_is_eq (SCM_INUM0, $2))
2944 Pitch p = *unsmob<Pitch> ($1);
2945 p = p.transposed (Pitch (scm_to_int ($2), 0));
2946 $$ = p.smobbed_copy ();
2956 TONICNAME_PITCH 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 ();
2968 | PITCH_IDENTIFIER quotes {
2969 if (!scm_is_eq (SCM_INUM0, $2))
2971 Pitch p = *unsmob<Pitch> ($1);
2972 p = p.transposed (Pitch (scm_to_int ($2), 0));
2973 $$ = p.smobbed_copy ();
2978 pitch_or_tonic_pitch:
2985 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2986 t->set_property ("text", $1);
2987 $$ = t->unprotect ();
2990 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2991 t->set_property ("text",
2992 make_simple_markup ($1));
2993 $$ = t->unprotect ();
2997 Music *m = unsmob<Music> ($1);
2998 if (m && m->is_mus_type ("post-event"))
3000 else if (Text_interface::is_markup ($1)) {
3001 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3002 t->set_property ("text", $1);
3003 $$ = t->unprotect ();
3005 parser->parser_error (@1, _ ("not an articulation"));
3011 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3012 t->set_property ("digit", $1);
3013 $$ = t->unprotect ();
3017 script_abbreviation:
3019 $$ = scm_from_ascii_string ("Hat");
3022 $$ = scm_from_ascii_string ("Plus");
3025 $$ = scm_from_ascii_string ("Dash");
3028 $$ = scm_from_ascii_string ("Bang");
3031 $$ = scm_from_ascii_string ("Larger");
3034 $$ = scm_from_ascii_string ("Dot");
3037 $$ = scm_from_ascii_string ("Underscore");
3042 '_' { $$ = scm_from_int (DOWN); }
3043 | '^' { $$ = scm_from_int (UP); }
3044 | '-' { $$ = SCM_UNDEFINED; }
3048 multiplied_duration {
3053 maybe_notemode_duration:
3057 | multiplied_duration {
3059 parser->default_duration_ = *unsmob<Duration> ($$);
3064 optional_notemode_duration:
3065 maybe_notemode_duration
3067 if (SCM_UNBNDP ($$))
3068 $$ = parser->default_duration_.smobbed_copy ();
3074 $$ = make_duration ($1, scm_to_int ($2));
3075 if (SCM_UNBNDP ($$))
3077 parser->parser_error (@1, _ ("not a duration"));
3078 $$ = Duration ().smobbed_copy ();
3081 | DURATION_IDENTIFIER dots {
3082 Duration *d = unsmob<Duration> ($1);
3083 Duration k (d->duration_log (),
3084 d->dot_count () + scm_to_int ($2));
3085 k = k.compressed (d->factor ());
3086 scm_remember_upto_here_1 ($1);
3087 $$ = k.smobbed_copy ();
3091 multiplied_duration:
3095 | multiplied_duration '*' UNSIGNED {
3096 $$ = unsmob<Duration> ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
3098 | multiplied_duration '*' FRACTION {
3099 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
3101 $$ = unsmob<Duration> ($$)->compressed (m).smobbed_copy ();
3110 $$ = scm_oneplus ($1);
3116 $$ = scm_from_int (parser->default_tremolo_type_);
3119 if (SCM_UNBNDP (make_duration ($2))) {
3120 parser->parser_error (@2, _ ("not a duration"));
3121 $$ = scm_from_int (parser->default_tremolo_type_);
3124 parser->default_tremolo_type_ = scm_to_int ($2);
3130 UNSIGNED { $$ = $1; }
3131 | STRING { $$ = $1; }
3132 | full_markup { $$ = $1; }
3135 // as an integer, it needs to be non-negative, and otherwise
3136 // it needs to be suitable as a markup.
3137 if (scm_is_integer ($1)
3138 ? scm_is_true (scm_negative_p ($1))
3139 : !Text_interface::is_markup ($1))
3141 parser->parser_error (@1, _ ("bass number expected"));
3147 figured_bass_alteration:
3148 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3149 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3150 | '!' { $$ = scm_from_int (0); }
3155 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3156 $$ = bfr->unprotect ();
3159 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3160 $$ = bfr->self_scm ();
3162 if (scm_is_number ($1))
3163 bfr->set_property ("figure", $1);
3164 else if (Text_interface::is_markup ($1))
3165 bfr->set_property ("text", $1);
3171 unsmob<Music> ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3173 | bass_figure figured_bass_alteration {
3174 Music *m = unsmob<Music> ($1);
3175 if (scm_to_double ($2)) {
3176 SCM salter = m->get_property ("alteration");
3177 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3178 m->set_property ("alteration",
3179 scm_sum (alter, $2));
3181 m->set_property ("alteration", scm_from_int (0));
3184 | bass_figure figured_bass_modification {
3185 Music *m = unsmob<Music> ($1);
3186 m->set_property ($2, SCM_BOOL_T);
3191 figured_bass_modification:
3193 $$ = ly_symbol2scm ("augmented");
3196 $$ = ly_symbol2scm ("no-continuation");
3199 $$ = ly_symbol2scm ("diminished");
3202 $$ = ly_symbol2scm ("augmented-slash");
3212 unsmob<Music> ($$)->set_property ("bracket-start", SCM_BOOL_T);
3220 | figure_list br_bass_figure {
3221 $$ = scm_cons ($2, $1);
3226 /**/ { $$ = SCM_BOOL_F; }
3227 | REST { $$ = SCM_BOOL_T; }
3231 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3232 if (!parser->lexer_->is_note_state ())
3233 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3234 if (!SCM_UNBNDP ($2)
3236 || scm_is_number ($4)
3239 || scm_is_pair ($7))
3242 if (scm_is_true ($6))
3243 n = MY_MAKE_MUSIC ("RestEvent", @$);
3245 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3247 n->set_property ("pitch", $1);
3248 if (SCM_UNBNDP ($5))
3249 n->set_property ("duration",
3250 parser->default_duration_.smobbed_copy ());
3252 n->set_property ("duration", $5);
3254 if (scm_is_number ($4))
3256 int q = scm_to_int ($4);
3257 n->set_property ("absolute-octave", scm_from_int (q-1));
3260 if (to_boolean ($3))
3261 n->set_property ("cautionary", SCM_BOOL_T);
3262 if (to_boolean ($2) || to_boolean ($3))
3263 n->set_property ("force-accidental", SCM_BOOL_T);
3264 if (scm_is_pair ($7))
3265 n->set_property ("articulations",
3266 scm_reverse_x ($7, SCM_EOL));
3267 $$ = n->unprotect ();
3270 | new_chord post_events {
3271 if (!parser->lexer_->is_chord_state ())
3272 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3273 if (scm_is_pair ($2)) {
3274 if (unsmob<Pitch> ($1))
3275 $1 = make_chord_elements (@1,
3277 parser->default_duration_.smobbed_copy (),
3280 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3282 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
3283 } else if (!unsmob<Pitch> ($1))
3284 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
3285 // A mere pitch drops through.
3290 DRUM_PITCH optional_notemode_duration {
3291 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3292 n->set_property ("duration", $2);
3293 n->set_property ("drum-type", $1);
3295 $$ = n->unprotect ();
3297 | RESTNAME optional_notemode_duration {
3299 if (ly_scm2string ($1) == "s") {
3301 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3304 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3307 ev->set_property ("duration", $2);
3308 $$ = ev->unprotect ();
3314 if (!parser->lexer_->is_lyric_state ())
3315 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3319 if (!parser->lexer_->is_lyric_state ())
3320 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3326 lyric_element_music:
3327 lyric_element optional_notemode_duration post_events {
3328 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3329 if (scm_is_pair ($3))
3330 unsmob<Music> ($$)->set_property
3331 ("articulations", scm_reverse_x ($3, SCM_EOL));
3335 // Can return a single pitch rather than a list.
3337 steno_tonic_pitch maybe_notemode_duration {
3338 if (SCM_UNBNDP ($2))
3341 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3343 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3344 SCM its = scm_reverse_x ($4, SCM_EOL);
3345 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3353 | chord_items chord_item {
3354 $$ = scm_cons ($2, $$);
3360 $$ = ly_symbol2scm ("chord-colon");
3363 $$ = ly_symbol2scm ("chord-caret");
3365 | CHORD_SLASH steno_tonic_pitch {
3366 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3368 | CHORD_BASS steno_tonic_pitch {
3369 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3378 $$ = scm_reverse_x ($1, SCM_EOL);
3386 step_number { $$ = scm_cons ($1, SCM_EOL); }
3387 | step_numbers '.' step_number {
3388 $$ = scm_cons ($3, $$);
3394 $$ = make_chord_step ($1, 0);
3397 $$ = make_chord_step ($1, SHARP_ALTERATION);
3399 | UNSIGNED CHORD_MINUS {
3400 $$ = make_chord_step ($1, FLAT_ALTERATION);
3408 | unsigned_number '-' unsigned_number {
3409 $$ = scm_cons ($1, $3);
3416 TODO: should deprecate in favor of Scheme?
3420 number_expression '+' number_term {
3421 $$ = scm_sum ($1, $3);
3423 | number_expression '-' number_term {
3424 $$ = scm_difference ($1, $3);
3433 | number_factor '*' number_factor {
3434 $$ = scm_product ($1, $3);
3436 | number_factor '/' number_factor {
3437 $$ = scm_divide ($1, $3);
3442 '-' number_factor { /* %prec UNARY_MINUS */
3443 $$ = scm_difference ($2, SCM_UNDEFINED);
3451 | REAL NUMBER_IDENTIFIER
3453 $$ = scm_product ($1, $2);
3460 | UNSIGNED NUMBER_IDENTIFIER {
3461 $$ = scm_product ($1, $2);
3469 if (!scm_is_integer ($1)
3470 || scm_is_true (scm_negative_p ($1)))
3472 parser->parser_error (@1, _("not an unsigned integer"));
3478 if (!scm_is_integer ($1)
3479 || scm_is_true (scm_negative_p ($1)))
3481 parser->parser_error (@1, _("not an unsigned integer"));
3488 { $$ = SCM_UNDEFINED; }
3491 if (SCM_UNBNDP ($1))
3499 // This precedence rule is rather weird. It triggers when '!' is
3500 // encountered after a pitch, and is used for deciding whether to save
3501 // this instead for a figure modification. This should not actually
3502 // occur in practice as pitches and figures are generated in different
3503 // modes. Using a greedy (%right) precedence makes sure that we don't
3504 // get stuck in a wrong interpretation.
3505 { $$ = SCM_UNDEFINED; } %prec ':'
3508 if (SCM_UNBNDP ($1))
3517 { parser->lexer_->push_markup_state (); }
3520 parser->lexer_->pop_state ();
3526 { parser->lexer_->push_markup_state (); }
3529 parser->lexer_->pop_state ();
3535 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3537 | markup_head_1_list simple_markup
3539 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3540 @2, $1, scm_list_1 ($2)));
3550 if (Text_interface::is_markup ($1))
3551 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3552 else if (Text_interface::is_markup_list ($1))
3553 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3555 parser->parser_error (@1, _ ("not a markup"));
3556 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3563 markup_composed_list {
3566 | markup_uncomposed_list
3569 markup_uncomposed_list:
3570 markup_braced_list {
3573 | markup_command_list {
3574 $$ = scm_list_1 ($1);
3576 | markup_scm MARKUPLIST_IDENTIFIER
3581 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3582 parser->lexer_->push_note_state (nn);
3583 } '{' score_body '}' {
3584 Score *sc = unsmob<Score> ($4);
3585 sc->origin ()->set_spot (@$);
3586 if (sc->defs_.empty ()) {
3587 Output_def *od = get_layout (parser);
3588 sc->add_output_def (od);
3591 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3592 parser->lexer_->pop_state ();
3596 markup_composed_list:
3597 markup_head_1_list markup_uncomposed_list {
3598 $$ = MAKE_SYNTAX ("composed-markup-list",
3604 '{' markup_braced_list_body '}' {
3605 $$ = scm_reverse_x ($2, SCM_EOL);
3609 markup_braced_list_body:
3610 /* empty */ { $$ = SCM_EOL; }
3611 | markup_braced_list_body markup {
3612 $$ = scm_cons ($2, $1);
3614 | markup_braced_list_body markup_list {
3615 $$ = scm_reverse_x ($2, $1);
3619 markup_command_list:
3620 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3621 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3625 markup_command_basic_arguments:
3626 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3627 $$ = scm_cons ($3, $2);
3629 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3630 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3632 | EXPECT_NO_MORE_ARGS {
3637 markup_command_list_arguments:
3638 markup_command_basic_arguments { $$ = $1; }
3639 | EXPECT_MARKUP markup_command_list_arguments markup {
3640 $$ = scm_cons ($3, $2);
3645 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3646 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3651 markup_head_1_item {
3652 $$ = scm_list_1 ($1);
3654 | markup_head_1_list markup_head_1_item {
3655 $$ = scm_cons ($2, $1);
3661 $$ = make_simple_markup ($1);
3664 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3665 parser->lexer_->push_note_state (nn);
3666 } '{' score_body '}' {
3667 Score *sc = unsmob<Score> ($4);
3668 sc->origin ()->set_spot (@$);
3669 if (sc->defs_.empty ()) {
3670 Output_def *od = get_layout (parser);
3671 sc->add_output_def (od);
3674 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3675 parser->lexer_->pop_state ();
3677 | MARKUP_FUNCTION markup_command_basic_arguments {
3678 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3680 | markup_scm MARKUP_IDENTIFIER
3687 markup_head_1_list simple_markup
3689 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3690 @2, $1, scm_list_1 ($2)));
3700 Lily_parser::set_yydebug (bool x)
3706 Lily_parser::do_yyparse ()
3708 return scm_c_with_fluid (ly_lily_module_constant ("%parser"),
3710 do_yyparse_trampoline,
3711 static_cast <void *>(this));
3715 Lily_parser::do_yyparse_trampoline (void *parser)
3717 SCM retval = SCM_UNDEFINED;
3718 yyparse (static_cast <Lily_parser *>(parser), &retval);
3726 It is a little strange to have this function in this file, but
3727 otherwise, we have to import music classes into the lexer.
3731 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3733 if (unsmob<Book> (sid)) {
3734 Book *book = unsmob<Book> (sid)->clone ();
3735 *destination = book->self_scm ();
3738 return BOOK_IDENTIFIER;
3739 } else if (scm_is_number (sid)) {
3741 return NUMBER_IDENTIFIER;
3742 } else if (unsmob<Context_def> (sid))
3744 *destination = unsmob<Context_def> (sid)->clone ()->unprotect ();
3745 return SCM_IDENTIFIER;
3746 } else if (unsmob<Context_mod> (sid)) {
3747 *destination = unsmob<Context_mod> (sid)->smobbed_copy ();
3748 return CONTEXT_MOD_IDENTIFIER;
3749 } else if (Music *mus = unsmob<Music> (sid)) {
3750 mus = mus->clone ();
3751 *destination = mus->self_scm ();
3752 bool is_event = mus->is_mus_type ("post-event");
3754 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3755 } else if (unsmob<Pitch> (sid)) {
3756 *destination = unsmob<Pitch> (sid)->smobbed_copy ();
3757 return PITCH_IDENTIFIER;
3758 } else if (unsmob<Duration> (sid)) {
3759 *destination = unsmob<Duration> (sid)->smobbed_copy ();
3760 return DURATION_IDENTIFIER;
3761 } else if (unsmob<Output_def> (sid)) {
3762 *destination = unsmob<Output_def> (sid)->clone ()->unprotect ();
3763 return SCM_IDENTIFIER;
3764 } else if (unsmob<Score> (sid)) {
3765 *destination = unsmob<Score> (sid)->clone ()->unprotect ();
3766 return SCM_IDENTIFIER;
3773 get_next_unique_context_id ()
3775 return scm_from_ascii_string ("$uniqueContextId");
3780 get_next_unique_lyrics_context_id ()
3782 static int new_context_count;
3784 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3785 return scm_from_ascii_string (s);
3788 // check_scheme_arg checks one argument with a given predicate for use
3789 // in an argument list and throws a syntax error if it is unusable.
3790 // The argument is prepended to the argument list in any case. After
3791 // throwing a syntax error, the argument list is terminated with #f as
3792 // its last cdr in order to mark it as uncallable while not losing
3793 // track of its total length.
3795 // There are a few special considerations: if optional argument disp
3796 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3797 // instead of arg in a prospective error message. This is useful if
3798 // arg is not the actual argument but rather a transformation of it.
3800 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3801 // and an error message using disp is produced unconditionally.
3803 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3804 SCM arg, SCM args, SCM pred, SCM disp)
3806 if (SCM_UNBNDP (arg))
3807 args = scm_cons (disp, args);
3809 args = scm_cons (arg, args);
3810 if (scm_is_true (scm_call_1 (pred, arg)))
3813 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3814 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3815 SCM_UNBNDP (disp) ? arg : disp);
3816 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3820 SCM loc_on_music (Input loc, SCM arg)
3822 if (Music *m = unsmob<Music> (arg))
3826 return m->unprotect ();
3832 try_string_variants (SCM pred, SCM str)
3834 // a matching predicate is always ok
3835 if (scm_is_true (scm_call_1 (pred, str)))
3837 // a symbol may be interpreted as a list of symbols if it helps
3838 if (scm_is_symbol (str)) {
3839 str = scm_list_1 (str);
3840 if (scm_is_true (scm_call_1 (pred, str)))
3842 return SCM_UNDEFINED;
3845 // If this cannot be a string representation of a symbol list,
3848 if (!is_regular_identifier (str, true))
3849 return SCM_UNDEFINED;
3851 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3852 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3853 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3855 // Let's attempt the symbol list interpretation first.
3857 if (scm_is_true (scm_call_1 (pred, str)))
3860 // If there is just one symbol in the list, we might interpret
3861 // it as a single symbol
3863 if (scm_is_null (scm_cdr (str)))
3865 str = scm_car (str);
3866 if (scm_is_true (scm_call_1 (pred, str)))
3870 return SCM_UNDEFINED;
3874 is_regular_identifier (SCM id, bool multiple)
3876 if (!scm_is_string (id))
3879 string str = ly_scm2string (id);
3881 bool middle = false;
3883 for (string::iterator it=str.begin(); it != str.end (); it++)
3886 if ((c >= 'a' && c <= 'z')
3887 || (c >= 'A' && c <= 'Z')
3890 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3899 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3901 if (unsmob<Music> (simple))
3903 if (parser->lexer_->is_note_state ()) {
3904 if (scm_is_symbol (simple)) {
3905 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3906 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3907 n->set_property ("drum-type", simple);
3908 return n->unprotect ();
3910 if (unsmob<Pitch> (simple)) {
3911 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3912 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3913 n->set_property ("pitch", simple);
3914 return n->unprotect ();
3917 } else if (parser->lexer_->is_lyric_state ()) {
3918 if (Text_interface::is_markup (simple))
3919 return MAKE_SYNTAX ("lyric-event", loc, simple,
3920 parser->default_duration_.smobbed_copy ());
3921 } else if (parser->lexer_->is_chord_state ()) {
3922 if (unsmob<Pitch> (simple))
3926 make_chord_elements (loc, simple,
3927 parser->default_duration_.smobbed_copy (),
3934 make_music_with_input (SCM name, Input where)
3936 Music *m = make_music_by_name (name);
3937 m->set_spot (where);
3942 make_simple_markup (SCM a)
3948 make_duration (SCM d, int dots)
3950 int t = scm_to_int (d);
3951 if (t > 0 && (t & (t-1)) == 0)
3952 return Duration (intlog2 (t), dots).smobbed_copy ();
3954 return SCM_UNDEFINED;
3958 make_chord_step (SCM step_scm, Rational alter)
3960 int step = scm_to_int (step_scm);
3963 alter += FLAT_ALTERATION;
3967 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3968 return m.smobbed_copy ();
3973 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3975 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3976 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3977 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3979 unsmob<Music> (scm_car (s))->set_spot (loc);
3985 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3987 Lily_lexer *lex = parser->lexer_;
3991 int tok = lex->pop_extra_token ();
3994 lex->prepare_for_next_token ();
3995 return lex->yylex ();