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--2012 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 char *p = scm_to_locale_string \
45 (scm_simple_format (SCM_BOOL_F, \
46 scm_from_locale_string ("~S"), \
47 scm_list_1 (value))); \
54 %parse-param {Lily_parser *parser}
55 %parse-param {SCM *retval}
56 %lex-param {Lily_parser *parser}
60 /* We use SCMs to do strings, because it saves us the trouble of
61 deleting them. Let's hope that a stack overflow doesn't trigger a move
62 of the parse stack onto the heap. */
68 /* The above precedences tackle the shift/reduce problem
71 \repeat .. \alternative
73 \repeat { \repeat .. \alternative }
77 \repeat { \repeat } \alternative
83 /* ADDLYRICS needs to have lower precedence than argument scanning,
84 * or we won't be able to tell music apart from closed_music without
85 * lookahead in the context of function calls.
90 /* \default is only applied after exhausting function arguments */
92 %nonassoc FUNCTION_ARGLIST
94 /* expressions with units are permitted into argument lists */
96 %right PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
97 UNSIGNED REAL DURATION_IDENTIFIER ':'
99 /* The above are the symbols that can start optional function arguments
100 that are recognized in the grammar rather than by predicate
103 %nonassoc NUMBER_IDENTIFIER '/'
105 /* Number-unit expressions, where permitted, are concatenated into
106 * function arguments, just like fractions and tremoli. Tremoli must
107 * not have higher precedence than UNSIGNED, or Lilypond will not
108 * join ':' with a following optional number.
121 %{ // -*-Fundamental-*-
126 * The rules for who is protecting what are very shady. Uniformise
129 * There are too many lexical modes?
140 #include "context-def.hh"
141 #include "context-mod.hh"
142 #include "dimensions.hh"
143 #include "file-path.hh"
145 #include "international.hh"
146 #include "lily-guile.hh"
147 #include "lily-lexer.hh"
148 #include "lily-parser.hh"
152 #include "output-def.hh"
153 #include "paper-book.hh"
154 #include "scm-hash.hh"
156 #include "text-interface.hh"
160 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
162 parser->parser_error (*i, s);
165 #define MYBACKUP(Token, Value, Location) \
167 if (yychar == YYEMPTY) \
170 parser->lexer_->push_extra_token (Token, Value); \
171 parser->lexer_->push_extra_token (BACKUP); \
173 parser->parser_error \
174 (Location, _("Too much lookahead")); \
179 #define MYREPARSE(Location, Pred, Token, Value) \
181 if (yychar == YYEMPTY) \
183 parser->lexer_->push_extra_token (Token, Value); \
184 parser->lexer_->push_extra_token (REPARSE, \
187 parser->parser_error \
188 (Location, _("Too much lookahead")); \
197 #define MY_MAKE_MUSIC(x, spot) \
198 make_music_with_input (ly_symbol2scm (x), \
199 parser->lexer_->override_input (spot))
202 - Don't use lily module, create a new module instead.
203 - delay application of the function
205 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
206 scm_apply_0 (proc, args)
207 /* Syntactic Sugar. */
208 #define MAKE_SYNTAX(name, location, ...) \
209 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (parser->lexer_->override_input (location)), ##__VA_ARGS__, SCM_UNDEFINED))
210 #define START_MAKE_SYNTAX(name, ...) \
211 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
212 #define FINISH_MAKE_SYNTAX(start, location, ...) \
213 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (parser->lexer_->override_input (location)), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
215 SCM get_next_unique_context_id ();
216 SCM get_next_unique_lyrics_context_id ();
223 #define _(x) gettext (x)
227 static Music *make_music_with_input (SCM name, Input where);
228 SCM check_scheme_arg (Lily_parser *parser, Input loc,
229 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
230 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
231 SCM loc_on_music (Input loc, SCM arg);
232 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
233 SCM make_chord_step (SCM step, Rational alter);
234 SCM make_simple_markup (SCM a);
235 bool is_duration (int t);
236 bool is_regular_identifier (SCM id, bool multiple=false);
237 SCM try_string_variants (SCM pred, SCM str);
238 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
242 /* The third option is an alias that will be used to display the
243 syntax error. Bison CVS now correctly handles backslash escapes.
245 FIXME: Bison needs to translate some of these, eg, STRING.
249 /* Keyword tokens with plain escaped name. */
250 %token END_OF_FILE 0 "end of input"
251 %token ACCEPTS "\\accepts"
252 %token ADDLYRICS "\\addlyrics"
253 %token ALIAS "\\alias"
254 %token ALTERNATIVE "\\alternative"
256 %token BOOKPART "\\bookpart"
257 %token CHANGE "\\change"
258 %token CHORDMODE "\\chordmode"
259 %token CHORDS "\\chords"
260 %token CONSISTS "\\consists"
261 %token CONTEXT "\\context"
262 %token DEFAULT "\\default"
263 %token DEFAULTCHILD "\\defaultchild"
264 %token DENIES "\\denies"
265 %token DESCRIPTION "\\description"
266 %token DRUMMODE "\\drummode"
267 %token DRUMS "\\drums"
268 %token FIGUREMODE "\\figuremode"
269 %token FIGURES "\\figures"
270 %token HEADER "\\header"
271 %token INVALID "\\version-error"
272 %token LAYOUT "\\layout"
273 %token LYRICMODE "\\lyricmode"
274 %token LYRICS "\\lyrics"
275 %token LYRICSTO "\\lyricsto"
276 %token MARKUP "\\markup"
277 %token MARKUPLIST "\\markuplist"
280 %token NOTEMODE "\\notemode"
281 %token OVERRIDE "\\override"
282 %token PAPER "\\paper"
283 %token REMOVE "\\remove"
284 %token REPEAT "\\repeat"
286 %token REVERT "\\revert"
287 %token SCORE "\\score"
288 %token SEQUENTIAL "\\sequential"
290 %token SIMULTANEOUS "\\simultaneous"
291 %token TEMPO "\\tempo"
293 %token UNSET "\\unset"
296 /* Keyword token exceptions. */
297 %token NEWCONTEXT "\\new"
300 /* Other string tokens. */
302 %token CHORD_BASS "/+"
303 %token CHORD_CARET "^"
304 %token CHORD_COLON ":"
305 %token CHORD_MINUS "-"
306 %token CHORD_SLASH "/"
307 %token ANGLE_OPEN "<"
308 %token ANGLE_CLOSE ">"
309 %token DOUBLE_ANGLE_OPEN "<<"
310 %token DOUBLE_ANGLE_CLOSE ">>"
311 %token E_BACKSLASH "\\"
312 %token E_EXCLAMATION "\\!"
317 If we give names, Bison complains.
319 %token FIGURE_CLOSE /* "\\>" */
320 %token FIGURE_OPEN /* "\\<" */
321 %token FIGURE_SPACE "_"
324 %token MULTI_MEASURE_REST
330 /* Artificial tokens, for more generic function syntax */
331 %token EXPECT_MARKUP "markup?"
332 %token EXPECT_DURATION "ly:duration?"
333 %token EXPECT_SCM "scheme?"
334 %token BACKUP "(backed-up?)"
335 %token REPARSE "(reparsed?)"
336 %token EXPECT_MARKUP_LIST "markup-list?"
337 %token EXPECT_OPTIONAL "optional?"
338 /* After the last argument. */
339 %token EXPECT_NO_MORE_ARGS;
341 /* An artificial token for parsing embedded Lilypond */
342 %token EMBEDDED_LILY "#{"
344 %token BOOK_IDENTIFIER
345 %token CHORD_MODIFIER
346 %token CHORD_REPETITION
347 %token CONTEXT_DEF_IDENTIFIER
348 %token CONTEXT_MOD_IDENTIFIER
350 %token PITCH_IDENTIFIER
351 %token DURATION_IDENTIFIER
352 %token EVENT_IDENTIFIER
353 %token EVENT_FUNCTION
356 %token MARKUP_FUNCTION
357 %token MARKUP_LIST_FUNCTION
358 %token MARKUP_IDENTIFIER
359 %token MARKUPLIST_IDENTIFIER
360 %token MUSIC_FUNCTION
361 %token MUSIC_IDENTIFIER
362 %token NOTENAME_PITCH
363 %token NUMBER_IDENTIFIER
364 %token OUTPUT_DEF_IDENTIFIER
369 %token SCM_IDENTIFIER
373 %token TONICNAME_PITCH
377 /* We don't assign precedence to / and *, because we might need varied
378 prec levels in different prods */
387 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
388 parser->lexer_->push_note_state (nn);
389 } embedded_lilypond {
390 parser->lexer_->pop_state ();
395 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
396 | lilypond toplevel_expression {
398 | lilypond assignment {
401 parser->error_level_ = 1;
404 parser->error_level_ = 1;
411 parser->lexer_->add_scope (get_header (parser));
413 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
416 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
417 scm_call_2 (proc, parser->self_scm (), $1);
420 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
421 scm_call_2 (proc, parser->self_scm (), $1);
424 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
425 scm_call_2 (proc, parser->self_scm (), $1);
428 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
429 scm_call_2 (proc, parser->self_scm (), $1);
432 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
433 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
436 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
437 scm_call_2 (proc, parser->self_scm (), $1);
440 // Evaluate and ignore #xxx, as opposed to \xxx
441 parser->lexer_->eval_scm_token ($1);
443 | embedded_scm_active
445 SCM out = SCM_UNDEFINED;
446 if (Text_interface::is_markup ($1))
447 out = scm_list_1 ($1);
448 else if (Text_interface::is_markup_list ($1))
450 if (scm_is_pair (out))
452 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
453 scm_call_2 (proc, parser->self_scm (), out);
454 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
455 parser->parser_error (@1, _("bad expression type"));
459 Output_def * od = unsmob_output_def ($1);
461 if (od->c_variable ("is-paper") == SCM_BOOL_T)
462 id = ly_symbol2scm ("$defaultpaper");
463 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
464 id = ly_symbol2scm ("$defaultmidi");
465 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
466 id = ly_symbol2scm ("$defaultlayout");
468 parser->lexer_->set_identifier (id, $1);
475 $$ = parser->lexer_->eval_scm_token ($1);
485 embedded_scm_bare_arg:
489 $$ = parser->lexer_->eval_scm_token ($1);
492 | context_modification
494 | context_def_spec_block
500 /* The generic version may end in music, or not */
507 /* embedded_scm_arg is _not_ casting pitches to music by default, this
508 * has to be done by the function itself. Note that this may cause
509 * the results of scm_function_call or embedded_scm_bare_arg to be
510 * turned into music from pitches as well. Note that this creates a
511 * distinctly awkward situation for calculated drum pitches. Those
512 * are at the current point of time rejected as music constituents as
513 * they can't be distinguished from "proper" symbols.
517 embedded_scm_bare_arg
523 SCM_FUNCTION function_arglist {
524 $$ = MAKE_SYNTAX ("music-function", @$,
532 // FIXME: @$ does not contain a useful source location
533 // for empty rules, and the only token in the whole
534 // production, EMBEDDED_LILY, is synthetic and also
535 // contains no source location.
536 $$ = MAKE_SYNTAX ("void-music", @$);
539 | music_embedded music_embedded music_list {
540 $3 = scm_reverse_x ($3, SCM_EOL);
541 if (unsmob_music ($2))
542 $3 = scm_cons ($2, $3);
543 if (unsmob_music ($1))
544 $3 = scm_cons ($1, $3);
545 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
548 parser->error_level_ = 1;
549 $$ = SCM_UNSPECIFIED;
551 | INVALID embedded_lilypond {
552 parser->error_level_ = 1;
558 lilypond_header_body:
559 /* empty */ { $$ = SCM_UNSPECIFIED; }
560 | lilypond_header_body assignment {
563 | lilypond_header_body embedded_scm {
569 HEADER '{' lilypond_header_body '}' {
570 $$ = parser->lexer_->remove_scope ();
582 assignment_id '=' identifier_init {
583 parser->lexer_->set_identifier ($1, $3);
584 $$ = SCM_UNSPECIFIED;
586 | assignment_id property_path '=' identifier_init {
587 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
588 parser->lexer_->set_identifier (path, $4);
589 $$ = SCM_UNSPECIFIED;
599 | context_def_spec_block
601 | post_event_nofinger post_events
603 $$ = scm_reverse_x ($2, SCM_EOL);
604 if (Music *m = unsmob_music ($1))
606 if (m->is_mus_type ("post-event-wrapper"))
608 (scm_list_2 (m->get_property ("elements"),
611 $$ = scm_cons ($1, $$);
614 && scm_is_null (scm_cdr ($$)))
618 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
619 m->set_property ("elements", $$);
620 $$ = m->unprotect ();
628 | context_modification
631 context_def_spec_block:
632 CONTEXT '{' context_def_spec_body '}'
635 unsmob_context_def ($$)->origin ()->set_spot (@$);
643 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
644 parser->lexer_->push_note_state (nn);
648 parser->lexer_->pop_state ();
653 context_mod_embedded:
656 if (unsmob_music ($1)) {
657 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
658 $1 = scm_call_2 (proc, parser->self_scm (), $1);
660 if (unsmob_context_mod ($1))
663 parser->parser_error (@1, _ ("not a context mod"));
664 $$ = Context_mod ().smobbed_copy ();
670 context_def_spec_body:
672 $$ = Context_def::make_scm ();
674 | CONTEXT_DEF_IDENTIFIER {
677 | context_def_spec_body context_mod {
678 if (!SCM_UNBNDP ($2))
679 unsmob_context_def ($$)->add_context_mod ($2);
681 | context_def_spec_body context_modification {
682 Context_def *td = unsmob_context_def ($$);
683 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
684 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
685 td->add_context_mod (scm_car (m));
688 | context_def_spec_body context_mod_embedded {
689 Context_def *td = unsmob_context_def ($$);
690 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
691 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
692 td->add_context_mod (scm_car (m));
700 BOOK '{' book_body '}' {
702 unsmob_book ($$)->origin ()->set_spot (@$);
704 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
709 * Use 'handlers' like for toplevel-* stuff?
710 * grok \layout and \midi? */
713 Book *book = new Book;
714 init_papers (parser);
715 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
716 book->paper_->unprotect ();
717 push_paper (parser, book->paper_);
718 book->header_ = get_header (parser);
719 $$ = book->unprotect ();
720 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
723 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
725 | book_body paper_block {
726 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
727 set_paper (parser, unsmob_output_def ($2));
729 | book_body bookpart_block {
730 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
731 scm_call_2 (proc, $1, $2);
733 | book_body score_block {
734 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
735 scm_call_2 (proc, $1, $2);
737 | book_body composite_music {
738 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
739 scm_call_3 (proc, parser->self_scm (), $1, $2);
741 | book_body full_markup {
742 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
743 scm_call_2 (proc, $1, scm_list_1 ($2));
745 | book_body full_markup_list {
746 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
747 scm_call_2 (proc, $1, $2);
749 | book_body SCM_TOKEN {
750 // Evaluate and ignore #xxx, as opposed to \xxx
751 parser->lexer_->eval_scm_token ($2);
753 | book_body embedded_scm_active
755 SCM out = SCM_UNDEFINED;
756 if (Text_interface::is_markup ($2))
757 out = scm_list_1 ($2);
758 else if (Text_interface::is_markup_list ($2))
760 if (scm_is_pair (out))
762 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
763 scm_call_2 (proc, $1, out);
764 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
765 parser->parser_error (@2, _("bad expression type"));
769 parser->lexer_->add_scope (unsmob_book ($1)->header_);
772 Book *book = unsmob_book ($1);
774 book->scores_ = SCM_EOL;
775 book->bookparts_ = SCM_EOL;
780 BOOKPART '{' bookpart_body '}' {
782 unsmob_book ($$)->origin ()->set_spot (@$);
783 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
789 Book *book = new Book;
790 $$ = book->unprotect ();
791 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
794 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
796 | bookpart_body paper_block {
797 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
799 | bookpart_body score_block {
800 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
801 scm_call_2 (proc, $1, $2);
803 | bookpart_body composite_music {
804 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
805 scm_call_3 (proc, parser->self_scm (), $1, $2);
807 | bookpart_body full_markup {
808 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
809 scm_call_2 (proc, $1, scm_list_1 ($2));
811 | bookpart_body full_markup_list {
812 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
813 scm_call_2 (proc, $1, $2);
815 | bookpart_body SCM_TOKEN {
816 // Evaluate and ignore #xxx, as opposed to \xxx
817 parser->lexer_->eval_scm_token ($2);
819 | bookpart_body embedded_scm_active
821 SCM out = SCM_UNDEFINED;
822 if (Text_interface::is_markup ($2))
823 out = scm_list_1 ($2);
824 else if (Text_interface::is_markup_list ($2))
826 if (scm_is_pair (out))
828 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
829 scm_call_2 (proc, $1, out);
830 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
831 parser->parser_error (@2, _("bad expression type"));
835 Book *book = unsmob_book ($1);
836 if (!ly_is_module (book->header_))
837 book->header_ = ly_make_module (false);
838 parser->lexer_->add_scope (book->header_);
840 | bookpart_body error {
841 Book *book = unsmob_book ($1);
843 book->scores_ = SCM_EOL;
848 SCORE '{' score_body '}' {
855 SCM scorify = ly_lily_module_constant ("scorify-music");
856 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
858 unsmob_score ($$)->origin ()->set_spot (@$);
860 | embedded_scm_active {
862 if (unsmob_score ($1))
863 score = new Score (*unsmob_score ($1));
866 parser->parser_error (@1, _("score expected"));
868 unsmob_score ($$)->origin ()->set_spot (@$);
869 $$ = score->unprotect ();
873 Score *score = unsmob_score ($1);
874 if (!ly_is_module (score->get_header ()))
875 score->set_header (ly_make_module (false));
876 parser->lexer_->add_scope (score->get_header ());
878 | score_body output_def {
879 Output_def *od = unsmob_output_def ($2);
880 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
882 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
887 unsmob_score ($1)->add_output_def (od);
891 unsmob_score ($$)->error_found_ = true;
902 Output_def *od = unsmob_output_def ($1);
904 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
906 parser->parser_error (@1, _ ("need \\paper for paper block"));
907 $$ = get_paper (parser)->unprotect ();
914 output_def_body '}' {
917 parser->lexer_->remove_scope ();
918 parser->lexer_->pop_state ();
924 Output_def *p = get_paper (parser);
925 p->input_origin_ = @$;
926 parser->lexer_->add_scope (p->scope_);
927 $$ = p->unprotect ();
930 Output_def *p = get_midi (parser);
931 $$ = p->unprotect ();
932 parser->lexer_->add_scope (p->scope_);
935 Output_def *p = get_layout (parser);
937 parser->lexer_->add_scope (p->scope_);
938 $$ = p->unprotect ();
942 output_def_head_with_mode_switch:
944 parser->lexer_->push_initial_state ();
949 // We need this weird nonterminal because both music as well as a
950 // context definition can start with \context and the difference is
951 // only apparent after looking at the next token. If it is '{', there
952 // is still time to escape from notes mode.
954 music_or_context_def:
956 | context_def_spec_block
960 output_def_head_with_mode_switch '{' {
962 unsmob_output_def ($$)->input_origin_.set_spot (@$);
964 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
965 Output_def *o = unsmob_output_def ($3);
966 o->input_origin_.set_spot (@$);
968 parser->lexer_->remove_scope ();
969 parser->lexer_->add_scope (o->scope_);
971 | output_def_body assignment {
974 | output_def_body embedded_scm {
979 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
980 parser->lexer_->push_note_state (nn);
981 } music_or_context_def
983 parser->lexer_->pop_state ();
984 if (unsmob_context_def ($3))
985 assign_context_def (unsmob_output_def ($1), $3);
988 SCM proc = parser->lexer_->lookup_identifier
989 ("output-def-music-handler");
990 scm_call_3 (proc, parser->self_scm (),
994 | output_def_body error {
1000 TEMPO steno_duration '=' tempo_range {
1001 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1003 | TEMPO scalar_closed steno_duration '=' tempo_range {
1004 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1007 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1012 The representation of a list is reversed to have efficient append. */
1018 | music_list music_embedded {
1019 if (unsmob_music ($2))
1020 $$ = scm_cons ($2, $1);
1022 | music_list error {
1023 Music *m = MY_MAKE_MUSIC("Music", @$);
1025 m->set_property ("error-found", SCM_BOOL_T);
1026 $$ = scm_cons (m->self_scm (), $1);
1027 m->unprotect (); /* UGH */
1034 $$ = scm_reverse_x ($2, SCM_EOL);
1039 | lyric_element_music
1045 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1046 parser->parser_error (@1, _ ("unexpected post-event"));
1047 $$ = SCM_UNSPECIFIED;
1050 | music_embedded_backup
1054 | music_embedded_backup BACKUP lyric_element_music
1060 music_embedded_backup:
1063 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1065 else if (Music *m = unsmob_music ($1)) {
1066 if (m->is_mus_type ("post-event")) {
1067 parser->parser_error
1068 (@1, _ ("unexpected post-event"));
1069 $$ = SCM_UNSPECIFIED;
1072 } else if (parser->lexer_->is_lyric_state ()
1073 && Text_interface::is_markup ($1))
1074 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1076 @$.warning (_ ("Ignoring non-music expression"));
1085 $$ = make_music_from_simple (parser, @1, $1);
1086 if (!unsmob_music ($$))
1087 parser->parser_error (@1, _ ("music expected"));
1089 | composite_music %prec COMPOSITE
1094 | composite_music %prec COMPOSITE
1098 REPEAT simple_string unsigned_number music
1100 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1102 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1104 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1109 SEQUENTIAL braced_music_list {
1110 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1112 | braced_music_list {
1113 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1118 SIMULTANEOUS braced_music_list {
1119 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1121 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1122 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1128 | music_property_def
1132 context_modification:
1135 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1136 parser->lexer_->push_note_state (nn);
1137 } '{' context_mod_list '}'
1139 parser->lexer_->pop_state ();
1142 | WITH CONTEXT_MOD_IDENTIFIER
1146 | CONTEXT_MOD_IDENTIFIER
1150 | WITH context_modification_arg
1152 if (unsmob_music ($2)) {
1153 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1154 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1156 if (unsmob_context_mod ($2))
1159 parser->parser_error (@2, _ ("not a context mod"));
1160 $$ = Context_mod ().smobbed_copy ();
1165 context_modification_arg:
1170 optional_context_mod:
1174 | context_modification
1182 $$ = Context_mod ().smobbed_copy ();
1184 | context_mod_list context_mod {
1185 if (!SCM_UNBNDP ($2))
1186 unsmob_context_mod ($1)->add_context_mod ($2);
1188 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1189 Context_mod *md = unsmob_context_mod ($2);
1191 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1193 | context_mod_list context_mod_embedded {
1194 unsmob_context_mod ($1)->add_context_mods
1195 (unsmob_context_mod ($2)->get_mods ());
1204 /* Music that can be parsed without lookahead */
1207 | complex_music_prefix closed_music
1209 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1211 | music_function_call_closed
1217 | grouped_music_list
1221 simultaneous_music { $$ = $1; }
1222 | sequential_music { $$ = $1; }
1225 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1226 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1227 and this rule returns the reversed list of arguments. */
1229 /* Function argument lists come in a number of flavors. Whenever
1230 * LilyPond has to pick between different flavors, the decision is
1231 * either made because of tokens it has already seen, or it is
1232 * postponed until tokens suitable for making the decision come up.
1233 * For postponing decisions, it may be necessary that the competing
1234 * rules are written in a way making them compatible until a decision
1235 * can be made. Sometimes this is done by putting common traits into
1236 * a separate "common" rule set.
1238 * function_arglist: a full argument list. Optional arguments at the
1239 * end of the list can only be skipped by writing \default in their
1242 * function_arglist_backup: an argument list ending in an optional
1243 * argument that may be skipped depending on its predicate.
1245 * function_arglist_skip: an argument list _not_ ending in an optional
1246 * argument that is actually taken.
1248 * function_arglist_nonbackup: an argument list ending in an optional
1249 * argument that may not be skipped because it is in end position and
1250 * has not been shortcircuited with \default.
1252 * function_arglist* / function_arglist_closed*: The closed variants
1253 * don't end in simple music expressions that might still accept
1254 * things like a duration or a postevent.
1257 function_arglist_skip:
1258 function_arglist_common
1259 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1261 $$ = scm_cons ($1, $3);
1262 } %prec FUNCTION_ARGLIST
1263 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1265 $$ = scm_cons ($1, $3);
1266 } %prec FUNCTION_ARGLIST
1270 function_arglist_nonbackup_common:
1271 EXPECT_OPTIONAL EXPECT_SCM function_arglist FRACTION
1273 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1275 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1277 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1279 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1281 SCM n = scm_difference ($5, SCM_UNDEFINED);
1282 if (scm_is_true (scm_call_1 ($2, n)))
1283 $$ = scm_cons (n, $3);
1285 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1286 t->set_property ("digit", $5);
1287 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1292 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1294 $$ = check_scheme_arg (parser, @4,
1295 scm_difference ($5, SCM_UNDEFINED),
1298 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1300 $$ = check_scheme_arg (parser, @4,
1301 scm_difference ($5, SCM_UNDEFINED),
1306 function_arglist_closed_nonbackup:
1307 function_arglist_nonbackup_common
1308 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1310 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1312 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1314 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1316 | EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1318 $$ = check_scheme_arg (parser, @4,
1319 try_string_variants ($2, $4),
1322 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1324 $$ = check_scheme_arg (parser, @4,
1325 try_string_variants ($2, $4),
1328 | EXPECT_OPTIONAL EXPECT_SCM function_arglist full_markup
1330 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1336 | SYMBOL_LIST '.' symbol_list_rev
1338 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1344 | symbol_list_rev '.' symbol_list_part
1346 $$ = scm_append_x (scm_list_2 ($3, $1));
1350 // symbol_list_part delivers elements in reverse copy.
1355 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1356 $$ = try_string_variants (sym_l_p, $1);
1357 if (SCM_UNBNDP ($$)) {
1358 parser->parser_error (@1, _("not a symbol"));
1361 $$ = scm_reverse ($$);
1366 symbol_list_element:
1372 function_arglist_nonbackup:
1373 function_arglist_nonbackup_common
1374 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length
1376 $$ = scm_cons ($4, $3);
1378 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1380 if (scm_is_true (scm_call_1 ($2, $4)))
1381 $$ = scm_cons ($4, $3);
1383 $$ = check_scheme_arg (parser, @4,
1384 make_music_from_simple
1388 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1390 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1392 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1394 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1396 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1398 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1400 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1402 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1406 function_arglist_nonbackup_reparse:
1407 EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1410 SCM res = try_string_variants ($2, $4);
1411 if (!SCM_UNBNDP (res))
1412 if (scm_is_pair (res))
1413 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1415 MYREPARSE (@4, $2, SCM_ARG, res);
1416 else if (scm_is_true
1418 ($2, make_music_from_simple
1420 MYREPARSE (@4, $2, STRING, $4);
1422 MYREPARSE (@4, $2, SCM_ARG, $4);
1424 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1427 SCM res = try_string_variants ($2, $4);
1428 if (!SCM_UNBNDP (res))
1429 if (scm_is_pair (res))
1430 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1432 MYREPARSE (@4, $2, SCM_ARG, res);
1433 else if (scm_is_true
1435 ($2, make_music_from_simple
1437 MYREPARSE (@4, $2, STRING, $4);
1439 MYREPARSE (@4, $2, SCM_ARG, $4);
1441 | EXPECT_OPTIONAL EXPECT_SCM function_arglist full_markup
1444 if (scm_is_true (scm_call_1 ($2, $4)))
1445 MYREPARSE (@4, $2, SCM_ARG, $4);
1446 else if (scm_is_true
1448 ($2, make_music_from_simple
1450 MYREPARSE (@4, $2, STRING, $4);
1452 MYREPARSE (@4, $2, SCM_ARG, $4);
1456 function_arglist_keep:
1457 function_arglist_common
1458 | function_arglist_backup
1461 function_arglist_closed_keep:
1462 function_arglist_closed_common
1463 | function_arglist_backup
1466 function_arglist_backup:
1467 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1469 if (scm_is_true (scm_call_1 ($2, $4)))
1471 $$ = scm_cons ($4, $3);
1473 $$ = scm_cons (loc_on_music (@3, $1), $3);
1474 MYBACKUP (SCM_ARG, $4, @4);
1477 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1479 if (scm_is_true (scm_call_1 ($2, $4)))
1481 $$ = scm_cons ($4, $3);
1483 $$ = scm_cons (loc_on_music (@3, $1), $3);
1484 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1487 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep full_markup
1489 if (scm_is_true (scm_call_1 ($2, $4)))
1490 $$ = scm_cons ($4, $3);
1492 $$ = scm_cons (loc_on_music (@3, $1), $3);
1493 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1496 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1498 if (scm_is_true (scm_call_1 ($2, $4)))
1501 MYREPARSE (@4, $2, UNSIGNED, $4);
1503 $$ = scm_cons (loc_on_music (@3, $1), $3);
1504 MYBACKUP (UNSIGNED, $4, @4);
1507 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1509 if (scm_is_true (scm_call_1 ($2, $4)))
1512 MYREPARSE (@4, $2, REAL, $4);
1514 $$ = scm_cons (loc_on_music (@3, $1), $3);
1515 MYBACKUP (REAL, $4, @4);
1518 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1520 if (scm_is_true (scm_call_1 ($2, $4)))
1522 $$ = scm_cons ($4, $3);
1524 $$ = scm_cons (loc_on_music (@3, $1), $3);
1525 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1528 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1530 if (scm_is_true (scm_call_1 ($2, $4)))
1532 $$ = scm_cons ($4, $3);
1534 $$ = scm_cons (loc_on_music (@3, $1), $3);
1535 MYBACKUP (FRACTION, $4, @4);
1538 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1540 SCM n = scm_difference ($5, SCM_UNDEFINED);
1541 if (scm_is_true (scm_call_1 ($2, n))) {
1543 MYREPARSE (@5, $2, REAL, n);
1545 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1546 t->set_property ("digit", $5);
1547 $$ = t->unprotect ();
1548 if (scm_is_true (scm_call_1 ($2, $$)))
1549 $$ = scm_cons ($$, $3);
1551 $$ = scm_cons (loc_on_music (@3, $1), $3);
1552 MYBACKUP (UNSIGNED, $5, @5);
1553 parser->lexer_->push_extra_token ('-');
1558 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1560 SCM n = scm_difference ($5, SCM_UNDEFINED);
1561 if (scm_is_true (scm_call_1 ($2, n))) {
1562 MYREPARSE (@5, $2, REAL, n);
1565 $$ = scm_cons (loc_on_music (@3, $1), $3);
1566 MYBACKUP (REAL, n, @5);
1569 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1571 SCM n = scm_difference ($5, SCM_UNDEFINED);
1572 if (scm_is_true (scm_call_1 ($2, n))) {
1573 $$ = scm_cons (n, $3);
1575 $$ = scm_cons (loc_on_music (@3, $1), $3);
1576 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1579 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep PITCH_IDENTIFIER
1581 if (scm_is_true (scm_call_1 ($2, $4)))
1583 $$ = scm_cons ($4, $3);
1585 $$ = scm_cons (loc_on_music (@3, $1), $3);
1586 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1589 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep NOTENAME_PITCH
1591 if (scm_is_true (scm_call_1 ($2, $4)))
1593 MYREPARSE (@4, $2, NOTENAME_PITCH, $4);
1596 $$ = scm_cons (loc_on_music (@3, $1), $3);
1597 MYBACKUP (NOTENAME_PITCH, $4, @4);
1600 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep TONICNAME_PITCH
1602 if (scm_is_true (scm_call_1 ($2, $4)))
1604 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1607 $$ = scm_cons (loc_on_music (@3, $1), $3);
1608 MYBACKUP (TONICNAME_PITCH, $4, @4);
1611 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1613 $$ = scm_cons ($4, $3);
1615 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep SCM_IDENTIFIER
1617 SCM res = try_string_variants ($2, $4);
1618 if (!SCM_UNBNDP (res))
1619 if (scm_is_pair (res)) {
1621 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1624 $$ = scm_cons (res, $3);
1626 $$ = scm_cons (loc_on_music (@3, $1), $3);
1627 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1630 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep STRING
1632 SCM res = try_string_variants ($2, $4);
1633 if (!SCM_UNBNDP (res))
1634 if (scm_is_pair (res)) {
1636 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1639 $$ = scm_cons (res, $3);
1641 $$ = scm_cons (loc_on_music (@3, $1), $3);
1642 MYBACKUP (STRING, $4, @4);
1645 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1647 $$ = scm_cons ($1, $3);
1648 MYBACKUP(0, SCM_UNDEFINED, @3);
1650 | function_arglist_backup REPARSE bare_number
1652 $$ = check_scheme_arg (parser, @3,
1655 | function_arglist_backup REPARSE symbol_list_arg
1657 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1659 | function_arglist_backup REPARSE pitch_also_in_chords
1661 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1666 function_arglist_common
1667 | function_arglist_nonbackup
1670 function_arglist_common:
1671 function_arglist_bare
1672 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1674 if (scm_is_true (scm_call_1 ($1, $3)))
1675 $$ = scm_cons ($3, $2);
1677 $$ = check_scheme_arg (parser, @3,
1678 make_music_from_simple
1682 | EXPECT_SCM function_arglist_closed_optional bare_number
1684 $$ = check_scheme_arg (parser, @3,
1687 | EXPECT_SCM function_arglist_optional FRACTION
1689 $$ = check_scheme_arg (parser, @3,
1692 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1694 $$ = check_scheme_arg (parser, @3,
1697 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1699 SCM n = scm_difference ($4, SCM_UNDEFINED);
1700 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1702 | function_arglist_common_reparse REPARSE SCM_ARG
1704 $$ = check_scheme_arg (parser, @3,
1707 | function_arglist_common_reparse REPARSE lyric_element_music
1709 $$ = check_scheme_arg (parser, @3,
1712 | function_arglist_common_reparse REPARSE bare_number
1714 $$ = check_scheme_arg (parser, @3,
1717 | function_arglist_common_reparse REPARSE symbol_list_arg
1719 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1723 function_arglist_common_reparse:
1724 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1727 SCM res = try_string_variants ($1, $3);
1728 if (!SCM_UNBNDP (res))
1729 if (scm_is_pair (res))
1730 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1732 MYREPARSE (@3, $1, SCM_ARG, res);
1733 else if (scm_is_true
1735 ($1, make_music_from_simple (parser, @3, $3))))
1736 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1738 // This is going to flag a syntax error, we
1739 // know the predicate to be false.
1740 MYREPARSE (@3, $1, SCM_ARG, $3);
1742 | EXPECT_SCM function_arglist_optional STRING
1745 SCM res = try_string_variants ($1, $3);
1746 if (!SCM_UNBNDP (res))
1747 if (scm_is_pair (res))
1748 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1750 MYREPARSE (@3, $1, SCM_ARG, res);
1751 else if (scm_is_true
1753 ($1, make_music_from_simple (parser, @3, $3))))
1754 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1756 // This is going to flag a syntax error, we
1757 // know the predicate to be false.
1758 MYREPARSE (@3, $1, SCM_ARG, $3);
1760 | EXPECT_SCM function_arglist_optional full_markup
1763 if (scm_is_true (scm_call_1 ($1, $3)))
1764 MYREPARSE (@3, $1, SCM_ARG, $3);
1765 else if (scm_is_true
1767 ($1, make_music_from_simple (parser, @3, $3))))
1768 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1770 // This is going to flag a syntax error, we
1771 // know the predicate to be false.
1772 MYREPARSE (@3, $1, SCM_ARG, $3);
1774 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1777 SCM n = scm_difference ($4, SCM_UNDEFINED);
1778 if (scm_is_true (scm_call_1 ($1, n)))
1779 MYREPARSE (@4, $1, REAL, n);
1781 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1782 t->set_property ("digit", $4);
1783 SCM m = t->unprotect ();
1784 if (scm_is_true (scm_call_1 ($1, m)))
1785 MYREPARSE (@4, $1, SCM_ARG, m);
1787 MYREPARSE (@4, $1, SCM_ARG, $4);
1791 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1794 SCM n = scm_difference ($4, SCM_UNDEFINED);
1795 MYREPARSE (@4, $1, REAL, n);
1799 function_arglist_closed:
1800 function_arglist_closed_common
1801 | function_arglist_closed_nonbackup
1804 function_arglist_closed_common:
1805 function_arglist_bare
1806 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1808 $$ = check_scheme_arg (parser, @3,
1811 | EXPECT_SCM function_arglist_closed_optional bare_number
1813 $$ = check_scheme_arg (parser, @3,
1816 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1818 $$ = check_scheme_arg (parser, @3,
1819 scm_difference ($4, SCM_UNDEFINED),
1822 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1824 $$ = check_scheme_arg (parser, @3,
1827 | EXPECT_SCM function_arglist_optional FRACTION
1829 $$ = check_scheme_arg (parser, @3,
1832 | function_arglist_common_reparse REPARSE SCM_ARG
1834 $$ = check_scheme_arg (parser, @3,
1837 | function_arglist_common_reparse REPARSE bare_number
1839 $$ = check_scheme_arg (parser, @3,
1842 | function_arglist_common_reparse REPARSE symbol_list_arg
1844 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1848 function_arglist_optional:
1849 function_arglist_keep %prec FUNCTION_ARGLIST
1850 | function_arglist_backup BACKUP
1851 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1853 $$ = scm_cons ($1, $3);
1857 function_arglist_closed_optional:
1858 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1859 | function_arglist_backup BACKUP
1860 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1862 $$ = scm_cons ($1, $3);
1866 embedded_scm_closed:
1868 | scm_function_call_closed
1871 embedded_scm_arg_closed:
1872 embedded_scm_bare_arg
1873 | scm_function_call_closed
1877 scm_function_call_closed:
1878 SCM_FUNCTION function_arglist_closed {
1879 $$ = MAKE_SYNTAX ("music-function", @$,
1881 } %prec FUNCTION_ARGLIST
1884 function_arglist_bare:
1885 EXPECT_NO_MORE_ARGS {
1888 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1889 $$ = scm_cons ($3, $2);
1891 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1892 $$ = scm_cons ($1, $3);
1894 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1895 $$ = scm_cons ($1, $3);
1899 music_function_call:
1900 MUSIC_FUNCTION function_arglist {
1901 $$ = MAKE_SYNTAX ("music-function", @$,
1908 /**/ { $$ = SCM_EOL; }
1909 | '=' simple_string {
1916 | repeated_music { $$ = $1; }
1917 | re_rhythmed_music { $$ = $1; }
1918 | complex_music_prefix music
1920 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1924 complex_music_prefix:
1925 CONTEXT symbol optional_id optional_context_mod {
1926 Context_mod *ctxmod = unsmob_context_mod ($4);
1929 mods = ctxmod->get_mods ();
1930 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1932 | NEWCONTEXT symbol optional_id optional_context_mod {
1933 Context_mod *ctxmod = unsmob_context_mod ($4);
1936 mods = ctxmod->get_mods ();
1937 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1942 mode_changing_head grouped_music_list {
1943 if ($1 == ly_symbol2scm ("chords"))
1945 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1951 parser->lexer_->pop_state ();
1953 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1954 Context_mod *ctxmod = unsmob_context_mod ($2);
1957 mods = ctxmod->get_mods ();
1958 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1959 if ($1 == ly_symbol2scm ("ChordNames"))
1961 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1963 parser->lexer_->pop_state ();
1969 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1970 parser->lexer_->push_note_state (nn);
1972 $$ = ly_symbol2scm ("notes");
1976 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1977 parser->lexer_->push_note_state (nn);
1979 $$ = ly_symbol2scm ("drums");
1982 parser->lexer_->push_figuredbass_state ();
1984 $$ = ly_symbol2scm ("figures");
1987 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1988 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1989 nn = parser->lexer_->lookup_identifier ("pitchnames");
1990 parser->lexer_->push_chord_state (nn);
1991 $$ = ly_symbol2scm ("chords");
1995 { parser->lexer_->push_lyric_state ();
1996 $$ = ly_symbol2scm ("lyrics");
2000 mode_changing_head_with_context:
2002 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2003 parser->lexer_->push_note_state (nn);
2005 $$ = ly_symbol2scm ("DrumStaff");
2008 parser->lexer_->push_figuredbass_state ();
2010 $$ = ly_symbol2scm ("FiguredBass");
2013 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2014 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2015 nn = parser->lexer_->lookup_identifier ("pitchnames");
2016 parser->lexer_->push_chord_state (nn);
2017 $$ = ly_symbol2scm ("ChordNames");
2020 { parser->lexer_->push_lyric_state ();
2021 $$ = ly_symbol2scm ("Lyrics");
2026 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2029 /* Can also use music at the expensive of two S/Rs similar to
2030 \repeat \alternative */
2031 parser->lexer_->pop_state ();
2033 $$ = scm_cons ($3, SCM_EOL);
2035 | new_lyrics ADDLYRICS {
2036 parser->lexer_->push_lyric_state ();
2038 parser->lexer_->pop_state ();
2039 $$ = scm_cons ($4, $1);
2044 composite_music new_lyrics {
2045 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2047 | LYRICSTO simple_string {
2048 parser->lexer_->push_lyric_state ();
2050 parser->lexer_->pop_state ();
2051 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2056 CHANGE STRING '=' STRING {
2057 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
2064 $$ = scm_reverse_x ($1, SCM_EOL);
2066 | symbol_list_rev property_path {
2067 $$ = scm_reverse_x ($1, $2);
2073 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2076 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2078 | OVERRIDE property_path '=' scalar {
2079 if (scm_ilength ($2) < 2) {
2080 parser->parser_error (@2, _("bad grob property path"));
2083 $$ = scm_cons (ly_symbol2scm ("push"),
2084 scm_cons2 (scm_car ($2),
2089 | REVERT revert_arg {
2090 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2094 // This is all quite awkward for the sake of substantial backward
2095 // compatibility while at the same time allowing a more "natural" form
2096 // of specification not separating grob specification from grob
2097 // property path. The purpose of this definition of revert_arg is to
2098 // allow the symbol list which specifies grob and property to revert
2099 // to be optionally be split into two parts after the grob (which in
2100 // this case is just the first element of the list). symbol_list_part
2101 // is only one path component, but it can be parsed without lookahead,
2102 // so we can follow it with a synthetic BACKUP token when needed. If
2103 // the first symbol_list_part already contains multiple elements (only
2104 // possible if a Scheme expression provides them), we just parse for
2105 // additional elements introduced by '.', which is what the
2106 // SYMBOL_LIST backup in connection with the immediately following
2107 // rule using symbol_list_arg does.
2109 // As long as we don't have our coffers filled with both grob and at
2110 // least one grob property specification, the rest of the required
2111 // symbol list chain may be provided either with or without a leading
2112 // dot. This is for both allowing the traditional
2113 // \revert Accidental #'color
2114 // as well as well as the "naive" form
2115 // \revert Accidental.color
2118 revert_arg_backup BACKUP symbol_list_arg
2127 if (scm_is_null ($1)
2128 || scm_is_null (scm_cdr ($1)))
2129 MYBACKUP (SCM_ARG, $1, @1);
2131 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2135 // revert_arg_part delivers results in reverse
2138 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2140 $$ = scm_append_x (scm_list_2 ($5, $3));
2142 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2144 $$ = scm_append_x (scm_list_2 ($4, $3));
2149 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2150 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2152 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2153 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2154 | DENIES { $$ = ly_symbol2scm ("denies"); }
2156 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2157 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2158 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2159 | NAME { $$ = ly_symbol2scm ("context-name"); }
2163 property_operation { $$ = $1; }
2164 | context_def_mod STRING {
2165 $$ = scm_list_2 ($1, $2);
2167 | context_def_mod embedded_scm
2169 if (!scm_is_string ($2)
2170 && ly_symbol2scm ("consists") != $1
2171 && ly_symbol2scm ("remove") != $1)
2174 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2178 $$ = scm_list_2 ($1, $2);
2183 // If defined, at least two members.
2187 SCM l = scm_reverse_x ($1, SCM_EOL);
2190 (scm_object_property (scm_car (l),
2191 ly_symbol2scm ("is-grob?"))))
2192 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2193 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2194 parser->parser_error (@1, _ ("bad grob property path"));
2201 // If defined, at least three members
2205 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2207 parser->parser_error (@1, _ ("bad grob property path"));
2211 | grob_prop_spec property_path
2213 if (!SCM_UNBNDP ($1)) {
2214 $$ = scm_append_x (scm_list_2 ($1, $2));
2215 if (scm_is_null (scm_cddr ($$))) {
2216 parser->parser_error (@$, _ ("bad grob property path"));
2224 // Exactly two elements or undefined
2228 SCM l = scm_reverse_x ($1, SCM_EOL);
2229 switch (scm_ilength (l)) {
2231 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2235 parser->parser_error (@1, _ ("bad context property path"));
2242 simple_music_property_def:
2243 OVERRIDE grob_prop_path '=' scalar {
2244 if (SCM_UNBNDP ($2))
2247 $$ = scm_list_5 (scm_car ($2),
2248 ly_symbol2scm ("OverrideProperty"),
2254 | REVERT simple_revert_context revert_arg {
2255 $$ = scm_list_4 ($2,
2256 ly_symbol2scm ("RevertProperty"),
2260 | SET context_prop_spec '=' scalar {
2261 if (SCM_UNBNDP ($2))
2264 $$ = scm_list_4 (scm_car ($2),
2265 ly_symbol2scm ("PropertySet"),
2269 | UNSET context_prop_spec {
2270 if (SCM_UNBNDP ($2))
2273 $$ = scm_list_3 (scm_car ($2),
2274 ly_symbol2scm ("PropertyUnset"),
2280 // This is all quite awkward for the sake of substantial backward
2281 // compatibility while at the same time allowing a more "natural" form
2282 // of specification not separating grob specification from grob
2283 // property path. The purpose of this definition of
2284 // simple_revert_context is to allow the symbol list which specifies
2285 // grob and property to revert to be optionally be split into two
2286 // parts after the grob (which may be preceded by a context
2287 // specification, a case which we distinguish by checking whether the
2288 // first symbol is a valid grob symbol instead).
2290 // See revert_arg above for the main work horse of this arrangement.
2291 // simple_revert_context just caters for the context and delegates the
2292 // rest of the job to revert_arg.
2294 simple_revert_context:
2297 $1 = scm_reverse_x ($1, SCM_EOL);
2298 if (scm_is_null ($1)
2300 (scm_object_property (scm_car ($1),
2301 ly_symbol2scm ("is-grob?")))) {
2302 $$ = ly_symbol2scm ("Bottom");
2303 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2306 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2313 simple_music_property_def {
2314 if (SCM_UNBNDP ($1))
2315 $$ = MAKE_SYNTAX ("void-music", @1);
2317 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2328 simple_string: STRING {
2333 if (scm_is_string ($1)) {
2336 parser->parser_error (@1, (_ ("simple string expected")));
2337 $$ = scm_string (SCM_EOL);
2344 $$ = scm_string_to_symbol ($1);
2348 // This is a bit of overkill but makes the same
2349 // routine responsible for all symbol interpretations.
2350 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2352 if (SCM_UNBNDP ($$))
2354 parser->parser_error (@1, (_ ("symbol expected")));
2355 // Generate a unique symbol in case it is used
2356 // for an assignment or similar
2357 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2366 // The following is a rather defensive variant of admitting
2367 // negative numbers: the grammar would permit number_factor or
2368 // even number_expression. However, function arguments allow
2369 // only this simple kind of negative number, so to have things
2370 // like \tweak and \override behave reasonably similar, it
2371 // makes sense to rule out things like -- which are rather an
2372 // accent in function argument contexts.
2375 $$ = scm_difference ($2, SCM_UNDEFINED);
2383 embedded_scm_arg_closed
2385 // for scalar_closed to be an actually closed (no lookahead)
2386 // expression, we'd need to use bare_number_closed here. It
2387 // turns out that the only use of scalar_closed in TEMPO is
2388 // not of the kind requiring the full closedness criterion.
2392 $$ = scm_difference ($2, SCM_UNDEFINED);
2401 simple_element post_events {
2402 // Let the rhythmic music iterator sort this mess out.
2403 if (scm_is_pair ($2)) {
2404 $$ = make_music_from_simple (parser, @1, $1);
2405 if (unsmob_music ($$))
2406 unsmob_music ($$)->set_property ("articulations",
2407 scm_reverse_x ($2, SCM_EOL));
2409 parser->parser_error (@1, _("music expected"));
2412 | simple_chord_elements post_events {
2413 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2416 /* why is this giving wrong start location? -ns
2418 i.set_location (@1, @2);
2419 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2421 | CHORD_REPETITION optional_notemode_duration post_events {
2423 i.set_location (@1, @3);
2424 $$ = MAKE_SYNTAX ("repetition-chord", i,
2425 $2, scm_reverse_x ($3, SCM_EOL));
2427 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2429 i.set_location (@1, @3);
2430 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2431 scm_reverse_x ($3, SCM_EOL));
2434 | note_chord_element
2439 chord_body optional_notemode_duration post_events
2441 Music *m = unsmob_music ($1);
2442 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2443 SCM es = m->get_property ("elements");
2444 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2446 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2447 unsmob_music (scm_car (s))->set_property ("duration", dur);
2448 es = ly_append2 (es, postevs);
2450 m-> set_property ("elements", es);
2452 $$ = m->self_scm ();
2457 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2459 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2463 chord_body_elements:
2464 /* empty */ { $$ = SCM_EOL; }
2465 | chord_body_elements chord_body_element {
2466 if (!SCM_UNBNDP ($2))
2467 $$ = scm_cons ($2, $1);
2472 pitch exclamations questions octave_check post_events
2474 bool q = to_boolean ($3);
2475 bool ex = to_boolean ($2);
2479 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2480 n->set_property ("pitch", $1);
2482 n->set_property ("cautionary", SCM_BOOL_T);
2484 n->set_property ("force-accidental", SCM_BOOL_T);
2486 if (scm_is_pair (post)) {
2487 SCM arts = scm_reverse_x (post, SCM_EOL);
2488 n->set_property ("articulations", arts);
2490 if (scm_is_number (check))
2492 int q = scm_to_int (check);
2493 n->set_property ("absolute-octave", scm_from_int (q-1));
2496 $$ = n->unprotect ();
2498 | DRUM_PITCH post_events {
2499 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2500 n->set_property ("drum-type", $1);
2502 if (scm_is_pair ($2)) {
2503 SCM arts = scm_reverse_x ($2, SCM_EOL);
2504 n->set_property ("articulations", arts);
2506 $$ = n->unprotect ();
2508 | music_function_chord_body
2510 Music *m = unsmob_music ($1);
2512 while (m && m->is_mus_type ("music-wrapper-music")) {
2513 $$ = m->get_property ("element");
2514 m = unsmob_music ($$);
2517 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2518 parser->parser_error (@$, _ ("not a rhythmic event"));
2524 music_function_chord_body:
2529 // Event functions may only take closed arglists, otherwise it would
2530 // not be clear whether a following postevent should be associated
2531 // with the last argument of the event function or with the expression
2532 // for which the function call acts itself as event.
2534 music_function_call_closed:
2535 MUSIC_FUNCTION function_arglist_closed {
2536 $$ = MAKE_SYNTAX ("music-function", @$,
2541 event_function_event:
2542 EVENT_FUNCTION function_arglist_closed {
2543 $$ = MAKE_SYNTAX ("music-function", @$,
2565 | post_events post_event {
2567 if (Music *m = unsmob_music ($2))
2569 if (m->is_mus_type ("post-event-wrapper"))
2571 for (SCM p = m->get_property ("elements");
2575 $$ = scm_cons (scm_car (p), $$);
2579 $$ = scm_cons ($2, $$);
2585 post_event_nofinger:
2586 direction_less_event {
2589 | script_dir music_function_call_closed {
2591 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2592 parser->parser_error (@2, _ ("post-event expected"));
2593 $$ = SCM_UNSPECIFIED;
2594 } else if (!SCM_UNBNDP ($1))
2596 unsmob_music ($$)->set_property ("direction", $1);
2600 if (!parser->lexer_->is_lyric_state ())
2601 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2602 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2605 if (!parser->lexer_->is_lyric_state ())
2606 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2607 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2609 | script_dir direction_reqd_event {
2610 if (!SCM_UNBNDP ($1))
2612 Music *m = unsmob_music ($2);
2613 m->set_property ("direction", $1);
2617 | script_dir direction_less_event {
2618 if (!SCM_UNBNDP ($1))
2620 Music *m = unsmob_music ($2);
2621 m->set_property ("direction", $1);
2628 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2633 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2644 string_number_event:
2646 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2647 s->set_property ("string-number", $1);
2648 $$ = s->unprotect ();
2652 direction_less_event:
2654 | EVENT_IDENTIFIER {
2658 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2659 a->set_property ("tremolo-type", $1);
2660 $$ = a->unprotect ();
2662 | event_function_event
2665 direction_reqd_event:
2669 | script_abbreviation {
2670 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2671 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2672 if (scm_is_string (s))
2673 a->set_property ("articulation-type", s);
2674 else parser->parser_error (@1, _ ("expecting string as script definition"));
2675 $$ = a->unprotect ();
2680 /**/ { $$ = SCM_EOL; }
2681 | '=' quotes { $$ = $2; }
2695 $$ = scm_from_int (1);
2698 $$ = scm_oneplus ($1);
2704 $$ = scm_from_int (-1);
2707 $$ = scm_oneminus ($1);
2712 NOTENAME_PITCH quotes {
2713 if (!scm_is_eq (SCM_INUM0, $2))
2715 Pitch p = *unsmob_pitch ($1);
2716 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2717 $$ = p.smobbed_copy ();
2727 TONICNAME_PITCH quotes {
2728 if (!scm_is_eq (SCM_INUM0, $2))
2730 Pitch p = *unsmob_pitch ($1);
2731 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2732 $$ = p.smobbed_copy ();
2742 pitch_also_in_chords:
2749 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2750 t->set_property ("text", $1);
2751 $$ = t->unprotect ();
2754 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2755 t->set_property ("text",
2756 make_simple_markup ($1));
2757 $$ = t->unprotect ();
2759 | embedded_scm_closed
2761 Music *m = unsmob_music ($1);
2762 if (m && m->is_mus_type ("post-event"))
2764 else if (Text_interface::is_markup ($1)) {
2765 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2766 t->set_property ("text", $1);
2767 $$ = t->unprotect ();
2769 parser->parser_error (@1, _ ("not an articulation"));
2775 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2776 t->set_property ("digit", $1);
2777 $$ = t->unprotect ();
2781 script_abbreviation:
2783 $$ = scm_from_locale_string ("Hat");
2786 $$ = scm_from_locale_string ("Plus");
2789 $$ = scm_from_locale_string ("Dash");
2792 $$ = scm_from_locale_string ("Bang");
2795 $$ = scm_from_locale_string ("Larger");
2798 $$ = scm_from_locale_string ("Dot");
2801 $$ = scm_from_locale_string ("Underscore");
2806 '_' { $$ = scm_from_int (DOWN); }
2807 | '^' { $$ = scm_from_int (UP); }
2808 | '-' { $$ = SCM_UNDEFINED; }
2812 multiplied_duration {
2817 maybe_notemode_duration:
2821 | multiplied_duration {
2823 parser->default_duration_ = *unsmob_duration ($$);
2828 optional_notemode_duration:
2829 maybe_notemode_duration
2831 if (SCM_UNBNDP ($$))
2832 $$ = parser->default_duration_.smobbed_copy ();
2839 int n = scm_to_int ($1);
2840 if (!is_duration (n))
2841 parser->parser_error (@1, _f ("not a duration: %d", n));
2845 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2847 | DURATION_IDENTIFIER dots {
2848 Duration *d = unsmob_duration ($1);
2849 Duration k (d->duration_log (),
2850 d->dot_count () + scm_to_int ($2));
2851 k = k.compressed (d->factor ());
2852 scm_remember_upto_here_1 ($1);
2853 $$ = k.smobbed_copy ();
2857 multiplied_duration:
2861 | multiplied_duration '*' UNSIGNED {
2862 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2864 | multiplied_duration '*' FRACTION {
2865 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2867 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2876 $$ = scm_oneplus ($1);
2885 int n = scm_to_int ($2);
2886 if (!is_duration (n))
2887 parser->parser_error (@2, _f ("not a duration: %d", n));
2893 UNSIGNED { $$ = $1; }
2894 | STRING { $$ = $1; }
2895 | full_markup { $$ = $1; }
2898 // as an integer, it needs to be non-negative, and otherwise
2899 // it needs to be suitable as a markup.
2900 if (scm_is_integer ($1)
2901 ? scm_is_true (scm_negative_p ($1))
2902 : !Text_interface::is_markup ($1))
2904 parser->parser_error (@1, _ ("bass number expected"));
2910 figured_bass_alteration:
2911 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2912 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2913 | '!' { $$ = scm_from_int (0); }
2918 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2919 $$ = bfr->unprotect ();
2922 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2923 $$ = bfr->self_scm ();
2925 if (scm_is_number ($1))
2926 bfr->set_property ("figure", $1);
2927 else if (Text_interface::is_markup ($1))
2928 bfr->set_property ("text", $1);
2934 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2936 | bass_figure figured_bass_alteration {
2937 Music *m = unsmob_music ($1);
2938 if (scm_to_double ($2)) {
2939 SCM salter = m->get_property ("alteration");
2940 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2941 m->set_property ("alteration",
2942 scm_sum (alter, $2));
2944 m->set_property ("alteration", scm_from_int (0));
2947 | bass_figure figured_bass_modification {
2948 Music *m = unsmob_music ($1);
2949 m->set_property ($2, SCM_BOOL_T);
2954 figured_bass_modification:
2956 $$ = ly_symbol2scm ("augmented");
2959 $$ = ly_symbol2scm ("no-continuation");
2962 $$ = ly_symbol2scm ("diminished");
2965 $$ = ly_symbol2scm ("augmented-slash");
2975 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2983 | figure_list br_bass_figure {
2984 $$ = scm_cons ($2, $1);
2989 FIGURE_OPEN figure_list FIGURE_CLOSE {
2990 $$ = scm_reverse_x ($2, SCM_EOL);
2996 /**/ { $$ = SCM_BOOL_F; }
2997 | REST { $$ = SCM_BOOL_T; }
3001 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3002 if (!parser->lexer_->is_note_state ())
3003 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3004 if (!SCM_UNBNDP ($2)
3006 || scm_is_number ($4)
3008 || scm_is_true ($6))
3011 if (scm_is_true ($6))
3012 n = MY_MAKE_MUSIC ("RestEvent", @$);
3014 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3016 n->set_property ("pitch", $1);
3017 if (SCM_UNBNDP ($5))
3018 n->set_property ("duration",
3019 parser->default_duration_.smobbed_copy ());
3021 n->set_property ("duration", $5);
3023 if (scm_is_number ($4))
3025 int q = scm_to_int ($4);
3026 n->set_property ("absolute-octave", scm_from_int (q-1));
3029 if (to_boolean ($3))
3030 n->set_property ("cautionary", SCM_BOOL_T);
3031 if (to_boolean ($2) || to_boolean ($3))
3032 n->set_property ("force-accidental", SCM_BOOL_T);
3034 $$ = n->unprotect ();
3037 | DRUM_PITCH optional_notemode_duration {
3038 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3039 n->set_property ("duration", $2);
3040 n->set_property ("drum-type", $1);
3042 $$ = n->unprotect ();
3044 | RESTNAME optional_notemode_duration {
3046 if (ly_scm2string ($1) == "s") {
3048 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3051 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3054 ev->set_property ("duration", $2);
3055 $$ = ev->unprotect ();
3059 simple_chord_elements:
3061 if (!parser->lexer_->is_chord_state ())
3062 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3065 | figure_spec optional_notemode_duration {
3066 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3068 unsmob_music (scm_car (s))->set_property ("duration", $2);
3076 if (!parser->lexer_->is_lyric_state ())
3077 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3081 if (!parser->lexer_->is_lyric_state ())
3082 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3088 lyric_element_music:
3089 lyric_element optional_notemode_duration post_events {
3090 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3091 if (scm_is_pair ($3))
3092 unsmob_music ($$)->set_property
3093 ("articulations", scm_reverse_x ($3, SCM_EOL));
3098 steno_tonic_pitch optional_notemode_duration {
3099 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3101 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3102 SCM its = scm_reverse_x ($4, SCM_EOL);
3103 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3111 | chord_items chord_item {
3112 $$ = scm_cons ($2, $$);
3118 $$ = ly_symbol2scm ("chord-colon");
3121 $$ = ly_symbol2scm ("chord-caret");
3123 | CHORD_SLASH steno_tonic_pitch {
3124 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3126 | CHORD_BASS steno_tonic_pitch {
3127 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3136 $$ = scm_reverse_x ($1, SCM_EOL);
3144 step_number { $$ = scm_cons ($1, SCM_EOL); }
3145 | step_numbers '.' step_number {
3146 $$ = scm_cons ($3, $$);
3152 $$ = make_chord_step ($1, 0);
3155 $$ = make_chord_step ($1, SHARP_ALTERATION);
3157 | UNSIGNED CHORD_MINUS {
3158 $$ = make_chord_step ($1, FLAT_ALTERATION);
3166 | UNSIGNED '-' UNSIGNED {
3167 $$ = scm_cons ($1, $3);
3174 TODO: should deprecate in favor of Scheme?
3178 number_expression '+' number_term {
3179 $$ = scm_sum ($1, $3);
3181 | number_expression '-' number_term {
3182 $$ = scm_difference ($1, $3);
3191 | number_factor '*' number_factor {
3192 $$ = scm_product ($1, $3);
3194 | number_factor '/' number_factor {
3195 $$ = scm_divide ($1, $3);
3200 '-' number_factor { /* %prec UNARY_MINUS */
3201 $$ = scm_difference ($2, SCM_UNDEFINED);
3209 | UNSIGNED NUMBER_IDENTIFIER {
3210 $$ = scm_product ($1, $2);
3212 | REAL NUMBER_IDENTIFIER {
3213 $$ = scm_product ($1, $2);
3229 { $$ = SCM_UNDEFINED; }
3232 if (SCM_UNBNDP ($1))
3240 { $$ = SCM_UNDEFINED; }
3243 if (SCM_UNBNDP ($1))
3252 { parser->lexer_->push_markup_state (); }
3255 parser->lexer_->pop_state ();
3261 { parser->lexer_->push_markup_state (); }
3264 parser->lexer_->pop_state ();
3269 simple_markup_list {
3270 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3272 | markup_head_1_list simple_markup
3274 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3275 @2, $1, scm_list_1 ($2)));
3285 if (Text_interface::is_markup ($1))
3286 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3287 else if (Text_interface::is_markup_list ($1))
3288 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3290 parser->parser_error (@1, _ ("not a markup"));
3291 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3298 markup_composed_list {
3301 | markup_uncomposed_list
3304 markup_uncomposed_list:
3305 markup_braced_list {
3308 | markup_command_list {
3309 $$ = scm_list_1 ($1);
3311 | markup_scm MARKUPLIST_IDENTIFIER
3321 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $1));
3327 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3328 parser->lexer_->push_note_state (nn);
3329 } '{' score_body '}' {
3331 parser->lexer_->pop_state ();
3335 markup_composed_list:
3336 markup_head_1_list markup_uncomposed_list {
3337 $$ = MAKE_SYNTAX ("composed-markup-list",
3343 '{' markup_braced_list_body '}' {
3344 $$ = scm_reverse_x ($2, SCM_EOL);
3348 markup_braced_list_body:
3349 /* empty */ { $$ = SCM_EOL; }
3350 | markup_braced_list_body markup {
3351 $$ = scm_cons ($2, $1);
3353 | markup_braced_list_body simple_markup_list {
3354 $$ = scm_reverse_x ($2, $1);
3358 markup_command_list:
3359 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3360 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3364 markup_command_basic_arguments:
3365 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3366 $$ = scm_cons ($3, $2);
3368 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3369 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3371 | EXPECT_NO_MORE_ARGS {
3376 markup_command_list_arguments:
3377 markup_command_basic_arguments { $$ = $1; }
3378 | EXPECT_MARKUP markup_command_list_arguments markup {
3379 $$ = scm_cons ($3, $2);
3384 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3385 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3390 markup_head_1_item {
3391 $$ = scm_list_1 ($1);
3393 | markup_head_1_list markup_head_1_item {
3394 $$ = scm_cons ($2, $1);
3400 $$ = make_simple_markup ($1);
3402 | MARKUP_FUNCTION markup_command_basic_arguments {
3403 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3405 | markup_scm MARKUP_IDENTIFIER
3411 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $1);
3416 markup_head_1_list simple_markup
3418 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3419 @2, $1, scm_list_1 ($2)));
3429 Lily_parser::set_yydebug (bool x)
3435 Lily_parser::do_yyparse ()
3437 SCM retval = SCM_UNDEFINED;
3438 yyparse (this, &retval);
3448 It is a little strange to have this function in this file, but
3449 otherwise, we have to import music classes into the lexer.
3453 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3455 if (unsmob_book (sid)) {
3456 Book *book = unsmob_book (sid)->clone ();
3457 *destination = book->self_scm ();
3460 return BOOK_IDENTIFIER;
3461 } else if (scm_is_number (sid)) {
3463 return NUMBER_IDENTIFIER;
3464 } else if (unsmob_context_def (sid)) {
3465 Context_def *def= unsmob_context_def (sid)->clone ();
3467 *destination = def->self_scm ();
3470 return CONTEXT_DEF_IDENTIFIER;
3471 } else if (unsmob_context_mod (sid)) {
3472 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3474 return CONTEXT_MOD_IDENTIFIER;
3475 } else if (Music *mus = unsmob_music (sid)) {
3476 mus = mus->clone ();
3477 *destination = mus->self_scm ();
3478 bool is_event = mus->is_mus_type ("post-event");
3480 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3481 } else if (unsmob_pitch (sid)) {
3482 *destination = unsmob_pitch (sid)->smobbed_copy ();
3483 return PITCH_IDENTIFIER;
3484 } else if (unsmob_duration (sid)) {
3485 *destination = unsmob_duration (sid)->smobbed_copy ();
3486 return DURATION_IDENTIFIER;
3487 } else if (unsmob_output_def (sid)) {
3488 Output_def *p = unsmob_output_def (sid);
3491 *destination = p->self_scm ();
3493 return OUTPUT_DEF_IDENTIFIER;
3500 get_next_unique_context_id ()
3502 return scm_from_locale_string ("$uniqueContextId");
3507 get_next_unique_lyrics_context_id ()
3509 static int new_context_count;
3511 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3512 return scm_from_locale_string (s);
3515 // check_scheme_arg checks one argument with a given predicate for use
3516 // in an argument list and throws a syntax error if it is unusable.
3517 // The argument is prepended to the argument list in any case. After
3518 // throwing a syntax error, the argument list is terminated with #f as
3519 // its last cdr in order to mark it as uncallable while not losing
3520 // track of its total length.
3522 // There are a few special considerations: if optional argument disp
3523 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3524 // instead of arg in a prospective error message. This is useful if
3525 // arg is not the actual argument but rather a transformation of it.
3527 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3528 // and an error message using disp is produced unconditionally.
3530 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3531 SCM arg, SCM args, SCM pred, SCM disp)
3533 if (SCM_UNBNDP (arg))
3534 args = scm_cons (disp, args);
3536 args = scm_cons (arg, args);
3537 if (scm_is_true (scm_call_1 (pred, arg)))
3540 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3541 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3542 SCM_UNBNDP (disp) ? arg : disp);
3543 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3547 SCM loc_on_music (Input loc, SCM arg)
3549 if (Music *m = unsmob_music (arg))
3553 return m->unprotect ();
3559 try_string_variants (SCM pred, SCM str)
3561 // a matching predicate is always ok
3562 if (scm_is_true (scm_call_1 (pred, str)))
3564 // a symbol may be interpreted as a list of symbols if it helps
3565 if (scm_is_symbol (str)) {
3566 str = scm_list_1 (str);
3567 if (scm_is_true (scm_call_1 (pred, str)))
3569 return SCM_UNDEFINED;
3572 // If this cannot be a string representation of a symbol list,
3575 if (!is_regular_identifier (str, true))
3576 return SCM_UNDEFINED;
3578 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3579 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3580 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3582 // Let's attempt the symbol list interpretation first.
3584 if (scm_is_true (scm_call_1 (pred, str)))
3587 // If there is just one symbol in the list, we might interpret
3588 // it as a single symbol
3590 if (scm_is_null (scm_cdr (str)))
3592 str = scm_car (str);
3593 if (scm_is_true (scm_call_1 (pred, str)))
3597 return SCM_UNDEFINED;
3601 is_regular_identifier (SCM id, bool multiple)
3603 if (!scm_is_string (id))
3606 string str = ly_scm2string (id);
3608 bool middle = false;
3610 for (string::iterator it=str.begin(); it != str.end (); it++)
3613 if ((c >= 'a' && c <= 'z')
3614 || (c >= 'A' && c <= 'Z')
3617 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3626 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3628 if (unsmob_music (simple))
3630 if (parser->lexer_->is_note_state ()) {
3631 if (scm_is_symbol (simple)) {
3632 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3633 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3634 n->set_property ("drum-type", simple);
3635 return n->unprotect ();
3637 if (unsmob_pitch (simple)) {
3638 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3639 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3640 n->set_property ("pitch", simple);
3641 return n->unprotect ();
3644 } else if (parser->lexer_->is_lyric_state ()) {
3645 if (Text_interface::is_markup (simple))
3646 return MAKE_SYNTAX ("lyric-event", loc, simple,
3647 parser->default_duration_.smobbed_copy ());
3648 } else if (parser->lexer_->is_chord_state ()) {
3649 if (unsmob_pitch (simple))
3650 return make_chord_elements (loc, simple,
3651 parser->default_duration_.smobbed_copy (),
3658 make_music_with_input (SCM name, Input where)
3660 Music *m = make_music_by_name (name);
3661 m->set_spot (where);
3666 make_simple_markup (SCM a)
3674 return t && t == 1 << intlog2 (t);
3678 make_chord_step (SCM step_scm, Rational alter)
3680 int step = scm_to_int (step_scm);
3683 alter += FLAT_ALTERATION;
3687 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3688 return m.smobbed_copy ();
3693 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3695 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3696 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3697 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3699 unsmob_music (scm_car (s))->set_spot (loc);
3705 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3707 Lily_lexer *lex = parser->lexer_;
3711 lex->prepare_for_next_token ();
3712 return lex->yylex ();