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"
135 #include "output-def.hh"
136 #include "paper-book.hh"
137 #include "scm-hash.hh"
139 #include "text-interface.hh"
143 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
145 parser->parser_error (*i, s);
148 // The following are somewhat precarious constructs as they may change
149 // the value of the lookahead token. That implies that the lookahead
150 // token must not yet have made an impact on the state stack other
151 // than causing the reduction of the current rule, or switching the
152 // lookahead token while Bison is mulling it over will cause trouble.
154 #define MYBACKUP(Token, Value, Location) \
156 if (yychar != YYEMPTY) \
157 parser->lexer_->push_extra_token \
158 (yylloc, yychar, yylval); \
160 parser->lexer_->push_extra_token \
161 (Location, Token, Value); \
162 parser->lexer_->push_extra_token (Location, BACKUP); \
167 #define MYREPARSE(Location, Pred, Token, Value) \
169 if (yychar != YYEMPTY) \
170 parser->lexer_->push_extra_token \
171 (yylloc, yychar, yylval); \
172 parser->lexer_->push_extra_token \
173 (Location, Token, Value); \
174 parser->lexer_->push_extra_token \
175 (Location, REPARSE, Pred); \
184 #define MY_MAKE_MUSIC(x, spot) \
185 make_music_with_input (ly_symbol2scm (x), \
186 parser->lexer_->override_input (spot))
189 - Don't use lily module, create a new module instead.
190 - delay application of the function
194 syntax_call (void *arg)
196 SCM sarg = reinterpret_cast <SCM> (arg);
197 return scm_apply_0 (scm_car (sarg), scm_cdr (sarg));
200 #define LOWLEVEL_MAKE_SYNTAX(location, args) \
202 (ly_lily_module_constant ("%location"), \
203 parser->lexer_->override_input (location).smobbed_copy (), \
205 reinterpret_cast <void*> (args))
207 /* Syntactic Sugar. */
208 #define MAKE_SYNTAX(name, location, ...) \
209 LOWLEVEL_MAKE_SYNTAX (location, \
210 scm_list_n (ly_lily_module_constant (name), \
211 ##__VA_ARGS__, SCM_UNDEFINED))
213 #define START_MAKE_SYNTAX(name, ...) \
214 scm_list_n (ly_lily_module_constant (name), \
215 ##__VA_ARGS__, SCM_UNDEFINED)
217 #define FINISH_MAKE_SYNTAX(start, location, ...) \
218 LOWLEVEL_MAKE_SYNTAX (location, \
220 (scm_list_2 (start, scm_list_n \
221 (__VA_ARGS__, SCM_UNDEFINED))))
223 SCM get_next_unique_context_id ();
224 SCM get_next_unique_lyrics_context_id ();
231 #define _(x) gettext (x)
235 static Music *make_music_with_input (SCM name, Input where);
236 SCM check_scheme_arg (Lily_parser *parser, Input loc,
237 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
238 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
239 SCM loc_on_music (Input loc, SCM arg);
240 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
241 SCM make_chord_step (SCM step, Rational alter);
242 SCM make_simple_markup (SCM a);
243 SCM make_duration (SCM t, int dots = 0);
244 bool is_regular_identifier (SCM id, bool multiple=false);
245 SCM try_string_variants (SCM pred, SCM str);
246 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
250 /* The third option is an alias that will be used to display the
251 syntax error. Bison CVS now correctly handles backslash escapes.
253 FIXME: Bison needs to translate some of these, eg, STRING.
257 /* Keyword tokens with plain escaped name. */
258 %token END_OF_FILE 0 "end of input"
259 %token ACCEPTS "\\accepts"
260 %token ADDLYRICS "\\addlyrics"
261 %token ALIAS "\\alias"
262 %token ALTERNATIVE "\\alternative"
264 %token BOOKPART "\\bookpart"
265 %token CHANGE "\\change"
266 %token CHORDMODE "\\chordmode"
267 %token CHORDS "\\chords"
268 %token CONSISTS "\\consists"
269 %token CONTEXT "\\context"
270 %token DEFAULT "\\default"
271 %token DEFAULTCHILD "\\defaultchild"
272 %token DENIES "\\denies"
273 %token DESCRIPTION "\\description"
274 %token DRUMMODE "\\drummode"
275 %token DRUMS "\\drums"
276 %token FIGUREMODE "\\figuremode"
277 %token FIGURES "\\figures"
278 %token HEADER "\\header"
279 %token INVALID "\\version-error"
280 %token LAYOUT "\\layout"
281 %token LYRICMODE "\\lyricmode"
282 %token LYRICS "\\lyrics"
283 %token LYRICSTO "\\lyricsto"
284 %token MARKUP "\\markup"
285 %token MARKUPLIST "\\markuplist"
288 %token NOTEMODE "\\notemode"
289 %token OVERRIDE "\\override"
290 %token PAPER "\\paper"
291 %token REMOVE "\\remove"
292 %token REPEAT "\\repeat"
294 %token REVERT "\\revert"
295 %token SCORE "\\score"
296 %token SCORELINES "\\score-lines"
297 %token SEQUENTIAL "\\sequential"
299 %token SIMULTANEOUS "\\simultaneous"
300 %token TEMPO "\\tempo"
302 %token UNSET "\\unset"
305 /* Keyword token exceptions. */
306 %token NEWCONTEXT "\\new"
309 /* Other string tokens. */
311 %token CHORD_BASS "/+"
312 %token CHORD_CARET "^"
313 %token CHORD_COLON ":"
314 %token CHORD_MINUS "-"
315 %token CHORD_SLASH "/"
316 %token ANGLE_OPEN "<"
317 %token ANGLE_CLOSE ">"
318 %token DOUBLE_ANGLE_OPEN "<<"
319 %token DOUBLE_ANGLE_CLOSE ">>"
320 %token E_BACKSLASH "\\"
321 %token E_EXCLAMATION "\\!"
326 If we give names, Bison complains.
328 %token FIGURE_CLOSE /* "\\>" */
329 %token FIGURE_OPEN /* "\\<" */
330 %token FIGURE_SPACE "_"
333 %token MULTI_MEASURE_REST
339 /* Artificial tokens, for more generic function syntax */
340 %token EXPECT_MARKUP "markup?"
341 %token EXPECT_SCM "scheme?"
342 %token BACKUP "(backed-up?)"
343 %token REPARSE "(reparsed?)"
344 %token EXPECT_MARKUP_LIST "markup-list?"
345 %token EXPECT_OPTIONAL "optional?"
346 /* After the last argument. */
347 %token EXPECT_NO_MORE_ARGS;
349 /* An artificial token for parsing embedded Lilypond */
350 %token EMBEDDED_LILY "#{"
352 %token BOOK_IDENTIFIER
353 %token CHORD_MODIFIER
354 %token CHORD_REPETITION
355 %token CONTEXT_MOD_IDENTIFIER
357 %token PITCH_IDENTIFIER
358 %token DURATION_IDENTIFIER
359 %token EVENT_IDENTIFIER
360 %token EVENT_FUNCTION
363 %token MARKUP_FUNCTION
364 %token MARKUP_LIST_FUNCTION
365 %token MARKUP_IDENTIFIER
366 %token MARKUPLIST_IDENTIFIER
367 %token MUSIC_FUNCTION
368 %token MUSIC_IDENTIFIER
369 %token NOTENAME_PITCH
370 %token NUMBER_IDENTIFIER
375 %token SCM_IDENTIFIER
379 %token TONICNAME_PITCH
383 /* We don't assign precedence to / and *, because we might need varied
384 prec levels in different prods */
393 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
394 parser->lexer_->push_note_state (nn);
395 } embedded_lilypond {
396 parser->lexer_->pop_state ();
401 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
402 | lilypond toplevel_expression {
404 | lilypond assignment {
407 parser->error_level_ = 1;
410 parser->error_level_ = 1;
417 parser->lexer_->add_scope (get_header (parser));
419 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
422 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
423 scm_call_1 (proc, $1);
426 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
427 scm_call_1 (proc, $1);
430 SCM proc = parser->lexer_->lookup_identifier
431 (unsmob<Book>($1)->paper_
432 ? "toplevel-book-handler"
433 : "toplevel-bookpart-handler");
434 scm_call_1 (proc, $1);
437 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
438 scm_call_1 (proc, $1);
441 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
442 scm_call_1 (proc, $1);
445 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
446 scm_call_1 (proc, scm_list_1 ($1));
449 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
450 scm_call_1 (proc, $1);
453 // Evaluate and ignore #xxx, as opposed to \xxx
454 parser->lexer_->eval_scm_token ($1, @1);
456 | embedded_scm_active
458 SCM out = SCM_UNDEFINED;
459 if (Text_interface::is_markup ($1))
460 out = scm_list_1 ($1);
461 else if (Text_interface::is_markup_list ($1))
463 if (scm_is_pair (out))
465 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
466 scm_call_1 (proc, out);
467 } else if (unsmob<Score> ($1))
469 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
470 scm_call_1 (proc, $1);
471 } else if (Output_def * od = unsmob<Output_def> ($1)) {
474 if (to_boolean (od->c_variable ("is-paper")))
475 id = ly_symbol2scm ("$defaultpaper");
476 else if (to_boolean (od->c_variable ("is-midi")))
477 id = ly_symbol2scm ("$defaultmidi");
478 else if (to_boolean (od->c_variable ("is-layout")))
479 id = ly_symbol2scm ("$defaultlayout");
481 parser->lexer_->set_identifier (id, $1);
482 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
483 parser->parser_error (@1, _("bad expression type"));
487 Output_def * od = unsmob<Output_def> ($1);
489 if (to_boolean (od->c_variable ("is-paper")))
490 id = ly_symbol2scm ("$defaultpaper");
491 else if (to_boolean (od->c_variable ("is-midi")))
492 id = ly_symbol2scm ("$defaultmidi");
493 else if (to_boolean (od->c_variable ("is-layout")))
494 id = ly_symbol2scm ("$defaultlayout");
496 parser->lexer_->set_identifier (id, $1);
503 $$ = parser->lexer_->eval_scm_token ($1, @1);
513 embedded_scm_bare_arg:
517 $$ = parser->lexer_->eval_scm_token ($1, @1);
521 | context_modification
523 | context_def_spec_block
529 /* The generic version may end in music, or not */
536 /* embedded_scm_arg is _not_ casting pitches to music by default, this
537 * has to be done by the function itself. Note that this may cause
538 * the results of scm_function_call or embedded_scm_bare_arg to be
539 * turned into music from pitches as well. Note that this creates a
540 * distinctly awkward situation for calculated drum pitches. Those
541 * are at the current point of time rejected as music constituents as
542 * they can't be distinguished from "proper" symbols.
546 embedded_scm_bare_arg
552 SCM_FUNCTION function_arglist {
553 $$ = MAKE_SYNTAX ("music-function", @$,
558 embedded_lilypond_number:
559 '-' embedded_lilypond_number
561 $$ = scm_difference ($2, SCM_UNDEFINED);
564 | UNSIGNED NUMBER_IDENTIFIER
566 $$ = scm_product ($1, $2);
573 // FIXME: @$ does not contain a useful source location
574 // for empty rules, and the only token in the whole
575 // production, EMBEDDED_LILY, is synthetic and also
576 // contains no source location.
577 $$ = MAKE_SYNTAX ("void-music", @$);
579 | identifier_init_nonumber
580 | embedded_lilypond_number
581 | post_event post_events
583 $$ = scm_reverse_x ($2, SCM_EOL);
584 if (Music *m = unsmob<Music> ($1))
586 if (m->is_mus_type ("post-event-wrapper"))
588 (scm_list_2 (m->get_property ("elements"),
591 $$ = scm_cons ($1, $$);
594 && scm_is_null (scm_cdr ($$)))
598 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
599 m->set_property ("elements", $$);
600 $$ = m->unprotect ();
603 | multiplied_duration
604 | music_embedded music_embedded music_list {
605 $3 = scm_reverse_x ($3, SCM_EOL);
606 if (unsmob<Music> ($2))
607 $3 = scm_cons ($2, $3);
608 if (unsmob<Music> ($1))
609 $3 = scm_cons ($1, $3);
610 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
613 parser->error_level_ = 1;
614 $$ = SCM_UNSPECIFIED;
616 | INVALID embedded_lilypond {
617 parser->error_level_ = 1;
623 lilypond_header_body:
624 /* empty */ { $$ = SCM_UNSPECIFIED; }
625 | lilypond_header_body assignment {
628 | lilypond_header_body embedded_scm {
634 HEADER '{' lilypond_header_body '}' {
635 $$ = parser->lexer_->remove_scope ();
647 assignment_id '=' identifier_init {
648 parser->lexer_->set_identifier ($1, $3);
649 $$ = SCM_UNSPECIFIED;
651 | assignment_id property_path '=' identifier_init {
652 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
653 parser->lexer_->set_identifier (path, $4);
654 $$ = SCM_UNSPECIFIED;
656 | assignment_id '.' property_path '=' identifier_init {
657 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
658 parser->lexer_->set_identifier (path, $5);
659 $$ = SCM_UNSPECIFIED;
665 identifier_init_nonumber
667 | post_event_nofinger post_events
669 $$ = scm_reverse_x ($2, SCM_EOL);
670 if (Music *m = unsmob<Music> ($1))
672 if (m->is_mus_type ("post-event-wrapper"))
674 (scm_list_2 (m->get_property ("elements"),
677 $$ = scm_cons ($1, $$);
680 && scm_is_null (scm_cdr ($$)))
684 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
685 m->set_property ("elements", $$);
686 $$ = m->unprotect ();
691 identifier_init_nonumber:
696 | context_def_spec_block
703 | context_modification
706 context_def_spec_block:
707 CONTEXT '{' context_def_spec_body '}'
710 Context_def *td = unsmob<Context_def> ($$);
712 $$ = Context_def::make_scm ();
713 td = unsmob<Context_def> ($$);
715 td->origin ()->set_spot (@$);
723 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
724 parser->lexer_->push_note_state (nn);
728 parser->lexer_->pop_state ();
734 context_def_spec_body:
736 $$ = SCM_UNSPECIFIED;
738 | context_def_spec_body context_mod {
739 if (!SCM_UNBNDP ($2)) {
740 Context_def *td = unsmob<Context_def> ($$);
742 $$ = Context_def::make_scm ();
743 td = unsmob<Context_def> ($$);
745 unsmob<Context_def> ($$)->add_context_mod ($2);
748 | context_def_spec_body context_modification {
749 Context_def *td = unsmob<Context_def> ($$);
751 $$ = Context_def::make_scm ();
752 td = unsmob<Context_def> ($$);
754 SCM new_mods = unsmob<Context_mod> ($2)->get_mods ();
755 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
756 td->add_context_mod (scm_car (m));
759 | context_def_spec_body context_mod_arg {
760 Context_def *td = unsmob<Context_def> ($1);
761 if (scm_is_eq ($2, SCM_UNSPECIFIED))
763 else if (!td && unsmob<Context_def> ($2))
767 $$ = Context_def::make_scm ();
768 td = unsmob<Context_def> ($$);
770 if (unsmob<Music> ($2)) {
771 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
772 $2 = scm_call_1 (proc, $2);
774 if (Context_mod *cm = unsmob<Context_mod> ($2)) {
775 for (SCM m = cm->get_mods (); scm_is_pair (m); m = scm_cdr (m)) {
776 td->add_context_mod (scm_car (m));
779 parser->parser_error (@2, _ ("not a context mod"));
787 BOOK '{' book_body '}' {
789 unsmob<Book> ($$)->origin ()->set_spot (@$);
791 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
796 * Use 'handlers' like for toplevel-* stuff?
797 * grok \layout and \midi? */
800 Book *book = new Book;
801 init_papers (parser);
802 book->paper_ = dynamic_cast<Output_def*> (unsmob<Output_def> (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
803 book->paper_->unprotect ();
804 push_paper (parser, book->paper_);
805 book->header_ = get_header (parser);
806 $$ = book->unprotect ();
807 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
810 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
812 | book_body paper_block {
813 unsmob<Book> ($1)->paper_ = unsmob<Output_def> ($2);
814 set_paper (parser, unsmob<Output_def> ($2));
816 | book_body bookpart_block {
817 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
818 scm_call_2 (proc, $1, $2);
820 | book_body score_block {
821 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
822 scm_call_2 (proc, $1, $2);
824 | book_body composite_music {
825 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
826 scm_call_2 (proc, $1, $2);
828 | book_body full_markup {
829 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
830 scm_call_2 (proc, $1, scm_list_1 ($2));
832 | book_body full_markup_list {
833 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
834 scm_call_2 (proc, $1, $2);
836 | book_body SCM_TOKEN {
837 // Evaluate and ignore #xxx, as opposed to \xxx
838 parser->lexer_->eval_scm_token ($2, @2);
840 | book_body embedded_scm_active
842 SCM out = SCM_UNDEFINED;
843 if (Text_interface::is_markup ($2))
844 out = scm_list_1 ($2);
845 else if (Text_interface::is_markup_list ($2))
847 if (scm_is_pair (out))
849 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
850 scm_call_2 (proc, $1, out);
851 } else if (unsmob<Score> ($2))
853 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
854 scm_call_2 (proc, $1, $2);
855 } else if (Output_def *od = unsmob<Output_def> ($2)) {
858 if (to_boolean (od->c_variable ("is-paper")))
859 id = ly_symbol2scm ("$defaultpaper");
860 else if (to_boolean (od->c_variable ("is-midi")))
861 id = ly_symbol2scm ("$defaultmidi");
862 else if (to_boolean (od->c_variable ("is-layout")))
863 id = ly_symbol2scm ("$defaultlayout");
865 parser->lexer_->set_identifier (id, $2);
866 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
867 parser->parser_error (@2, _("bad expression type"));
871 parser->lexer_->add_scope (unsmob<Book> ($1)->header_);
874 Book *book = unsmob<Book> ($1);
876 book->scores_ = SCM_EOL;
877 book->bookparts_ = SCM_EOL;
882 BOOKPART '{' bookpart_body '}' {
884 unsmob<Book> ($$)->origin ()->set_spot (@$);
885 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
891 Book *book = new Book;
892 $$ = book->unprotect ();
893 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
896 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
898 | bookpart_body paper_block {
899 unsmob<Book> ($$)->paper_ = unsmob<Output_def> ($2);
901 | bookpart_body score_block {
902 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
903 scm_call_2 (proc, $1, $2);
905 | bookpart_body composite_music {
906 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
907 scm_call_2 (proc, $1, $2);
909 | bookpart_body full_markup {
910 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
911 scm_call_2 (proc, $1, scm_list_1 ($2));
913 | bookpart_body full_markup_list {
914 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
915 scm_call_2 (proc, $1, $2);
917 | bookpart_body SCM_TOKEN {
918 // Evaluate and ignore #xxx, as opposed to \xxx
919 parser->lexer_->eval_scm_token ($2, @2);
921 | bookpart_body embedded_scm_active
923 SCM out = SCM_UNDEFINED;
924 if (Text_interface::is_markup ($2))
925 out = scm_list_1 ($2);
926 else if (Text_interface::is_markup_list ($2))
928 if (scm_is_pair (out))
930 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
931 scm_call_2 (proc, $1, out);
932 } else if (unsmob<Score> ($2))
934 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
935 scm_call_2 (proc, $1, $2);
936 } else if (Output_def *od = unsmob<Output_def> ($2)) {
939 if (to_boolean (od->c_variable ("is-paper")))
940 id = ly_symbol2scm ("$defaultpaper");
941 else if (to_boolean (od->c_variable ("is-midi")))
942 id = ly_symbol2scm ("$defaultmidi");
943 else if (to_boolean (od->c_variable ("is-layout")))
944 id = ly_symbol2scm ("$defaultlayout");
946 parser->lexer_->set_identifier (id, $2);
947 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
948 parser->parser_error (@2, _("bad expression type"));
952 Book *book = unsmob<Book> ($1);
953 if (!ly_is_module (book->header_))
954 book->header_ = ly_make_module (false);
955 parser->lexer_->add_scope (book->header_);
957 | bookpart_body error {
958 Book *book = unsmob<Book> ($1);
960 book->scores_ = SCM_EOL;
965 SCORE '{' score_body '}' {
966 unsmob<Score> ($3)->origin ()->set_spot (@$);
973 if (!unsmob<Score> ($1)) {
974 parser->parser_error (@1, _("Missing music in \\score"));
975 $$ = (new Score)->unprotect ();
976 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
978 unsmob<Score> ($$)->set_header (scm_car ($1));
981 for (SCM p = scm_reverse_x ($1, SCM_EOL);
982 scm_is_pair (p); p = scm_cdr (p))
985 add_output_def (unsmob<Output_def> (scm_car (p)));
990 unsmob<Score> ($$)->error_found_ = true;
1005 | score_items score_item
1007 Output_def *od = unsmob<Output_def> ($2);
1009 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1011 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1013 $2 = SCM_UNSPECIFIED;
1015 } else if (!unsmob<Score> ($$)) {
1016 if (unsmob<Music> ($2)) {
1017 SCM scorify = ly_lily_module_constant ("scorify-music");
1018 $2 = scm_call_1 (scorify, $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 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1603 $$ = try_string_variants (sym_l_p, $1);
1604 if (SCM_UNBNDP ($$)) {
1605 parser->parser_error (@1, _("not a symbol"));
1608 $$ = scm_reverse ($$);
1613 symbol_list_element:
1619 function_arglist_nonbackup:
1620 function_arglist_common
1621 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1623 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1625 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1627 SCM n = scm_difference ($5, SCM_UNDEFINED);
1628 if (scm_is_true (scm_call_1 ($2, n)))
1629 $$ = scm_cons (n, $3);
1631 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1632 t->set_property ("digit", $5);
1633 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1637 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1639 $$ = check_scheme_arg (parser, @4,
1640 scm_difference ($5, SCM_UNDEFINED),
1643 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1645 $$ = check_scheme_arg (parser, @4,
1646 scm_difference ($5, SCM_UNDEFINED),
1649 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1651 if (scm_is_true (scm_call_1 ($2, $4)))
1652 $$ = scm_cons ($4, $3);
1654 $$ = check_scheme_arg (parser, @4,
1655 make_music_from_simple
1659 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1661 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1663 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1665 if (scm_is_true (scm_call_1 ($2, $3)))
1666 $$ = scm_cons ($3, $1);
1668 $$ = check_scheme_arg (parser, @3,
1669 make_music_from_simple
1673 | function_arglist_nonbackup_reparse REPARSE duration_length
1675 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1677 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1679 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1681 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1683 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1685 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1687 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1689 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1691 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1695 function_arglist_nonbackup_reparse:
1696 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1699 SCM res = try_string_variants ($2, $4);
1700 if (!SCM_UNBNDP (res))
1701 if (scm_is_pair (res))
1702 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1704 MYREPARSE (@4, $2, SCM_ARG, res);
1705 else if (scm_is_true
1707 ($2, make_music_from_simple
1709 MYREPARSE (@4, $2, STRING, $4);
1711 MYREPARSE (@4, $2, SCM_ARG, $4);
1713 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1718 ($2, make_music_from_simple
1720 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1722 MYREPARSE (@4, $2, SCM_ARG, $4);
1724 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1729 ($2, make_music_from_simple
1731 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1733 MYREPARSE (@4, $2, SCM_ARG, $4);
1735 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1738 SCM res = try_string_variants ($2, $4);
1739 if (!SCM_UNBNDP (res))
1740 if (scm_is_pair (res))
1741 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1743 MYREPARSE (@4, $2, SCM_ARG, res);
1744 else if (scm_is_true
1746 ($2, make_music_from_simple
1748 MYREPARSE (@4, $2, STRING, $4);
1750 MYREPARSE (@4, $2, SCM_ARG, $4);
1752 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1755 if (scm_is_true (scm_call_1 ($2, $4)))
1756 MYREPARSE (@4, $2, SCM_ARG, $4);
1757 else if (scm_is_true
1759 ($2, make_music_from_simple
1761 MYREPARSE (@4, $2, STRING, $4);
1763 MYREPARSE (@4, $2, SCM_ARG, $4);
1765 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1768 if (scm_is_true (scm_call_1 ($2, $4)))
1769 MYREPARSE (@4, $2, REAL, $4);
1771 SCM d = make_duration ($4);
1772 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1773 MYREPARSE (@4, $2, REAL, $4); // trigger error
1775 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1778 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1780 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1785 // function_arglist_backup can't occur at the end of an argument
1787 function_arglist_backup:
1788 function_arglist_common
1789 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1791 if (scm_is_true (scm_call_1 ($2, $4)))
1792 $$ = scm_cons ($4, $3);
1794 $$ = make_music_from_simple (parser, @4, $4);
1795 if (scm_is_true (scm_call_1 ($2, $$)))
1796 $$ = scm_cons ($$, $3);
1799 $$ = scm_cons (loc_on_music (@3, $1), $3);
1800 MYBACKUP (SCM_ARG, $4, @4);
1804 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1806 if (scm_is_true (scm_call_1 ($2, $4)))
1808 $$ = scm_cons ($4, $3);
1810 $$ = scm_cons (loc_on_music (@3, $1), $3);
1811 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1814 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1818 ($2, make_music_from_simple
1822 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1823 } else if (scm_is_true (scm_call_1 ($2, $4)))
1824 $$ = scm_cons ($4, $3);
1826 $$ = scm_cons (loc_on_music (@3, $1), $3);
1827 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1830 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1834 ($2, make_music_from_simple
1838 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1839 } else if (scm_is_true (scm_call_1 ($2, $4)))
1840 $$ = scm_cons ($4, $3);
1842 $$ = scm_cons (loc_on_music (@3, $1), $3);
1843 MYBACKUP (TONICNAME_PITCH, $4, @4);
1846 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1848 if (scm_is_true (scm_call_1 ($2, $4)))
1849 $$ = scm_cons ($4, $3);
1851 $$ = scm_cons (loc_on_music (@3, $1), $3);
1852 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1855 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1857 if (scm_is_true (scm_call_1 ($2, $4)))
1859 MYREPARSE (@4, $2, REAL, $4);
1862 SCM d = make_duration ($4);
1863 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1865 $$ = scm_cons (loc_on_music (@3, $1), $3);
1866 MYBACKUP (UNSIGNED, $4, @4);
1868 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1873 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1875 if (scm_is_true (scm_call_1 ($2, $4)))
1878 MYREPARSE (@4, $2, REAL, $4);
1880 $$ = scm_cons (loc_on_music (@3, $1), $3);
1881 MYBACKUP (REAL, $4, @4);
1884 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1886 if (scm_is_true (scm_call_1 ($2, $4)))
1888 $$ = scm_cons ($4, $3);
1890 $$ = scm_cons (loc_on_music (@3, $1), $3);
1891 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1894 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1896 SCM n = scm_difference ($5, SCM_UNDEFINED);
1897 if (scm_is_true (scm_call_1 ($2, n))) {
1899 MYREPARSE (@5, $2, REAL, n);
1901 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1902 t->set_property ("digit", $5);
1903 $$ = t->unprotect ();
1904 if (scm_is_true (scm_call_1 ($2, $$)))
1905 $$ = scm_cons ($$, $3);
1907 $$ = scm_cons (loc_on_music (@3, $1), $3);
1908 MYBACKUP (UNSIGNED, $5, @5);
1909 parser->lexer_->push_extra_token (@4, '-');
1913 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1915 SCM n = scm_difference ($5, SCM_UNDEFINED);
1916 if (scm_is_true (scm_call_1 ($2, n))) {
1917 MYREPARSE (@5, $2, REAL, n);
1920 $$ = scm_cons (loc_on_music (@3, $1), $3);
1921 MYBACKUP (REAL, n, @5);
1924 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1926 SCM n = scm_difference ($5, SCM_UNDEFINED);
1927 if (scm_is_true (scm_call_1 ($2, n))) {
1928 $$ = scm_cons (n, $3);
1930 $$ = scm_cons (loc_on_music (@3, $1), $3);
1931 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1934 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1936 if (scm_is_true (scm_call_1 ($2, $4)))
1938 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1941 $$ = scm_cons (loc_on_music (@3, $1), $3);
1942 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1945 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1947 SCM res = try_string_variants ($2, $4);
1948 if (!SCM_UNBNDP (res))
1949 if (scm_is_pair (res)) {
1951 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1954 $$ = scm_cons (res, $3);
1956 $$ = scm_cons (loc_on_music (@3, $1), $3);
1957 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1960 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1962 SCM res = try_string_variants ($2, $4);
1963 if (!SCM_UNBNDP (res))
1964 if (scm_is_pair (res)) {
1966 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1969 $$ = scm_cons (res, $3);
1971 $$ = scm_cons (loc_on_music (@3, $1), $3);
1972 MYBACKUP (STRING, $4, @4);
1975 | function_arglist_backup REPARSE pitch_or_music
1977 if (scm_is_true (scm_call_1 ($2, $3)))
1978 $$ = scm_cons ($3, $1);
1980 $$ = check_scheme_arg (parser, @3,
1981 make_music_from_simple
1985 | function_arglist_backup REPARSE bare_number_common
1987 $$ = check_scheme_arg (parser, @3,
1990 | function_arglist_backup REPARSE duration_length
1992 $$ = check_scheme_arg (parser, @3,
1995 | function_arglist_backup REPARSE symbol_list_arg
1997 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2002 function_arglist_nonbackup
2003 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2005 $$ = scm_cons (loc_on_music (@4, $1), $3);
2009 function_arglist_skip_nonbackup:
2010 function_arglist_nonbackup
2011 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
2013 $$ = scm_cons (loc_on_music (@3, $1), $3);
2017 function_arglist_common:
2018 EXPECT_NO_MORE_ARGS {
2021 | EXPECT_SCM function_arglist_optional embedded_scm_arg
2023 if (scm_is_true (scm_call_1 ($1, $3)))
2024 $$ = scm_cons ($3, $2);
2026 $$ = check_scheme_arg (parser, @3,
2027 make_music_from_simple
2031 | EXPECT_SCM function_arglist_optional bare_number_common
2033 $$ = check_scheme_arg (parser, @3,
2036 | EXPECT_SCM function_arglist_optional post_event_nofinger
2038 $$ = check_scheme_arg (parser, @3,
2041 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2043 SCM n = scm_difference ($4, SCM_UNDEFINED);
2044 $$ = check_scheme_arg (parser, @4, n, $2, $1);
2046 | function_arglist_common_reparse REPARSE SCM_ARG
2048 $$ = check_scheme_arg (parser, @3,
2051 | function_arglist_common_reparse REPARSE lyric_element_music
2053 $$ = check_scheme_arg (parser, @3,
2056 | function_arglist_common_reparse REPARSE pitch_or_music
2058 if (scm_is_true (scm_call_1 ($2, $3)))
2059 $$ = scm_cons ($3, $1);
2061 $$ = check_scheme_arg (parser, @3,
2062 make_music_from_simple
2066 | function_arglist_common_reparse REPARSE bare_number_common
2068 $$ = check_scheme_arg (parser, @3,
2071 | function_arglist_common_reparse REPARSE duration_length
2073 $$ = check_scheme_arg (parser, @3,
2076 | function_arglist_common_reparse REPARSE symbol_list_arg
2078 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2082 function_arglist_common_reparse:
2083 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2086 SCM res = try_string_variants ($1, $3);
2087 if (!SCM_UNBNDP (res))
2088 if (scm_is_pair (res))
2089 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2091 MYREPARSE (@3, $1, SCM_ARG, res);
2092 else if (scm_is_true
2094 ($1, make_music_from_simple (parser, @3, $3))))
2095 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2097 // This is going to flag a syntax error, we
2098 // know the predicate to be false.
2099 MYREPARSE (@3, $1, SCM_ARG, $3);
2101 | EXPECT_SCM function_arglist_optional pitch
2106 ($1, make_music_from_simple
2108 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2110 MYREPARSE (@3, $1, SCM_ARG, $3);
2112 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2117 ($1, make_music_from_simple
2119 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2121 MYREPARSE (@3, $1, SCM_ARG, $3);
2123 | EXPECT_SCM function_arglist_optional STRING
2126 SCM res = try_string_variants ($1, $3);
2127 if (!SCM_UNBNDP (res))
2128 if (scm_is_pair (res))
2129 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2131 MYREPARSE (@3, $1, SCM_ARG, res);
2132 else if (scm_is_true
2134 ($1, make_music_from_simple (parser, @3, $3))))
2135 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2137 // This is going to flag a syntax error, we
2138 // know the predicate to be false.
2139 MYREPARSE (@3, $1, SCM_ARG, $3);
2141 | EXPECT_SCM function_arglist_optional full_markup
2144 if (scm_is_true (scm_call_1 ($1, $3)))
2145 MYREPARSE (@3, $1, SCM_ARG, $3);
2146 else if (scm_is_true
2148 ($1, make_music_from_simple (parser, @3, $3))))
2149 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2151 // This is going to flag a syntax error, we
2152 // know the predicate to be false.
2153 MYREPARSE (@3, $1, SCM_ARG, $3);
2155 | EXPECT_SCM function_arglist_optional UNSIGNED
2158 if (scm_is_true (scm_call_1 ($1, $3)))
2159 MYREPARSE (@3, $1, REAL, $3);
2161 SCM d = make_duration ($3);
2162 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
2163 MYREPARSE (@3, $1, REAL, $3);
2165 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2168 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2171 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2173 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2176 SCM n = scm_difference ($4, SCM_UNDEFINED);
2177 if (scm_is_true (scm_call_1 ($1, n)))
2178 MYREPARSE (@4, $1, REAL, n);
2180 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2181 t->set_property ("digit", $4);
2182 SCM m = t->unprotect ();
2183 if (scm_is_true (scm_call_1 ($1, m)))
2184 MYREPARSE (@4, $1, SCM_ARG, m);
2186 MYREPARSE (@4, $1, SCM_ARG, $4);
2189 | EXPECT_SCM function_arglist_optional '-' REAL
2192 SCM n = scm_difference ($4, SCM_UNDEFINED);
2193 MYREPARSE (@4, $1, REAL, n);
2197 function_arglist_optional:
2198 function_arglist_backup
2199 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2201 $$ = scm_cons (loc_on_music (@4, $1), $3);
2203 | function_arglist_skip_backup BACKUP
2206 function_arglist_skip_backup:
2207 function_arglist_backup
2208 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2210 $$ = scm_cons (loc_on_music (@3, $1), $3);
2214 music_function_call:
2215 MUSIC_FUNCTION function_arglist {
2216 $$ = MAKE_SYNTAX ("music-function", @$,
2223 /**/ { $$ = SCM_EOL; }
2224 | '=' simple_string {
2229 // We must not have lookahead tokens parsed in lyric mode. In order
2230 // to save confusion, we take almost the same set as permitted with
2231 // \lyricmode and/or \lyrics. However, music identifiers are also
2232 // allowed, and they obviously do not require switching into lyrics
2233 // mode for parsing.
2237 parser->lexer_->push_lyric_state ();
2238 } grouped_music_list
2240 parser->lexer_->pop_state ();
2247 mode_changing_head grouped_music_list {
2248 if (scm_is_eq ($1, ly_symbol2scm ("chords")))
2250 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2256 parser->lexer_->pop_state ();
2258 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2259 Context_mod *ctxmod = unsmob<Context_mod> ($2);
2262 mods = ctxmod->get_mods ();
2263 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2264 if (scm_is_eq ($1, ly_symbol2scm ("ChordNames")))
2266 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2268 parser->lexer_->pop_state ();
2274 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2275 parser->lexer_->push_note_state (nn);
2277 $$ = ly_symbol2scm ("notes");
2281 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2282 parser->lexer_->push_note_state (nn);
2284 $$ = ly_symbol2scm ("drums");
2287 parser->lexer_->push_figuredbass_state ();
2289 $$ = ly_symbol2scm ("figures");
2292 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2293 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2294 nn = parser->lexer_->lookup_identifier ("pitchnames");
2295 parser->lexer_->push_chord_state (nn);
2296 $$ = ly_symbol2scm ("chords");
2300 { parser->lexer_->push_lyric_state ();
2301 $$ = ly_symbol2scm ("lyrics");
2305 mode_changing_head_with_context:
2307 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2308 parser->lexer_->push_note_state (nn);
2310 $$ = ly_symbol2scm ("DrumStaff");
2313 parser->lexer_->push_figuredbass_state ();
2315 $$ = ly_symbol2scm ("FiguredBass");
2318 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2319 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2320 nn = parser->lexer_->lookup_identifier ("pitchnames");
2321 parser->lexer_->push_chord_state (nn);
2322 $$ = ly_symbol2scm ("ChordNames");
2325 { parser->lexer_->push_lyric_state ();
2326 $$ = ly_symbol2scm ("Lyrics");
2331 CHANGE symbol '=' simple_string {
2332 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2339 $$ = scm_reverse_x ($1, SCM_EOL);
2341 | symbol_list_rev property_path {
2342 $$ = scm_reverse_x ($1, $2);
2348 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2351 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2353 | OVERRIDE property_path '=' scalar {
2354 if (scm_ilength ($2) < 2) {
2355 parser->parser_error (@2, _("bad grob property path"));
2358 $$ = scm_cons (ly_symbol2scm ("push"),
2359 scm_cons2 (scm_car ($2),
2364 | REVERT revert_arg {
2365 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2369 // This is all quite awkward for the sake of substantial backward
2370 // compatibility while at the same time allowing a more "natural" form
2371 // of specification not separating grob specification from grob
2372 // property path. The purpose of this definition of revert_arg is to
2373 // allow the symbol list which specifies grob and property to revert
2374 // to be optionally be split into two parts after the grob (which in
2375 // this case is just the first element of the list). symbol_list_part
2376 // is only one path component, but it can be parsed without lookahead,
2377 // so we can follow it with a synthetic BACKUP token when needed. If
2378 // the first symbol_list_part already contains multiple elements (only
2379 // possible if a Scheme expression provides them), we just parse for
2380 // additional elements introduced by '.', which is what the
2381 // SYMBOL_LIST backup in connection with the immediately following
2382 // rule using symbol_list_arg does.
2384 // As long as we don't have our coffers filled with both grob and at
2385 // least one grob property specification, the rest of the required
2386 // symbol list chain may be provided either with or without a leading
2387 // dot. This is for both allowing the traditional
2388 // \revert Accidental #'color
2389 // as well as well as the "naive" form
2390 // \revert Accidental.color
2393 revert_arg_backup BACKUP symbol_list_arg
2402 if (scm_is_null ($1)
2403 || scm_is_null (scm_cdr ($1)))
2404 MYBACKUP (SCM_ARG, $1, @1);
2406 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2410 // revert_arg_part delivers results in reverse
2413 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2415 $$ = scm_append_x (scm_list_2 ($5, $3));
2417 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2419 $$ = scm_append_x (scm_list_2 ($4, $3));
2424 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2425 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2427 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2428 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2429 | DENIES { $$ = ly_symbol2scm ("denies"); }
2431 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2432 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2433 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2434 | NAME { $$ = ly_symbol2scm ("context-name"); }
2438 property_operation { $$ = $1; }
2439 | context_def_mod STRING {
2440 $$ = scm_list_2 ($1, $2);
2442 | context_def_mod embedded_scm
2444 if (!scm_is_string ($2)
2445 && ly_symbol2scm ("consists") != $1
2446 && ly_symbol2scm ("remove") != $1)
2449 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2453 $$ = scm_list_2 ($1, $2);
2458 // If defined, at least two members.
2462 SCM l = scm_reverse_x ($1, SCM_EOL);
2465 (scm_object_property (scm_car (l),
2466 ly_symbol2scm ("is-grob?"))))
2467 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2468 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2469 parser->parser_error (@1, _ ("bad grob property path"));
2476 // If defined, at least three members
2480 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2482 parser->parser_error (@1, _ ("bad grob property path"));
2486 | grob_prop_spec property_path
2488 if (!SCM_UNBNDP ($1)) {
2489 $$ = scm_append_x (scm_list_2 ($1, $2));
2490 if (scm_is_null (scm_cddr ($$))) {
2491 parser->parser_error (@$, _ ("bad grob property path"));
2499 // Exactly two elements or undefined
2503 SCM l = scm_reverse_x ($1, SCM_EOL);
2504 switch (scm_ilength (l)) {
2506 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2510 parser->parser_error (@1, _ ("bad context property path"));
2518 // This is all quite awkward for the sake of substantial backward
2519 // compatibility while at the same time allowing a more "natural" form
2520 // of specification not separating grob specification from grob
2521 // property path. The purpose of this definition of
2522 // simple_revert_context is to allow the symbol list which specifies
2523 // grob and property to revert to be optionally be split into two
2524 // parts after the grob (which may be preceded by a context
2525 // specification, a case which we distinguish by checking whether the
2526 // first symbol is a valid grob symbol instead).
2528 // See revert_arg above for the main work horse of this arrangement.
2529 // simple_revert_context just caters for the context and delegates the
2530 // rest of the job to revert_arg.
2532 simple_revert_context:
2535 $1 = scm_reverse_x ($1, SCM_EOL);
2536 if (scm_is_null ($1)
2538 (scm_object_property (scm_car ($1),
2539 ly_symbol2scm ("is-grob?")))) {
2540 $$ = ly_symbol2scm ("Bottom");
2541 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2544 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2551 OVERRIDE grob_prop_path '=' scalar {
2552 if (SCM_UNBNDP ($2))
2553 $$ = MAKE_SYNTAX ("void-music", @$);
2555 $$ = MAKE_SYNTAX ("property-operation", @$,
2557 ly_symbol2scm ("OverrideProperty"),
2563 | REVERT simple_revert_context revert_arg {
2564 $$ = MAKE_SYNTAX ("property-operation", @$,
2566 ly_symbol2scm ("RevertProperty"),
2570 | SET context_prop_spec '=' scalar {
2571 if (SCM_UNBNDP ($2))
2572 $$ = MAKE_SYNTAX ("void-music", @$);
2574 $$ = MAKE_SYNTAX ("property-operation", @$,
2576 ly_symbol2scm ("PropertySet"),
2580 | UNSET context_prop_spec {
2581 if (SCM_UNBNDP ($2))
2582 $$ = MAKE_SYNTAX ("void-music", @$);
2584 $$ = MAKE_SYNTAX ("property-operation", @$,
2586 ly_symbol2scm ("PropertyUnset"),
2598 simple_string: STRING {
2603 if (scm_is_string ($1)) {
2606 parser->parser_error (@1, (_ ("simple string expected")));
2607 $$ = scm_string (SCM_EOL);
2614 $$ = scm_string_to_symbol ($1);
2618 // This is a bit of overkill but makes the same
2619 // routine responsible for all symbol interpretations.
2620 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2622 if (SCM_UNBNDP ($$))
2624 parser->parser_error (@1, (_ ("symbol expected")));
2625 // Generate a unique symbol in case it is used
2626 // for an assignment or similar
2627 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2637 // The following is a rather defensive variant of admitting
2638 // negative numbers: the grammar would permit number_factor or
2639 // even number_expression. However, function arguments allow
2640 // only this simple kind of negative number, so to have things
2641 // like \tweak and \override behave reasonably similar, it
2642 // makes sense to rule out things like -- which are rather an
2643 // accent in function argument contexts.
2646 $$ = scm_difference ($2, SCM_UNDEFINED);
2652 simple_element post_events {
2653 // Let the rhythmic music iterator sort this mess out.
2654 if (scm_is_pair ($2)) {
2655 unsmob<Music> ($$)->set_property ("articulations",
2656 scm_reverse_x ($2, SCM_EOL));
2659 | CHORD_REPETITION optional_notemode_duration post_events {
2661 i.set_location (@1, @3);
2662 $$ = MAKE_SYNTAX ("repetition-chord", i,
2663 $2, scm_reverse_x ($3, SCM_EOL));
2665 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2667 i.set_location (@1, @3);
2668 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2669 scm_reverse_x ($3, SCM_EOL));
2672 | note_chord_element
2677 chord_body optional_notemode_duration post_events
2679 Music *m = unsmob<Music> ($1);
2680 SCM dur = unsmob<Duration> ($2)->smobbed_copy ();
2681 SCM es = m->get_property ("elements");
2682 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2684 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2685 unsmob<Music> (scm_car (s))->set_property ("duration", dur);
2686 es = ly_append2 (es, postevs);
2688 m-> set_property ("elements", es);
2690 $$ = m->self_scm ();
2695 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2697 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2699 | FIGURE_OPEN figure_list FIGURE_CLOSE
2701 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2705 chord_body_elements:
2706 /* empty */ { $$ = SCM_EOL; }
2707 | chord_body_elements chord_body_element {
2708 if (!SCM_UNBNDP ($2))
2709 $$ = scm_cons ($2, $1);
2714 pitch_or_tonic_pitch exclamations questions octave_check post_events
2716 bool q = to_boolean ($3);
2717 bool ex = to_boolean ($2);
2721 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2722 n->set_property ("pitch", $1);
2724 n->set_property ("cautionary", SCM_BOOL_T);
2726 n->set_property ("force-accidental", SCM_BOOL_T);
2728 if (scm_is_pair (post)) {
2729 SCM arts = scm_reverse_x (post, SCM_EOL);
2730 n->set_property ("articulations", arts);
2732 if (scm_is_number (check))
2734 int q = scm_to_int (check);
2735 n->set_property ("absolute-octave", scm_from_int (q-1));
2738 $$ = n->unprotect ();
2740 | DRUM_PITCH post_events {
2741 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2742 n->set_property ("drum-type", $1);
2744 if (scm_is_pair ($2)) {
2745 SCM arts = scm_reverse_x ($2, SCM_EOL);
2746 n->set_property ("articulations", arts);
2748 $$ = n->unprotect ();
2750 | music_function_chord_body
2752 Music *m = unsmob<Music> ($1);
2754 while (m && m->is_mus_type ("music-wrapper-music")) {
2755 $$ = m->get_property ("element");
2756 m = unsmob<Music> ($$);
2759 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2760 parser->parser_error (@$, _ ("not a rhythmic event"));
2766 music_function_chord_body:
2772 event_function_event:
2773 EVENT_FUNCTION function_arglist {
2774 $$ = MAKE_SYNTAX ("music-function", @$,
2783 | post_events post_event {
2785 if (Music *m = unsmob<Music> ($2))
2787 if (m->is_mus_type ("post-event-wrapper"))
2789 for (SCM p = m->get_property ("elements");
2793 $$ = scm_cons (scm_car (p), $$);
2797 $$ = scm_cons ($2, $$);
2803 post_event_nofinger:
2804 direction_less_event {
2807 | script_dir music_function_call {
2809 if (!unsmob<Music> ($2)->is_mus_type ("post-event")) {
2810 parser->parser_error (@2, _ ("post-event expected"));
2811 $$ = SCM_UNSPECIFIED;
2812 } else if (!SCM_UNBNDP ($1))
2814 unsmob<Music> ($$)->set_property ("direction", $1);
2818 if (!parser->lexer_->is_lyric_state ())
2819 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2820 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2823 if (!parser->lexer_->is_lyric_state ())
2824 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2825 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2827 | script_dir direction_reqd_event {
2828 if (!SCM_UNBNDP ($1))
2830 Music *m = unsmob<Music> ($2);
2831 m->set_property ("direction", $1);
2835 | script_dir direction_less_event {
2836 if (!SCM_UNBNDP ($1))
2838 Music *m = unsmob<Music> ($2);
2839 m->set_property ("direction", $1);
2846 unsmob<Music> ($$)->set_property ("direction", scm_from_int (UP));
2851 unsmob<Music> ($$)->set_property ("direction", scm_from_int (DOWN));
2862 string_number_event:
2864 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2865 s->set_property ("string-number", $1);
2866 $$ = s->unprotect ();
2870 direction_less_event:
2872 | EVENT_IDENTIFIER {
2876 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2877 a->set_property ("tremolo-type", $1);
2878 $$ = a->unprotect ();
2880 | event_function_event
2883 direction_reqd_event:
2887 | script_abbreviation {
2888 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2889 if (scm_is_string (s)) {
2890 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2891 a->set_property ("articulation-type", s);
2892 $$ = a->unprotect ();
2894 Music *original = unsmob<Music> (s);
2895 if (original && original->is_mus_type ("post-event")) {
2896 Music *a = original->clone ();
2897 a->set_spot (parser->lexer_->override_input (@$));
2898 $$ = a->unprotect ();
2900 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2901 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2908 /**/ { $$ = SCM_EOL; }
2909 | '=' quotes { $$ = $2; }
2923 $$ = scm_from_int (1);
2926 $$ = scm_oneplus ($1);
2932 $$ = scm_from_int (-1);
2935 $$ = scm_oneminus ($1);
2940 NOTENAME_PITCH quotes {
2941 if (!scm_is_eq (SCM_INUM0, $2))
2943 Pitch p = *unsmob<Pitch> ($1);
2944 p = p.transposed (Pitch (scm_to_int ($2), 0));
2945 $$ = p.smobbed_copy ();
2955 TONICNAME_PITCH quotes {
2956 if (!scm_is_eq (SCM_INUM0, $2))
2958 Pitch p = *unsmob<Pitch> ($1);
2959 p = p.transposed (Pitch (scm_to_int ($2), 0));
2960 $$ = p.smobbed_copy ();
2967 | PITCH_IDENTIFIER quotes {
2968 if (!scm_is_eq (SCM_INUM0, $2))
2970 Pitch p = *unsmob<Pitch> ($1);
2971 p = p.transposed (Pitch (scm_to_int ($2), 0));
2972 $$ = p.smobbed_copy ();
2977 pitch_or_tonic_pitch:
2984 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2985 t->set_property ("text", $1);
2986 $$ = t->unprotect ();
2989 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2990 t->set_property ("text",
2991 make_simple_markup ($1));
2992 $$ = t->unprotect ();
2996 Music *m = unsmob<Music> ($1);
2997 if (m && m->is_mus_type ("post-event"))
2999 else if (Text_interface::is_markup ($1)) {
3000 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3001 t->set_property ("text", $1);
3002 $$ = t->unprotect ();
3004 parser->parser_error (@1, _ ("not an articulation"));
3010 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3011 t->set_property ("digit", $1);
3012 $$ = t->unprotect ();
3016 script_abbreviation:
3018 $$ = scm_from_ascii_string ("Hat");
3021 $$ = scm_from_ascii_string ("Plus");
3024 $$ = scm_from_ascii_string ("Dash");
3027 $$ = scm_from_ascii_string ("Bang");
3030 $$ = scm_from_ascii_string ("Larger");
3033 $$ = scm_from_ascii_string ("Dot");
3036 $$ = scm_from_ascii_string ("Underscore");
3041 '_' { $$ = scm_from_int (DOWN); }
3042 | '^' { $$ = scm_from_int (UP); }
3043 | '-' { $$ = SCM_UNDEFINED; }
3047 multiplied_duration {
3052 maybe_notemode_duration:
3056 | multiplied_duration {
3058 parser->default_duration_ = *unsmob<Duration> ($$);
3063 optional_notemode_duration:
3064 maybe_notemode_duration
3066 if (SCM_UNBNDP ($$))
3067 $$ = parser->default_duration_.smobbed_copy ();
3073 $$ = make_duration ($1, scm_to_int ($2));
3074 if (SCM_UNBNDP ($$))
3076 parser->parser_error (@1, _ ("not a duration"));
3077 $$ = Duration ().smobbed_copy ();
3080 | DURATION_IDENTIFIER dots {
3081 Duration *d = unsmob<Duration> ($1);
3082 Duration k (d->duration_log (),
3083 d->dot_count () + scm_to_int ($2));
3084 k = k.compressed (d->factor ());
3085 scm_remember_upto_here_1 ($1);
3086 $$ = k.smobbed_copy ();
3090 multiplied_duration:
3094 | multiplied_duration '*' UNSIGNED {
3095 $$ = unsmob<Duration> ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
3097 | multiplied_duration '*' FRACTION {
3098 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
3100 $$ = unsmob<Duration> ($$)->compressed (m).smobbed_copy ();
3109 $$ = scm_oneplus ($1);
3115 $$ = scm_from_int (parser->default_tremolo_type_);
3118 if (SCM_UNBNDP (make_duration ($2))) {
3119 parser->parser_error (@2, _ ("not a duration"));
3120 $$ = scm_from_int (parser->default_tremolo_type_);
3123 parser->default_tremolo_type_ = scm_to_int ($2);
3129 UNSIGNED { $$ = $1; }
3130 | STRING { $$ = $1; }
3131 | full_markup { $$ = $1; }
3134 // as an integer, it needs to be non-negative, and otherwise
3135 // it needs to be suitable as a markup.
3136 if (scm_is_integer ($1)
3137 ? scm_is_true (scm_negative_p ($1))
3138 : !Text_interface::is_markup ($1))
3140 parser->parser_error (@1, _ ("bass number expected"));
3146 figured_bass_alteration:
3147 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3148 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3149 | '!' { $$ = scm_from_int (0); }
3154 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3155 $$ = bfr->unprotect ();
3158 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3159 $$ = bfr->self_scm ();
3161 if (scm_is_number ($1))
3162 bfr->set_property ("figure", $1);
3163 else if (Text_interface::is_markup ($1))
3164 bfr->set_property ("text", $1);
3170 unsmob<Music> ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3172 | bass_figure figured_bass_alteration {
3173 Music *m = unsmob<Music> ($1);
3174 if (scm_to_double ($2)) {
3175 SCM salter = m->get_property ("alteration");
3176 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3177 m->set_property ("alteration",
3178 scm_sum (alter, $2));
3180 m->set_property ("alteration", scm_from_int (0));
3183 | bass_figure figured_bass_modification {
3184 Music *m = unsmob<Music> ($1);
3185 m->set_property ($2, SCM_BOOL_T);
3190 figured_bass_modification:
3192 $$ = ly_symbol2scm ("augmented");
3195 $$ = ly_symbol2scm ("no-continuation");
3198 $$ = ly_symbol2scm ("diminished");
3201 $$ = ly_symbol2scm ("augmented-slash");
3211 unsmob<Music> ($$)->set_property ("bracket-start", SCM_BOOL_T);
3219 | figure_list br_bass_figure {
3220 $$ = scm_cons ($2, $1);
3225 /**/ { $$ = SCM_BOOL_F; }
3226 | REST { $$ = SCM_BOOL_T; }
3230 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3231 if (!parser->lexer_->is_note_state ())
3232 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3233 if (!SCM_UNBNDP ($2)
3235 || scm_is_number ($4)
3238 || scm_is_pair ($7))
3241 if (scm_is_true ($6))
3242 n = MY_MAKE_MUSIC ("RestEvent", @$);
3244 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3246 n->set_property ("pitch", $1);
3247 if (SCM_UNBNDP ($5))
3248 n->set_property ("duration",
3249 parser->default_duration_.smobbed_copy ());
3251 n->set_property ("duration", $5);
3253 if (scm_is_number ($4))
3255 int q = scm_to_int ($4);
3256 n->set_property ("absolute-octave", scm_from_int (q-1));
3259 if (to_boolean ($3))
3260 n->set_property ("cautionary", SCM_BOOL_T);
3261 if (to_boolean ($2) || to_boolean ($3))
3262 n->set_property ("force-accidental", SCM_BOOL_T);
3263 if (scm_is_pair ($7))
3264 n->set_property ("articulations",
3265 scm_reverse_x ($7, SCM_EOL));
3266 $$ = n->unprotect ();
3269 | new_chord post_events {
3270 if (!parser->lexer_->is_chord_state ())
3271 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3272 if (scm_is_pair ($2)) {
3273 if (unsmob<Pitch> ($1))
3274 $1 = make_chord_elements (@1,
3276 parser->default_duration_.smobbed_copy (),
3279 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3281 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
3282 } else if (!unsmob<Pitch> ($1))
3283 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
3284 // A mere pitch drops through.
3289 DRUM_PITCH optional_notemode_duration {
3290 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3291 n->set_property ("duration", $2);
3292 n->set_property ("drum-type", $1);
3294 $$ = n->unprotect ();
3296 | RESTNAME optional_notemode_duration {
3298 if (ly_scm2string ($1) == "s") {
3300 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3303 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3306 ev->set_property ("duration", $2);
3307 $$ = ev->unprotect ();
3313 if (!parser->lexer_->is_lyric_state ())
3314 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3318 if (!parser->lexer_->is_lyric_state ())
3319 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3325 lyric_element_music:
3326 lyric_element optional_notemode_duration post_events {
3327 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3328 if (scm_is_pair ($3))
3329 unsmob<Music> ($$)->set_property
3330 ("articulations", scm_reverse_x ($3, SCM_EOL));
3334 // Can return a single pitch rather than a list.
3336 steno_tonic_pitch maybe_notemode_duration {
3337 if (SCM_UNBNDP ($2))
3340 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3342 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3343 SCM its = scm_reverse_x ($4, SCM_EOL);
3344 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3352 | chord_items chord_item {
3353 $$ = scm_cons ($2, $$);
3359 $$ = ly_symbol2scm ("chord-colon");
3362 $$ = ly_symbol2scm ("chord-caret");
3364 | CHORD_SLASH steno_tonic_pitch {
3365 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3367 | CHORD_BASS steno_tonic_pitch {
3368 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3377 $$ = scm_reverse_x ($1, SCM_EOL);
3385 step_number { $$ = scm_cons ($1, SCM_EOL); }
3386 | step_numbers '.' step_number {
3387 $$ = scm_cons ($3, $$);
3393 $$ = make_chord_step ($1, 0);
3396 $$ = make_chord_step ($1, SHARP_ALTERATION);
3398 | UNSIGNED CHORD_MINUS {
3399 $$ = make_chord_step ($1, FLAT_ALTERATION);
3407 | unsigned_number '-' unsigned_number {
3408 $$ = scm_cons ($1, $3);
3415 TODO: should deprecate in favor of Scheme?
3419 number_expression '+' number_term {
3420 $$ = scm_sum ($1, $3);
3422 | number_expression '-' number_term {
3423 $$ = scm_difference ($1, $3);
3432 | number_factor '*' number_factor {
3433 $$ = scm_product ($1, $3);
3435 | number_factor '/' number_factor {
3436 $$ = scm_divide ($1, $3);
3441 '-' number_factor { /* %prec UNARY_MINUS */
3442 $$ = scm_difference ($2, SCM_UNDEFINED);
3450 | REAL NUMBER_IDENTIFIER
3452 $$ = scm_product ($1, $2);
3459 | UNSIGNED NUMBER_IDENTIFIER {
3460 $$ = scm_product ($1, $2);
3468 if (!scm_is_integer ($1)
3469 || scm_is_true (scm_negative_p ($1)))
3471 parser->parser_error (@1, _("not an unsigned integer"));
3477 if (!scm_is_integer ($1)
3478 || scm_is_true (scm_negative_p ($1)))
3480 parser->parser_error (@1, _("not an unsigned integer"));
3487 { $$ = SCM_UNDEFINED; }
3490 if (SCM_UNBNDP ($1))
3498 // This precedence rule is rather weird. It triggers when '!' is
3499 // encountered after a pitch, and is used for deciding whether to save
3500 // this instead for a figure modification. This should not actually
3501 // occur in practice as pitches and figures are generated in different
3502 // modes. Using a greedy (%right) precedence makes sure that we don't
3503 // get stuck in a wrong interpretation.
3504 { $$ = SCM_UNDEFINED; } %prec ':'
3507 if (SCM_UNBNDP ($1))
3516 { parser->lexer_->push_markup_state (); }
3519 parser->lexer_->pop_state ();
3525 { parser->lexer_->push_markup_state (); }
3528 parser->lexer_->pop_state ();
3534 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3536 | markup_head_1_list simple_markup
3538 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3539 @2, $1, scm_list_1 ($2)));
3549 if (Text_interface::is_markup ($1))
3550 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3551 else if (Text_interface::is_markup_list ($1))
3552 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3554 parser->parser_error (@1, _ ("not a markup"));
3555 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3562 markup_composed_list {
3565 | markup_uncomposed_list
3568 markup_uncomposed_list:
3569 markup_braced_list {
3572 | markup_command_list {
3573 $$ = scm_list_1 ($1);
3575 | markup_scm MARKUPLIST_IDENTIFIER
3580 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3581 parser->lexer_->push_note_state (nn);
3582 } '{' score_body '}' {
3583 Score *sc = unsmob<Score> ($4);
3584 sc->origin ()->set_spot (@$);
3585 if (sc->defs_.empty ()) {
3586 Output_def *od = get_layout (parser);
3587 sc->add_output_def (od);
3590 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3591 parser->lexer_->pop_state ();
3595 markup_composed_list:
3596 markup_head_1_list markup_uncomposed_list {
3597 $$ = MAKE_SYNTAX ("composed-markup-list",
3603 '{' markup_braced_list_body '}' {
3604 $$ = scm_reverse_x ($2, SCM_EOL);
3608 markup_braced_list_body:
3609 /* empty */ { $$ = SCM_EOL; }
3610 | markup_braced_list_body markup {
3611 $$ = scm_cons ($2, $1);
3613 | markup_braced_list_body markup_list {
3614 $$ = scm_reverse_x ($2, $1);
3618 markup_command_list:
3619 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3620 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3624 markup_command_basic_arguments:
3625 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3626 $$ = scm_cons ($3, $2);
3628 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3629 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3631 | EXPECT_NO_MORE_ARGS {
3636 markup_command_list_arguments:
3637 markup_command_basic_arguments { $$ = $1; }
3638 | EXPECT_MARKUP markup_command_list_arguments markup {
3639 $$ = scm_cons ($3, $2);
3644 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3645 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3650 markup_head_1_item {
3651 $$ = scm_list_1 ($1);
3653 | markup_head_1_list markup_head_1_item {
3654 $$ = scm_cons ($2, $1);
3660 $$ = make_simple_markup ($1);
3663 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3664 parser->lexer_->push_note_state (nn);
3665 } '{' score_body '}' {
3666 Score *sc = unsmob<Score> ($4);
3667 sc->origin ()->set_spot (@$);
3668 if (sc->defs_.empty ()) {
3669 Output_def *od = get_layout (parser);
3670 sc->add_output_def (od);
3673 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3674 parser->lexer_->pop_state ();
3676 | MARKUP_FUNCTION markup_command_basic_arguments {
3677 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3679 | markup_scm MARKUP_IDENTIFIER
3686 markup_head_1_list simple_markup
3688 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3689 @2, $1, scm_list_1 ($2)));
3699 Lily_parser::set_yydebug (bool x)
3705 Lily_parser::do_yyparse ()
3707 return scm_c_with_fluid (ly_lily_module_constant ("%parser"),
3709 do_yyparse_trampoline,
3710 static_cast <void *>(this));
3714 Lily_parser::do_yyparse_trampoline (void *parser)
3716 SCM retval = SCM_UNDEFINED;
3717 yyparse (static_cast <Lily_parser *>(parser), &retval);
3725 It is a little strange to have this function in this file, but
3726 otherwise, we have to import music classes into the lexer.
3730 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3732 if (unsmob<Book> (sid)) {
3733 Book *book = unsmob<Book> (sid)->clone ();
3734 *destination = book->self_scm ();
3737 return BOOK_IDENTIFIER;
3738 } else if (scm_is_number (sid)) {
3740 return NUMBER_IDENTIFIER;
3741 } else if (unsmob<Context_def> (sid))
3743 *destination = unsmob<Context_def> (sid)->clone ()->unprotect ();
3744 return SCM_IDENTIFIER;
3745 } else if (unsmob<Context_mod> (sid)) {
3746 *destination = unsmob<Context_mod> (sid)->smobbed_copy ();
3747 return CONTEXT_MOD_IDENTIFIER;
3748 } else if (Music *mus = unsmob<Music> (sid)) {
3749 mus = mus->clone ();
3750 *destination = mus->self_scm ();
3751 bool is_event = mus->is_mus_type ("post-event");
3753 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3754 } else if (unsmob<Pitch> (sid)) {
3755 *destination = unsmob<Pitch> (sid)->smobbed_copy ();
3756 return PITCH_IDENTIFIER;
3757 } else if (unsmob<Duration> (sid)) {
3758 *destination = unsmob<Duration> (sid)->smobbed_copy ();
3759 return DURATION_IDENTIFIER;
3760 } else if (unsmob<Output_def> (sid)) {
3761 *destination = unsmob<Output_def> (sid)->clone ()->unprotect ();
3762 return SCM_IDENTIFIER;
3763 } else if (unsmob<Score> (sid)) {
3764 *destination = unsmob<Score> (sid)->clone ()->unprotect ();
3765 return SCM_IDENTIFIER;
3772 get_next_unique_context_id ()
3774 return scm_from_ascii_string ("$uniqueContextId");
3779 get_next_unique_lyrics_context_id ()
3781 static int new_context_count;
3783 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3784 return scm_from_ascii_string (s);
3787 // check_scheme_arg checks one argument with a given predicate for use
3788 // in an argument list and throws a syntax error if it is unusable.
3789 // The argument is prepended to the argument list in any case. After
3790 // throwing a syntax error, the argument list is terminated with #f as
3791 // its last cdr in order to mark it as uncallable while not losing
3792 // track of its total length.
3794 // There are a few special considerations: if optional argument disp
3795 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3796 // instead of arg in a prospective error message. This is useful if
3797 // arg is not the actual argument but rather a transformation of it.
3799 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3800 // and an error message using disp is produced unconditionally.
3802 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3803 SCM arg, SCM args, SCM pred, SCM disp)
3805 if (SCM_UNBNDP (arg))
3806 args = scm_cons (disp, args);
3808 args = scm_cons (arg, args);
3809 if (scm_is_true (scm_call_1 (pred, arg)))
3812 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3813 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3814 SCM_UNBNDP (disp) ? arg : disp);
3815 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3819 SCM loc_on_music (Input loc, SCM arg)
3821 if (Music *m = unsmob<Music> (arg))
3825 return m->unprotect ();
3831 try_string_variants (SCM pred, SCM str)
3833 // a matching predicate is always ok
3834 if (scm_is_true (scm_call_1 (pred, str)))
3836 // a symbol may be interpreted as a list of symbols if it helps
3837 if (scm_is_symbol (str)) {
3838 str = scm_list_1 (str);
3839 if (scm_is_true (scm_call_1 (pred, str)))
3841 return SCM_UNDEFINED;
3844 // If this cannot be a string representation of a symbol list,
3847 if (!is_regular_identifier (str, true))
3848 return SCM_UNDEFINED;
3850 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3851 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3852 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3854 // Let's attempt the symbol list interpretation first.
3856 if (scm_is_true (scm_call_1 (pred, str)))
3859 // If there is just one symbol in the list, we might interpret
3860 // it as a single symbol
3862 if (scm_is_null (scm_cdr (str)))
3864 str = scm_car (str);
3865 if (scm_is_true (scm_call_1 (pred, str)))
3869 return SCM_UNDEFINED;
3873 is_regular_identifier (SCM id, bool multiple)
3875 if (!scm_is_string (id))
3878 string str = ly_scm2string (id);
3880 bool middle = false;
3882 for (string::iterator it=str.begin(); it != str.end (); it++)
3885 if ((c >= 'a' && c <= 'z')
3886 || (c >= 'A' && c <= 'Z')
3889 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3898 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3900 if (unsmob<Music> (simple))
3902 if (parser->lexer_->is_note_state ()) {
3903 if (scm_is_symbol (simple)) {
3904 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3905 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3906 n->set_property ("drum-type", simple);
3907 return n->unprotect ();
3909 if (unsmob<Pitch> (simple)) {
3910 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3911 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3912 n->set_property ("pitch", simple);
3913 return n->unprotect ();
3916 } else if (parser->lexer_->is_lyric_state ()) {
3917 if (Text_interface::is_markup (simple))
3918 return MAKE_SYNTAX ("lyric-event", loc, simple,
3919 parser->default_duration_.smobbed_copy ());
3920 } else if (parser->lexer_->is_chord_state ()) {
3921 if (unsmob<Pitch> (simple))
3925 make_chord_elements (loc, simple,
3926 parser->default_duration_.smobbed_copy (),
3933 make_music_with_input (SCM name, Input where)
3935 Music *m = make_music_by_name (name);
3936 m->set_spot (where);
3941 make_simple_markup (SCM a)
3947 make_duration (SCM d, int dots)
3949 int t = scm_to_int (d);
3950 if (t > 0 && (t & (t-1)) == 0)
3951 return Duration (intlog2 (t), dots).smobbed_copy ();
3953 return SCM_UNDEFINED;
3957 make_chord_step (SCM step_scm, Rational alter)
3959 int step = scm_to_int (step_scm);
3962 alter += FLAT_ALTERATION;
3966 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3967 return m.smobbed_copy ();
3972 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3974 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3975 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3976 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3978 unsmob<Music> (scm_car (s))->set_spot (loc);
3984 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3986 Lily_lexer *lex = parser->lexer_;
3990 int tok = lex->pop_extra_token ();
3993 lex->prepare_for_next_token ();
3994 return lex->yylex ();