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 *, 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) make_music_with_input (ly_symbol2scm (x), spot)
200 - Don't use lily module, create a new module instead.
201 - delay application of the function
203 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
204 scm_apply_0 (proc, args)
205 /* Syntactic Sugar. */
206 #define MAKE_SYNTAX(name, location, ...) \
207 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (location) , ##__VA_ARGS__, SCM_UNDEFINED))
208 #define START_MAKE_SYNTAX(name, ...) \
209 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
210 #define FINISH_MAKE_SYNTAX(start, location, ...) \
211 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (location), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
213 SCM get_next_unique_context_id ();
214 SCM get_next_unique_lyrics_context_id ();
221 #define _(x) gettext (x)
225 static Music *make_music_with_input (SCM name, Input where);
226 SCM check_scheme_arg (Lily_parser *parser, Input loc,
227 SCM arg, SCM args, SCM pred);
228 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
229 SCM loc_on_music (Input loc, SCM arg);
230 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
231 SCM make_chord_step (SCM step, Rational alter);
232 SCM make_simple_markup (SCM a);
233 bool is_duration (int t);
234 bool is_regular_identifier (SCM id);
235 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
239 /* The third option is an alias that will be used to display the
240 syntax error. Bison CVS now correctly handles backslash escapes.
242 FIXME: Bison needs to translate some of these, eg, STRING.
246 /* Keyword tokens with plain escaped name. */
247 %token END_OF_FILE 0 "end of input"
248 %token ACCEPTS "\\accepts"
249 %token ADDLYRICS "\\addlyrics"
250 %token ALIAS "\\alias"
251 %token ALTERNATIVE "\\alternative"
253 %token BOOKPART "\\bookpart"
254 %token CHANGE "\\change"
255 %token CHORDMODE "\\chordmode"
256 %token CHORDS "\\chords"
257 %token CONSISTS "\\consists"
258 %token CONTEXT "\\context"
259 %token DEFAULT "\\default"
260 %token DEFAULTCHILD "\\defaultchild"
261 %token DENIES "\\denies"
262 %token DESCRIPTION "\\description"
263 %token DRUMMODE "\\drummode"
264 %token DRUMS "\\drums"
265 %token FIGUREMODE "\\figuremode"
266 %token FIGURES "\\figures"
267 %token HEADER "\\header"
268 %token INVALID "\\version-error"
269 %token LAYOUT "\\layout"
270 %token LYRICMODE "\\lyricmode"
271 %token LYRICS "\\lyrics"
272 %token LYRICSTO "\\lyricsto"
273 %token MARKUP "\\markup"
274 %token MARKUPLIST "\\markuplist"
277 %token NOTEMODE "\\notemode"
278 %token OVERRIDE "\\override"
279 %token PAPER "\\paper"
280 %token REMOVE "\\remove"
281 %token REPEAT "\\repeat"
283 %token REVERT "\\revert"
284 %token SCORE "\\score"
285 %token SEQUENTIAL "\\sequential"
287 %token SIMULTANEOUS "\\simultaneous"
288 %token TEMPO "\\tempo"
290 %token UNSET "\\unset"
293 /* Keyword token exceptions. */
294 %token NEWCONTEXT "\\new"
297 /* Other string tokens. */
299 %token CHORD_BASS "/+"
300 %token CHORD_CARET "^"
301 %token CHORD_COLON ":"
302 %token CHORD_MINUS "-"
303 %token CHORD_SLASH "/"
304 %token ANGLE_OPEN "<"
305 %token ANGLE_CLOSE ">"
306 %token DOUBLE_ANGLE_OPEN "<<"
307 %token DOUBLE_ANGLE_CLOSE ">>"
308 %token E_BACKSLASH "\\"
309 %token E_ANGLE_CLOSE "\\>"
310 %token E_CHAR "\\C[haracter]"
312 %token E_EXCLAMATION "\\!"
313 %token E_BRACKET_OPEN "\\["
315 %token E_BRACKET_CLOSE "\\]"
316 %token E_ANGLE_OPEN "\\<"
322 If we give names, Bison complains.
324 %token FIGURE_CLOSE /* "\\>" */
325 %token FIGURE_OPEN /* "\\<" */
326 %token FIGURE_SPACE "_"
329 %token CHORDMODIFIERS
331 %token MULTI_MEASURE_REST
337 /* Artificial tokens, for more generic function syntax */
338 %token EXPECT_MARKUP "markup?"
339 %token EXPECT_PITCH "ly:pitch?"
340 %token EXPECT_DURATION "ly:duration?"
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 CHORDMODIFIER_PITCH
354 %token CHORD_MODIFIER
355 %token CHORD_REPETITION
356 %token CONTEXT_DEF_IDENTIFIER
357 %token CONTEXT_MOD_IDENTIFIER
359 %token PITCH_IDENTIFIER
360 %token DURATION_IDENTIFIER
361 %token EVENT_IDENTIFIER
362 %token EVENT_FUNCTION
366 %token LYRIC_MARKUP_IDENTIFIER
367 %token MARKUP_FUNCTION
368 %token MARKUP_LIST_FUNCTION
369 %token MARKUP_IDENTIFIER
370 %token MARKUPLIST_IDENTIFIER
371 %token MUSIC_FUNCTION
372 %token MUSIC_IDENTIFIER
373 %token NOTENAME_PITCH
374 %token NUMBER_IDENTIFIER
375 %token OUTPUT_DEF_IDENTIFIER
379 %token SCM_IDENTIFIER
381 %token SCORE_IDENTIFIER
383 %token TONICNAME_PITCH
387 /* We don't assign precedence to / and *, because we might need varied
388 prec levels in different prods */
397 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
398 parser->lexer_->push_note_state (nn);
399 } embedded_lilypond {
400 parser->lexer_->pop_state ();
405 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
406 | lilypond toplevel_expression {
408 | lilypond assignment {
410 | lilypond embedded_scm {
413 parser->error_level_ = 1;
416 parser->error_level_ = 1;
423 parser->lexer_->add_scope (get_header (parser));
425 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
428 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
429 scm_call_2 (proc, parser->self_scm (), $1);
432 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
433 scm_call_2 (proc, parser->self_scm (), $1);
436 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
437 scm_call_2 (proc, parser->self_scm (), $1);
440 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
441 scm_call_2 (proc, parser->self_scm (), $1);
444 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
445 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
448 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
449 scm_call_2 (proc, parser->self_scm (), $1);
453 Output_def * od = unsmob_output_def ($1);
455 if (od->c_variable ("is-paper") == SCM_BOOL_T)
456 id = ly_symbol2scm ("$defaultpaper");
457 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
458 id = ly_symbol2scm ("$defaultmidi");
459 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
460 id = ly_symbol2scm ("$defaultlayout");
462 parser->lexer_->set_identifier (id, $1);
469 $$ = parser->lexer_->eval_scm_token ($1);
474 embedded_scm_bare_arg:
479 | context_modification
481 | context_def_spec_block
487 /* The generic version may end in music, or not */
495 embedded_scm_bare_arg
501 SCM_FUNCTION function_arglist {
502 $$ = MAKE_SYNTAX ("music-function", @$,
510 $$ = MAKE_SYNTAX ("void-music", @$);
513 | music_embedded music_embedded music_list {
514 $3 = scm_reverse_x ($3, SCM_EOL);
515 if (unsmob_music ($2))
516 $3 = scm_cons ($2, $3);
517 if (unsmob_music ($1))
518 $3 = scm_cons ($1, $3);
519 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
522 parser->error_level_ = 1;
523 $$ = SCM_UNSPECIFIED;
525 | INVALID embedded_lilypond {
526 parser->error_level_ = 1;
532 lilypond_header_body:
533 /* empty */ { $$ = SCM_UNSPECIFIED; }
534 | lilypond_header_body assignment {
537 | lilypond_header_body embedded_scm {
543 HEADER '{' lilypond_header_body '}' {
544 $$ = parser->lexer_->remove_scope ();
553 | LYRICS_STRING { $$ = $1; }
557 assignment_id '=' identifier_init {
558 parser->lexer_->set_identifier ($1, $3);
559 $$ = SCM_UNSPECIFIED;
561 | assignment_id property_path '=' identifier_init {
562 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
563 parser->lexer_->set_identifier (path, $4);
564 $$ = SCM_UNSPECIFIED;
574 | context_def_spec_block
576 | post_event_nofinger
582 | context_modification
585 context_def_spec_block:
586 CONTEXT '{' context_def_spec_body '}'
597 context_mod_embedded:
600 if (unsmob_music ($1)) {
601 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
602 $1 = scm_call_2 (proc, parser->self_scm (), $1);
604 if (unsmob_context_mod ($1))
607 parser->parser_error (@1, _ ("not a context mod"));
613 context_def_spec_body:
615 $$ = Context_def::make_scm ();
616 unsmob_context_def ($$)->origin ()->set_spot (@$);
618 | CONTEXT_DEF_IDENTIFIER {
620 unsmob_context_def ($$)->origin ()->set_spot (@$);
622 | context_def_spec_body context_mod {
623 unsmob_context_def ($$)->add_context_mod ($2);
625 | context_def_spec_body context_modification {
626 Context_def *td = unsmob_context_def ($$);
627 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
628 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
629 td->add_context_mod (scm_car (m));
632 | context_def_spec_body context_mod_embedded {
633 Context_def *td = unsmob_context_def ($$);
634 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
635 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
636 td->add_context_mod (scm_car (m));
644 BOOK '{' book_body '}' {
647 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
652 * Use 'handlers' like for toplevel-* stuff?
653 * grok \layout and \midi? */
656 Book *book = new Book;
657 init_papers (parser);
658 book->origin ()->set_spot (@$);
659 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
660 book->paper_->unprotect ();
661 push_paper (parser, book->paper_);
662 book->header_ = get_header (parser);
663 $$ = book->unprotect ();
664 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
667 unsmob_book ($1)->origin ()->set_spot (@$);
668 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
670 | book_body paper_block {
671 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
672 set_paper (parser, unsmob_output_def ($2));
674 | book_body bookpart_block {
675 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
676 scm_call_2 (proc, $1, $2);
678 | book_body score_block {
679 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
680 scm_call_2 (proc, $1, $2);
682 | book_body composite_music {
683 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
684 scm_call_3 (proc, parser->self_scm (), $1, $2);
686 | book_body full_markup {
687 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
688 scm_call_2 (proc, $1, scm_list_1 ($2));
690 | book_body full_markup_list {
691 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
692 scm_call_2 (proc, $1, $2);
696 parser->lexer_->add_scope (unsmob_book ($1)->header_);
698 | book_body embedded_scm { }
700 Book *book = unsmob_book ($1);
702 book->scores_ = SCM_EOL;
703 book->bookparts_ = SCM_EOL;
708 BOOKPART '{' bookpart_body '}' {
710 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
716 Book *book = new Book;
717 book->origin ()->set_spot (@$);
718 $$ = book->unprotect ();
719 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
722 unsmob_book ($1)->origin ()->set_spot (@$);
723 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
725 | bookpart_body paper_block {
726 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
728 | bookpart_body score_block {
729 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
730 scm_call_2 (proc, $1, $2);
732 | bookpart_body composite_music {
733 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
734 scm_call_3 (proc, parser->self_scm (), $1, $2);
736 | bookpart_body full_markup {
737 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
738 scm_call_2 (proc, $1, scm_list_1 ($2));
740 | bookpart_body full_markup_list {
741 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
742 scm_call_2 (proc, $1, $2);
746 Book *book = unsmob_book ($1);
747 if (!ly_is_module (book->header_))
748 book->header_ = ly_make_module (false);
749 parser->lexer_->add_scope (book->header_);
751 | bookpart_body embedded_scm { }
752 | bookpart_body error {
753 Book *book = unsmob_book ($1);
755 book->scores_ = SCM_EOL;
760 SCORE '{' score_body '}' {
767 SCM scorify = ly_lily_module_constant ("scorify-music");
768 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
770 unsmob_score ($$)->origin ()->set_spot (@$);
773 unsmob_score ($$)->origin ()->set_spot (@$);
777 Score *score = unsmob_score ($1);
778 if (!ly_is_module (score->get_header ()))
779 score->set_header (ly_make_module (false));
780 parser->lexer_->add_scope (score->get_header ());
782 | score_body output_def {
783 Output_def *od = unsmob_output_def ($2);
784 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
786 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
791 unsmob_score ($1)->add_output_def (od);
795 unsmob_score ($$)->error_found_ = true;
806 Output_def *od = unsmob_output_def ($1);
808 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
810 parser->parser_error (@1, _ ("need \\paper for paper block"));
811 $$ = get_paper (parser)->unprotect ();
818 output_def_body '}' {
821 parser->lexer_->remove_scope ();
822 parser->lexer_->pop_state ();
828 Output_def *p = get_paper (parser);
829 p->input_origin_ = @$;
830 parser->lexer_->add_scope (p->scope_);
831 $$ = p->unprotect ();
834 Output_def *p = get_midi (parser);
835 $$ = p->unprotect ();
836 parser->lexer_->add_scope (p->scope_);
839 Output_def *p = get_layout (parser);
841 parser->lexer_->add_scope (p->scope_);
842 $$ = p->unprotect ();
846 output_def_head_with_mode_switch:
848 parser->lexer_->push_initial_state ();
853 // We need this weird nonterminal because both music as well as a
854 // context definition can start with \context and the difference is
855 // only apparent after looking at the next token. If it is '{', there
856 // is still time to escape from notes mode.
858 music_or_context_def:
861 parser->lexer_->pop_state ();
865 parser->lexer_->pop_state ();
866 } '{' context_def_spec_body '}'
873 output_def_head_with_mode_switch '{' {
875 unsmob_output_def ($$)->input_origin_.set_spot (@$);
877 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
878 Output_def *o = unsmob_output_def ($3);
879 o->input_origin_.set_spot (@$);
881 parser->lexer_->remove_scope ();
882 parser->lexer_->add_scope (o->scope_);
884 | output_def_body assignment {
887 | output_def_body embedded_scm {
892 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
893 parser->lexer_->push_note_state (nn);
894 } music_or_context_def
896 if (unsmob_context_def ($3))
897 assign_context_def (unsmob_output_def ($1), $3);
900 SCM proc = parser->lexer_->lookup_identifier
901 ("output-def-music-handler");
902 scm_call_3 (proc, parser->self_scm (),
906 | output_def_body error {
912 TEMPO steno_duration '=' tempo_range {
913 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
915 | TEMPO scalar_closed steno_duration '=' tempo_range {
916 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
919 $$ = MAKE_SYNTAX ("tempo", @$, $2);
924 The representation of a list is reversed to have efficient append. */
930 | music_list music_embedded {
931 if (unsmob_music ($2))
932 $$ = scm_cons ($2, $1);
935 Music *m = MY_MAKE_MUSIC("Music", @$);
937 m->set_property ("error-found", SCM_BOOL_T);
938 $$ = scm_cons (m->self_scm (), $1);
939 m->unprotect (); /* UGH */
946 $$ = scm_reverse_x ($2, SCM_EOL);
951 | lyric_element_music
958 if (unsmob_music ($1)
959 || scm_is_eq ($1, SCM_UNSPECIFIED))
963 @$.warning (_ ("Ignoring non-music expression"));
964 $$ = SCM_UNSPECIFIED;
972 $$ = make_music_from_simple (parser, @1, $1);
973 if (!unsmob_music ($$))
974 parser->parser_error (@1, _ ("music expected"));
976 | composite_music %prec COMPOSITE
981 | composite_music %prec COMPOSITE
982 | lyric_element_music
986 REPEAT simple_string unsigned_number music
988 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
990 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
992 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
997 SEQUENTIAL braced_music_list {
998 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1000 | braced_music_list {
1001 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1006 SIMULTANEOUS braced_music_list {
1007 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1009 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1010 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1016 | music_property_def
1020 context_modification:
1021 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1023 parser->lexer_->pop_state ();
1026 | WITH CONTEXT_MOD_IDENTIFIER
1030 | CONTEXT_MOD_IDENTIFIER
1034 | WITH embedded_scm_closed
1036 if (unsmob_context_mod ($2))
1039 parser->parser_error (@2, _ ("not a context mod"));
1040 $$ = Context_mod ().smobbed_copy ();
1045 optional_context_mod:
1049 | context_modification
1057 $$ = Context_mod ().smobbed_copy ();
1059 | context_mod_list context_mod {
1060 unsmob_context_mod ($1)->add_context_mod ($2);
1062 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1063 Context_mod *md = unsmob_context_mod ($2);
1065 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1067 | context_mod_list context_mod_embedded {
1068 unsmob_context_mod ($1)->add_context_mods
1069 (unsmob_context_mod ($2)->get_mods ());
1078 /* Music that can be parsed without lookahead */
1081 | complex_music_prefix closed_music
1083 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1085 | music_function_call_closed
1091 | grouped_music_list
1095 simultaneous_music { $$ = $1; }
1096 | sequential_music { $$ = $1; }
1099 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1100 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1101 and this rule returns the reversed list of arguments. */
1103 function_arglist_skip:
1104 function_arglist_common
1105 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1107 $$ = scm_cons ($1, $3);
1108 } %prec FUNCTION_ARGLIST
1109 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1111 $$ = scm_cons ($1, $3);
1112 } %prec FUNCTION_ARGLIST
1113 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1115 $$ = scm_cons ($1, $3);
1116 } %prec FUNCTION_ARGLIST
1120 function_arglist_nonbackup_common:
1121 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1122 $$ = scm_cons ($4, $3);
1124 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1125 $$ = scm_cons ($4, $3);
1127 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1129 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1131 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1133 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1135 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1137 SCM n = scm_difference ($5, SCM_UNDEFINED);
1138 if (scm_is_true (scm_call_1 ($2, n)))
1139 $$ = scm_cons (n, $3);
1141 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1142 t->set_property ("digit", $5);
1143 $$ = t->unprotect ();
1144 if (scm_is_true (scm_call_1 ($2, $$)))
1145 $$ = scm_cons ($$, $3);
1147 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1151 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1153 $$ = check_scheme_arg (parser, @4,
1154 scm_difference ($5, SCM_UNDEFINED),
1157 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1159 $$ = check_scheme_arg (parser, @4,
1160 scm_difference ($5, SCM_UNDEFINED),
1165 function_arglist_closed_nonbackup:
1166 function_arglist_nonbackup_common
1167 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1169 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1171 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1173 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1177 function_arglist_nonbackup:
1178 function_arglist_nonbackup_common
1179 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1181 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1183 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1185 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1189 function_arglist_keep:
1190 function_arglist_common
1191 | function_arglist_backup
1194 function_arglist_closed_keep:
1195 function_arglist_closed_common
1196 | function_arglist_backup
1199 function_arglist_backup:
1200 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1202 if (scm_is_true (scm_call_1 ($2, $4)))
1204 $$ = scm_cons ($4, $3);
1206 $$ = scm_cons (loc_on_music (@3, $1), $3);
1207 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1210 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1212 if (scm_is_true (scm_call_1 ($2, $4)))
1214 $$ = scm_cons ($4, $3);
1216 $$ = scm_cons (loc_on_music (@3, $1), $3);
1217 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1220 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1222 // There is no point interpreting a lyrics string as
1223 // an event, since we don't allow music possibly
1224 // followed by durations or postevent into closed
1225 // music, and we only accept closed music in optional
1226 // arguments at the moment. If this changes, more
1227 // complex schemes might become interesting here as
1228 // well: see how we do this at the mandatory argument
1230 if (scm_is_true (scm_call_1 ($2, $4)))
1231 $$ = scm_cons ($4, $3);
1233 $$ = scm_cons (loc_on_music (@3, $1), $3);
1234 MYBACKUP (LYRICS_STRING, $4, @4);
1237 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1239 if (scm_is_true (scm_call_1 ($2, $4)))
1242 MYREPARSE (@4, $2, UNSIGNED, $4);
1244 $$ = scm_cons (loc_on_music (@3, $1), $3);
1245 MYBACKUP (UNSIGNED, $4, @4);
1248 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1250 if (scm_is_true (scm_call_1 ($2, $4)))
1253 MYREPARSE (@4, $2, REAL, $4);
1255 $$ = scm_cons (loc_on_music (@3, $1), $3);
1256 MYBACKUP (REAL, $4, @4);
1259 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1261 if (scm_is_true (scm_call_1 ($2, $4)))
1263 $$ = scm_cons ($4, $3);
1265 $$ = scm_cons (loc_on_music (@3, $1), $3);
1266 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1269 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1271 if (scm_is_true (scm_call_1 ($2, $4)))
1273 $$ = scm_cons ($4, $3);
1275 $$ = scm_cons (loc_on_music (@3, $1), $3);
1276 MYBACKUP (FRACTION, $4, @4);
1279 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1281 SCM n = scm_difference ($5, SCM_UNDEFINED);
1282 if (scm_is_true (scm_call_1 ($2, n))) {
1284 MYREPARSE (@5, $2, REAL, n);
1286 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1287 t->set_property ("digit", $5);
1288 $$ = t->unprotect ();
1289 if (scm_is_true (scm_call_1 ($2, $$)))
1290 $$ = scm_cons ($$, $3);
1292 $$ = scm_cons (loc_on_music (@3, $1), $3);
1293 MYBACKUP (UNSIGNED, $5, @5);
1294 parser->lexer_->push_extra_token ('-');
1299 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1301 SCM n = scm_difference ($5, SCM_UNDEFINED);
1302 if (scm_is_true (scm_call_1 ($2, n))) {
1303 MYREPARSE (@5, $2, REAL, n);
1306 MYBACKUP (REAL, n, @5);
1309 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1311 SCM n = scm_difference ($5, SCM_UNDEFINED);
1312 if (scm_is_true (scm_call_1 ($2, n))) {
1313 $$ = scm_cons (n, $3);
1315 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1318 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1320 $$ = scm_cons ($4, $3);
1322 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1324 $$ = scm_cons ($4, $3);
1326 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1328 $$ = scm_cons ($1, $3);
1329 MYBACKUP(0, SCM_UNDEFINED, @3);
1331 | function_arglist_backup REPARSE embedded_scm_arg_closed
1333 $$ = check_scheme_arg (parser, @3,
1336 | function_arglist_backup REPARSE bare_number
1338 $$ = check_scheme_arg (parser, @3,
1344 function_arglist_common
1345 | function_arglist_nonbackup
1348 function_arglist_common:
1349 function_arglist_bare
1350 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1352 $$ = check_scheme_arg (parser, @3,
1355 | EXPECT_SCM function_arglist_closed_optional bare_number
1357 $$ = check_scheme_arg (parser, @3,
1360 | EXPECT_SCM function_arglist_closed_optional FRACTION
1362 $$ = check_scheme_arg (parser, @3,
1365 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1367 $$ = check_scheme_arg (parser, @3,
1370 | function_arglist_common_minus
1371 | function_arglist_common_lyric
1374 function_arglist_common_lyric:
1375 EXPECT_SCM function_arglist_optional lyric_element
1377 // We check how the predicate thinks about a lyrics
1378 // event or about a markup. If it accepts neither, we
1379 // backup the original token. Otherwise we commit to
1380 // taking the token. Depending on what the predicate
1381 // is willing to accept, we interpret as a string, as
1382 // a lyric event, or ambiguously (meaning that if
1383 // something looking like a duration or post event
1384 // follows, we take the event, otherwise the string).
1385 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1386 parser->default_duration_.smobbed_copy ());
1387 if (scm_is_true (scm_call_1 ($1, $3)))
1388 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1391 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1393 $$ = scm_cons ($3, $2);
1395 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1398 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1400 // This is going to flag a syntax error, we
1401 // know the predicate to be false.
1402 check_scheme_arg (parser, @3,
1406 | function_arglist_common_lyric REPARSE lyric_element_arg
1408 // This should never be false
1409 $$ = check_scheme_arg (parser, @3,
1414 function_arglist_common_minus:
1415 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1417 SCM n = scm_difference ($4, SCM_UNDEFINED);
1418 if (scm_is_true (scm_call_1 ($1, n))) {
1420 MYREPARSE (@4, $1, REAL, n);
1422 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1423 t->set_property ("digit", $4);
1424 $$ = t->unprotect ();
1425 if (scm_is_true (scm_call_1 ($1, $$)))
1426 $$ = scm_cons ($$, $2);
1428 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1432 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1435 SCM n = scm_difference ($4, SCM_UNDEFINED);
1436 MYREPARSE (@4, $1, REAL, n);
1438 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1440 SCM n = scm_difference ($4, SCM_UNDEFINED);
1441 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1443 | function_arglist_common_minus REPARSE bare_number
1445 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1449 function_arglist_closed:
1450 function_arglist_closed_common
1451 | function_arglist_closed_nonbackup
1454 function_arglist_closed_common:
1455 function_arglist_bare
1456 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1458 $$ = check_scheme_arg (parser, @3,
1461 | EXPECT_SCM function_arglist_closed_optional bare_number
1463 $$ = check_scheme_arg (parser, @3,
1466 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1468 SCM n = scm_difference ($4, SCM_UNDEFINED);
1469 if (scm_is_true (scm_call_1 ($1, n))) {
1470 $$ = scm_cons (n, $2);
1472 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1473 t->set_property ("digit", $4);
1474 $$ = t->unprotect ();
1475 if (scm_is_true (scm_call_1 ($1, $$)))
1476 $$ = scm_cons ($$, $2);
1478 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1482 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1484 $$ = check_scheme_arg (parser, @3,
1485 scm_difference ($4, SCM_UNDEFINED),
1488 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1490 $$ = check_scheme_arg (parser, @3,
1491 scm_difference ($4, SCM_UNDEFINED),
1494 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1496 $$ = check_scheme_arg (parser, @3,
1499 | EXPECT_SCM function_arglist_closed_optional FRACTION
1501 $$ = check_scheme_arg (parser, @3,
1504 | EXPECT_SCM function_arglist_optional lyric_element
1506 $$ = check_scheme_arg (parser, @3,
1511 function_arglist_optional:
1512 function_arglist_keep %prec FUNCTION_ARGLIST
1513 | function_arglist_backup BACKUP
1514 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1516 $$ = scm_cons ($1, $3);
1518 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1520 $$ = scm_cons ($1, $3);
1524 function_arglist_closed_optional:
1525 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1526 | function_arglist_backup BACKUP
1527 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1529 $$ = scm_cons ($1, $3);
1531 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1533 $$ = scm_cons ($1, $3);
1537 embedded_scm_closed:
1539 | scm_function_call_closed
1542 embedded_scm_arg_closed:
1543 embedded_scm_bare_arg
1544 | scm_function_call_closed
1548 scm_function_call_closed:
1549 SCM_FUNCTION function_arglist_closed {
1550 $$ = MAKE_SYNTAX ("music-function", @$,
1552 } %prec FUNCTION_ARGLIST
1555 function_arglist_bare:
1556 EXPECT_NO_MORE_ARGS {
1559 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1560 $$ = scm_cons ($3, $2);
1562 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1563 $$ = scm_cons ($3, $2);
1565 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1566 $$ = scm_cons ($1, $3);
1568 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1569 $$ = scm_cons ($1, $3);
1571 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1572 $$ = scm_cons ($1, $3);
1576 music_function_call:
1577 MUSIC_FUNCTION function_arglist {
1578 $$ = MAKE_SYNTAX ("music-function", @$,
1585 /**/ { $$ = SCM_EOL; }
1586 | '=' simple_string {
1593 | repeated_music { $$ = $1; }
1594 | re_rhythmed_music { $$ = $1; }
1595 | complex_music_prefix music
1597 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1601 complex_music_prefix:
1602 CONTEXT simple_string optional_id optional_context_mod {
1603 Context_mod *ctxmod = unsmob_context_mod ($4);
1606 mods = ctxmod->get_mods ();
1607 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1609 | NEWCONTEXT simple_string optional_id optional_context_mod {
1610 Context_mod *ctxmod = unsmob_context_mod ($4);
1613 mods = ctxmod->get_mods ();
1614 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1619 mode_changing_head grouped_music_list {
1620 if ($1 == ly_symbol2scm ("chords"))
1622 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1628 parser->lexer_->pop_state ();
1630 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1631 Context_mod *ctxmod = unsmob_context_mod ($2);
1634 mods = ctxmod->get_mods ();
1635 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1636 if ($1 == ly_symbol2scm ("ChordNames"))
1638 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1640 parser->lexer_->pop_state ();
1646 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1647 parser->lexer_->push_note_state (nn);
1649 $$ = ly_symbol2scm ("notes");
1653 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1654 parser->lexer_->push_note_state (nn);
1656 $$ = ly_symbol2scm ("drums");
1659 parser->lexer_->push_figuredbass_state ();
1661 $$ = ly_symbol2scm ("figures");
1664 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1665 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1666 nn = parser->lexer_->lookup_identifier ("pitchnames");
1667 parser->lexer_->push_chord_state (nn);
1668 $$ = ly_symbol2scm ("chords");
1672 { parser->lexer_->push_lyric_state ();
1673 $$ = ly_symbol2scm ("lyrics");
1677 mode_changing_head_with_context:
1679 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1680 parser->lexer_->push_note_state (nn);
1682 $$ = ly_symbol2scm ("DrumStaff");
1685 parser->lexer_->push_figuredbass_state ();
1687 $$ = ly_symbol2scm ("FiguredBass");
1690 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1691 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1692 nn = parser->lexer_->lookup_identifier ("pitchnames");
1693 parser->lexer_->push_chord_state (nn);
1694 $$ = ly_symbol2scm ("ChordNames");
1697 { parser->lexer_->push_lyric_state ();
1698 $$ = ly_symbol2scm ("Lyrics");
1703 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1706 /* Can also use music at the expensive of two S/Rs similar to
1707 \repeat \alternative */
1708 parser->lexer_->pop_state ();
1710 $$ = scm_cons ($3, SCM_EOL);
1712 | new_lyrics ADDLYRICS {
1713 parser->lexer_->push_lyric_state ();
1715 parser->lexer_->pop_state ();
1716 $$ = scm_cons ($4, $1);
1721 composite_music new_lyrics {
1722 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1724 | LYRICSTO simple_string {
1725 parser->lexer_->push_lyric_state ();
1727 parser->lexer_->pop_state ();
1728 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1733 CHANGE STRING '=' STRING {
1734 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1739 property_path_revved:
1740 embedded_scm_closed {
1741 $$ = scm_cons ($1, SCM_EOL);
1743 | property_path_revved embedded_scm_closed {
1744 $$ = scm_cons ($2, $1);
1749 property_path_revved {
1750 $$ = scm_reverse_x ($1, SCM_EOL);
1756 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1757 scm_string_to_symbol ($1), $3);
1759 | UNSET simple_string {
1760 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1761 scm_string_to_symbol ($2));
1763 | OVERRIDE simple_string property_path '=' scalar {
1764 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1765 scm_string_to_symbol ($2), $5),
1768 | REVERT simple_string embedded_scm {
1769 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1770 scm_string_to_symbol ($2), $3);
1775 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1776 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1778 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1779 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1780 | DENIES { $$ = ly_symbol2scm ("denies"); }
1782 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1783 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1784 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1785 | NAME { $$ = ly_symbol2scm ("context-name"); }
1789 property_operation { $$ = $1; }
1790 | context_def_mod STRING {
1791 $$ = scm_list_2 ($1, $2);
1793 | context_def_mod embedded_scm
1795 if (!scm_is_string ($2)
1796 && ly_symbol2scm ("consists") != $1
1797 && ly_symbol2scm ("remove") != $1)
1800 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
1804 $$ = scm_list_2 ($1, $2);
1811 if (!is_regular_identifier ($1))
1813 @$.error (_("Grob name should be alphanumeric"));
1816 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1817 scm_string_to_symbol ($1));
1819 | simple_string '.' simple_string {
1820 $$ = scm_list_2 (scm_string_to_symbol ($1),
1821 scm_string_to_symbol ($3));
1825 simple_music_property_def:
1826 OVERRIDE context_prop_spec property_path '=' scalar {
1827 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1828 ly_symbol2scm ("OverrideProperty"),
1833 | REVERT context_prop_spec embedded_scm {
1834 $$ = scm_list_4 (scm_car ($2),
1835 ly_symbol2scm ("RevertProperty"),
1839 | SET context_prop_spec '=' scalar {
1840 $$ = scm_list_4 (scm_car ($2),
1841 ly_symbol2scm ("PropertySet"),
1845 | UNSET context_prop_spec {
1846 $$ = scm_list_3 (scm_car ($2),
1847 ly_symbol2scm ("PropertyUnset"),
1853 simple_music_property_def {
1854 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
1863 | string '+' string {
1864 if (!scm_is_string ($1)) {
1865 parser->parser_error (@1, (_ ("simple string expected")));
1866 $1 = scm_string (SCM_EOL);
1868 if (!scm_is_string ($3)) {
1869 parser->parser_error (@3, (_ ("simple string expected")));
1870 $3 = scm_string (SCM_EOL);
1872 $$ = scm_string_append (scm_list_2 ($1, $3));
1876 simple_string: STRING {
1884 if (scm_is_string ($1)) {
1887 parser->parser_error (@1, (_ ("simple string expected")));
1888 $$ = scm_string (SCM_EOL);
1891 | LYRIC_MARKUP_IDENTIFIER
1893 if (scm_is_string ($1)) {
1896 parser->parser_error (@1, (_ ("simple string expected")));
1897 $$ = scm_string (SCM_EOL);
1910 embedded_scm_arg_closed
1918 simple_element post_events {
1919 // Let the rhythmic music iterator sort this mess out.
1920 if (scm_is_pair ($2)) {
1921 $$ = make_music_from_simple (parser, @1, $1);
1922 if (unsmob_music ($$))
1923 unsmob_music ($$)->set_property ("articulations",
1924 scm_reverse_x ($2, SCM_EOL));
1926 parser->parser_error (@1, _("music expected"));
1929 | simple_chord_elements post_events {
1930 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1933 /* why is this giving wrong start location? -ns
1935 i.set_location (@1, @2);
1936 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1938 | CHORD_REPETITION optional_notemode_duration post_events {
1940 i.set_location (@1, @3);
1941 $$ = MAKE_SYNTAX ("repetition-chord", i,
1942 $2, scm_reverse_x ($3, SCM_EOL));
1944 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1946 i.set_location (@1, @3);
1947 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1948 scm_reverse_x ($3, SCM_EOL));
1951 | note_chord_element
1956 chord_body optional_notemode_duration post_events
1958 Music *m = unsmob_music ($1);
1959 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1960 SCM es = m->get_property ("elements");
1961 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1963 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1964 unsmob_music (scm_car (s))->set_property ("duration", dur);
1965 es = ly_append2 (es, postevs);
1967 m-> set_property ("elements", es);
1969 $$ = m->self_scm ();
1974 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1976 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1980 chord_body_elements:
1981 /* empty */ { $$ = SCM_EOL; }
1982 | chord_body_elements chord_body_element {
1983 if (!SCM_UNBNDP ($2))
1984 $$ = scm_cons ($2, $1);
1989 pitch exclamations questions octave_check post_events
1991 bool q = to_boolean ($3);
1992 bool ex = to_boolean ($2);
1996 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1997 n->set_property ("pitch", $1);
1999 n->set_property ("cautionary", SCM_BOOL_T);
2001 n->set_property ("force-accidental", SCM_BOOL_T);
2003 if (scm_is_pair (post)) {
2004 SCM arts = scm_reverse_x (post, SCM_EOL);
2005 n->set_property ("articulations", arts);
2007 if (scm_is_number (check))
2009 int q = scm_to_int (check);
2010 n->set_property ("absolute-octave", scm_from_int (q-1));
2013 $$ = n->unprotect ();
2015 | DRUM_PITCH post_events {
2016 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2017 n->set_property ("drum-type", $1);
2019 if (scm_is_pair ($2)) {
2020 SCM arts = scm_reverse_x ($2, SCM_EOL);
2021 n->set_property ("articulations", arts);
2023 $$ = n->unprotect ();
2025 | music_function_chord_body
2027 Music *m = unsmob_music ($1);
2029 while (m && m->is_mus_type ("music-wrapper-music")) {
2030 $$ = m->get_property ("element");
2031 m = unsmob_music ($$);
2034 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2035 parser->parser_error (@$, _ ("not a rhythmic event"));
2041 music_function_chord_body:
2046 // Event functions may only take closed arglists, otherwise it would
2047 // not be clear whether a following postevent should be associated
2048 // with the last argument of the event function or with the expression
2049 // for which the function call acts itself as event.
2051 music_function_call_closed:
2052 MUSIC_FUNCTION function_arglist_closed {
2053 $$ = MAKE_SYNTAX ("music-function", @$,
2058 event_function_event:
2059 EVENT_FUNCTION function_arglist_closed {
2060 $$ = MAKE_SYNTAX ("music-function", @$,
2070 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2071 m->set_property ("span-direction", scm_from_int (START));
2072 $$ = m->unprotect();
2075 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2076 m->set_property ("span-direction", scm_from_int (STOP));
2077 $$ = m->unprotect ();
2080 $$ = MAKE_SYNTAX ("voice-separator", @$);
2083 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2085 Music *m = unsmob_music (pipe);
2090 $$ = m->unprotect ();
2093 $$ = MAKE_SYNTAX ("bar-check", @$);
2100 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2112 | post_events post_event {
2113 unsmob_music ($2)->set_spot (@2);
2114 $$ = scm_cons ($2, $$);
2118 post_event_nofinger:
2119 direction_less_event {
2122 | script_dir music_function_call_closed {
2124 if (!SCM_UNBNDP ($1))
2126 unsmob_music ($$)->set_property ("direction", $1);
2130 if (!parser->lexer_->is_lyric_state ())
2131 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2132 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2135 if (!parser->lexer_->is_lyric_state ())
2136 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2137 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2139 | script_dir direction_reqd_event {
2140 if (!SCM_UNBNDP ($1))
2142 Music *m = unsmob_music ($2);
2143 m->set_property ("direction", $1);
2147 | script_dir direction_less_event {
2148 if (!SCM_UNBNDP ($1))
2150 Music *m = unsmob_music ($2);
2151 m->set_property ("direction", $1);
2158 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2163 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2174 string_number_event:
2176 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2177 s->set_property ("string-number", $1);
2178 $$ = s->unprotect ();
2182 direction_less_char:
2184 $$ = ly_symbol2scm ("bracketOpenSymbol");
2187 $$ = ly_symbol2scm ("bracketCloseSymbol");
2190 $$ = ly_symbol2scm ("tildeSymbol");
2193 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2196 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2199 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2202 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2205 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2208 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2211 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2215 direction_less_event:
2216 direction_less_char {
2217 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2219 if (unsmob_music (predefd))
2221 m = unsmob_music (predefd)->clone ();
2226 m = MY_MAKE_MUSIC ("Music", @$);
2228 $$ = m->unprotect ();
2230 | string_number_event
2231 | EVENT_IDENTIFIER {
2235 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2236 a->set_property ("tremolo-type", $1);
2237 $$ = a->unprotect ();
2239 | event_function_event
2242 direction_reqd_event:
2246 | script_abbreviation {
2247 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2248 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2249 if (scm_is_string (s))
2250 a->set_property ("articulation-type", s);
2251 else parser->parser_error (@1, _ ("expecting string as script definition"));
2252 $$ = a->unprotect ();
2257 /**/ { $$ = SCM_EOL; }
2258 | '=' quotes { $$ = $2; }
2272 $$ = scm_from_int (1);
2275 $$ = scm_oneplus ($1);
2281 $$ = scm_from_int (-1);
2284 $$ = scm_oneminus ($1);
2289 NOTENAME_PITCH quotes {
2290 if (!scm_is_eq (SCM_INUM0, $2))
2292 Pitch p = *unsmob_pitch ($1);
2293 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2294 $$ = p.smobbed_copy ();
2304 TONICNAME_PITCH quotes {
2305 if (!scm_is_eq (SCM_INUM0, $2))
2307 Pitch p = *unsmob_pitch ($1);
2308 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2309 $$ = p.smobbed_copy ();
2319 pitch_also_in_chords:
2326 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2327 t->set_property ("text", $1);
2328 $$ = t->unprotect ();
2331 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2332 t->set_property ("text",
2333 make_simple_markup ($1));
2334 $$ = t->unprotect ();
2337 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2338 t->set_property ("text",
2339 make_simple_markup ($1));
2340 $$ = t->unprotect ();
2346 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2347 t->set_property ("digit", $1);
2348 $$ = t->unprotect ();
2352 script_abbreviation:
2354 $$ = scm_from_locale_string ("Hat");
2357 $$ = scm_from_locale_string ("Plus");
2360 $$ = scm_from_locale_string ("Dash");
2363 $$ = scm_from_locale_string ("Bar");
2366 $$ = scm_from_locale_string ("Larger");
2369 $$ = scm_from_locale_string ("Dot");
2372 $$ = scm_from_locale_string ("Underscore");
2377 '_' { $$ = scm_from_int (DOWN); }
2378 | '^' { $$ = scm_from_int (UP); }
2379 | '-' { $$ = SCM_UNDEFINED; }
2383 multiplied_duration {
2388 maybe_notemode_duration:
2392 | multiplied_duration {
2394 parser->default_duration_ = *unsmob_duration ($$);
2399 optional_notemode_duration:
2400 maybe_notemode_duration
2402 if (SCM_UNBNDP ($$))
2403 $$ = parser->default_duration_.smobbed_copy ();
2410 int n = scm_to_int ($1);
2411 if (!is_duration (n))
2412 parser->parser_error (@1, _f ("not a duration: %d", n));
2416 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2418 | DURATION_IDENTIFIER dots {
2419 Duration *d = unsmob_duration ($1);
2420 Duration k (d->duration_log (),
2421 d->dot_count () + scm_to_int ($2));
2422 k = k.compressed (d->factor ());
2423 scm_remember_upto_here_1 ($1);
2424 $$ = k.smobbed_copy ();
2428 multiplied_duration:
2432 | multiplied_duration '*' UNSIGNED {
2433 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2435 | multiplied_duration '*' FRACTION {
2436 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2438 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2447 $$ = scm_oneplus ($1);
2456 int n = scm_to_int ($2);
2457 if (!is_duration (n))
2458 parser->parser_error (@2, _f ("not a duration: %d", n));
2464 UNSIGNED { $$ = $1; }
2465 | STRING { $$ = $1; }
2466 | full_markup { $$ = $1; }
2469 figured_bass_alteration:
2470 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2471 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2472 | '!' { $$ = scm_from_int (0); }
2477 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2478 $$ = bfr->unprotect ();
2481 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2482 $$ = bfr->self_scm ();
2484 if (scm_is_number ($1))
2485 bfr->set_property ("figure", $1);
2486 else if (Text_interface::is_markup ($1))
2487 bfr->set_property ("text", $1);
2493 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2495 | bass_figure figured_bass_alteration {
2496 Music *m = unsmob_music ($1);
2497 if (scm_to_double ($2)) {
2498 SCM salter = m->get_property ("alteration");
2499 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2500 m->set_property ("alteration",
2501 scm_sum (alter, $2));
2503 m->set_property ("alteration", scm_from_int (0));
2506 | bass_figure figured_bass_modification {
2507 Music *m = unsmob_music ($1);
2508 if ($2 == ly_symbol2scm ("plus"))
2510 m->set_property ("augmented", SCM_BOOL_T);
2512 else if ($2 == ly_symbol2scm ("slash"))
2514 m->set_property ("diminished", SCM_BOOL_T);
2516 else if ($2 == ly_symbol2scm ("exclamation"))
2518 m->set_property ("no-continuation", SCM_BOOL_T);
2520 else if ($2 == ly_symbol2scm ("backslash"))
2522 m->set_property ("augmented-slash", SCM_BOOL_T);
2528 figured_bass_modification:
2530 $$ = ly_symbol2scm ("plus");
2533 $$ = ly_symbol2scm ("exclamation");
2536 $$ = ly_symbol2scm ("slash");
2539 $$ = ly_symbol2scm ("backslash");
2549 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2557 | figure_list br_bass_figure {
2558 $$ = scm_cons ($2, $1);
2563 FIGURE_OPEN figure_list FIGURE_CLOSE {
2564 $$ = scm_reverse_x ($2, SCM_EOL);
2570 /**/ { $$ = SCM_BOOL_F; }
2571 | REST { $$ = SCM_BOOL_T; }
2575 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2576 if (!parser->lexer_->is_note_state ())
2577 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2578 if (!SCM_UNBNDP ($2)
2580 || scm_is_number ($4)
2582 || scm_is_true ($6))
2585 if (scm_is_true ($6))
2586 n = MY_MAKE_MUSIC ("RestEvent", @$);
2588 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2590 n->set_property ("pitch", $1);
2591 if (SCM_UNBNDP ($5))
2592 n->set_property ("duration",
2593 parser->default_duration_.smobbed_copy ());
2595 n->set_property ("duration", $5);
2597 if (scm_is_number ($4))
2599 int q = scm_to_int ($4);
2600 n->set_property ("absolute-octave", scm_from_int (q-1));
2603 if (to_boolean ($3))
2604 n->set_property ("cautionary", SCM_BOOL_T);
2605 if (to_boolean ($2) || to_boolean ($3))
2606 n->set_property ("force-accidental", SCM_BOOL_T);
2608 $$ = n->unprotect ();
2611 | DRUM_PITCH optional_notemode_duration {
2612 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2613 n->set_property ("duration", $2);
2614 n->set_property ("drum-type", $1);
2616 $$ = n->unprotect ();
2618 | RESTNAME optional_notemode_duration {
2620 if (ly_scm2string ($1) == "s") {
2622 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2625 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2628 ev->set_property ("duration", $2);
2629 $$ = ev->unprotect ();
2633 simple_chord_elements:
2635 if (!parser->lexer_->is_chord_state ())
2636 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2639 | figure_spec optional_notemode_duration {
2640 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2642 unsmob_music (scm_car (s))->set_property ("duration", $2);
2659 | lyric_element multiplied_duration post_events {
2660 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2661 if (scm_is_pair ($3))
2662 unsmob_music ($$)->set_property
2663 ("articulations", scm_reverse_x ($3, SCM_EOL));
2665 | lyric_element post_event post_events {
2666 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2667 parser->default_duration_.smobbed_copy ());
2668 unsmob_music ($$)->set_property
2669 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2671 | LYRIC_ELEMENT optional_notemode_duration post_events {
2672 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2673 if (scm_is_pair ($3))
2674 unsmob_music ($$)->set_property
2675 ("articulations", scm_reverse_x ($3, SCM_EOL));
2680 lyric_element_music:
2681 lyric_element optional_notemode_duration post_events {
2682 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2683 if (scm_is_pair ($3))
2684 unsmob_music ($$)->set_property
2685 ("articulations", scm_reverse_x ($3, SCM_EOL));
2690 steno_tonic_pitch optional_notemode_duration {
2691 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2693 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2694 SCM its = scm_reverse_x ($4, SCM_EOL);
2695 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2703 | chord_items chord_item {
2704 $$ = scm_cons ($2, $$);
2710 $$ = ly_symbol2scm ("chord-colon");
2713 $$ = ly_symbol2scm ("chord-caret");
2715 | CHORD_SLASH steno_tonic_pitch {
2716 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2718 | CHORD_BASS steno_tonic_pitch {
2719 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2728 $$ = scm_reverse_x ($1, SCM_EOL);
2736 step_number { $$ = scm_cons ($1, SCM_EOL); }
2737 | step_numbers '.' step_number {
2738 $$ = scm_cons ($3, $$);
2744 $$ = make_chord_step ($1, 0);
2747 $$ = make_chord_step ($1, SHARP_ALTERATION);
2749 | UNSIGNED CHORD_MINUS {
2750 $$ = make_chord_step ($1, FLAT_ALTERATION);
2758 | UNSIGNED '~' UNSIGNED {
2759 $$ = scm_cons ($1, $3);
2766 TODO: should deprecate in favor of Scheme?
2770 number_expression '+' number_term {
2771 $$ = scm_sum ($1, $3);
2773 | number_expression '-' number_term {
2774 $$ = scm_difference ($1, $3);
2783 | number_factor '*' number_factor {
2784 $$ = scm_product ($1, $3);
2786 | number_factor '/' number_factor {
2787 $$ = scm_divide ($1, $3);
2792 '-' number_factor { /* %prec UNARY_MINUS */
2793 $$ = scm_difference ($2, SCM_UNDEFINED);
2801 | UNSIGNED NUMBER_IDENTIFIER {
2802 $$ = scm_product ($1, $2);
2804 | REAL NUMBER_IDENTIFIER {
2805 $$ = scm_product ($1, $2);
2821 { $$ = SCM_UNDEFINED; }
2824 if (SCM_UNBNDP ($1))
2832 { $$ = SCM_UNDEFINED; }
2835 if (SCM_UNBNDP ($1))
2843 This should be done more dynamically if possible.
2847 LYRIC_MARKUP_IDENTIFIER {
2851 { parser->lexer_->push_markup_state (); }
2854 parser->lexer_->pop_state ();
2859 MARKUPLIST_IDENTIFIER {
2863 { parser->lexer_->push_markup_state (); }
2866 parser->lexer_->pop_state ();
2875 { parser->lexer_->push_markup_state (); }
2878 parser->lexer_->pop_state ();
2884 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2886 | markup_head_1_list simple_markup {
2887 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2897 if (Text_interface::is_markup ($1))
2898 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
2899 else if (Text_interface::is_markup_list ($1))
2900 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
2902 parser->parser_error (@1, _ ("not a markup"));
2903 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
2910 MARKUPLIST_IDENTIFIER {
2913 | markup_composed_list {
2916 | markup_braced_list {
2919 | markup_command_list {
2920 $$ = scm_list_1 ($1);
2922 | markup_scm MARKUPLIST_IDENTIFIER
2928 markup_composed_list:
2929 markup_head_1_list markup_braced_list {
2930 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2936 '{' markup_braced_list_body '}' {
2937 $$ = scm_reverse_x ($2, SCM_EOL);
2941 markup_braced_list_body:
2942 /* empty */ { $$ = SCM_EOL; }
2943 | markup_braced_list_body markup {
2944 $$ = scm_cons ($2, $1);
2946 | markup_braced_list_body markup_list {
2947 $$ = scm_reverse_x ($2, $1);
2951 markup_command_list:
2952 MARKUP_LIST_FUNCTION markup_command_list_arguments {
2953 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
2957 markup_command_basic_arguments:
2958 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
2959 $$ = scm_cons ($3, $2);
2961 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
2962 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
2964 | EXPECT_NO_MORE_ARGS {
2969 markup_command_list_arguments:
2970 markup_command_basic_arguments { $$ = $1; }
2971 | EXPECT_MARKUP markup_command_list_arguments markup {
2972 $$ = scm_cons ($3, $2);
2977 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
2978 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
2983 markup_head_1_item {
2984 $$ = scm_list_1 ($1);
2986 | markup_head_1_list markup_head_1_item {
2987 $$ = scm_cons ($2, $1);
2993 $$ = make_simple_markup ($1);
2995 | MARKUP_IDENTIFIER {
2998 | LYRIC_MARKUP_IDENTIFIER {
3002 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3003 parser->lexer_->push_note_state (nn);
3004 } '{' score_body '}' {
3005 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3006 parser->lexer_->pop_state ();
3008 | MARKUP_FUNCTION markup_command_basic_arguments {
3009 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3011 | markup_scm MARKUP_IDENTIFIER
3018 markup_head_1_list simple_markup {
3019 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3020 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3030 Lily_parser::set_yydebug (bool x)
3036 Lily_parser::do_yyparse ()
3038 SCM retval = SCM_UNDEFINED;
3039 yyparse (this, &retval);
3049 It is a little strange to have this function in this file, but
3050 otherwise, we have to import music classes into the lexer.
3054 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3056 if (unsmob_book (sid)) {
3057 Book *book = unsmob_book (sid)->clone ();
3058 *destination = book->self_scm ();
3061 return BOOK_IDENTIFIER;
3062 } else if (scm_is_number (sid)) {
3064 return NUMBER_IDENTIFIER;
3065 } else if (unsmob_context_def (sid)) {
3066 Context_def *def= unsmob_context_def (sid)->clone ();
3068 *destination = def->self_scm ();
3071 return CONTEXT_DEF_IDENTIFIER;
3072 } else if (unsmob_context_mod (sid)) {
3073 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3075 return CONTEXT_MOD_IDENTIFIER;
3076 } else if (unsmob_score (sid)) {
3077 Score *score = new Score (*unsmob_score (sid));
3078 *destination = score->self_scm ();
3080 score->unprotect ();
3081 return SCORE_IDENTIFIER;
3082 } else if (Music *mus = unsmob_music (sid)) {
3083 mus = mus->clone ();
3084 *destination = mus->self_scm ();
3085 unsmob_music (*destination)->
3086 set_property ("origin", make_input (last_input_));
3088 bool is_event = mus->is_mus_type ("post-event");
3090 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3091 } else if (unsmob_pitch (sid)) {
3092 *destination = unsmob_pitch (sid)->smobbed_copy ();
3093 return PITCH_IDENTIFIER;
3094 } else if (unsmob_duration (sid)) {
3095 *destination = unsmob_duration (sid)->smobbed_copy ();
3096 return DURATION_IDENTIFIER;
3097 } else if (unsmob_output_def (sid)) {
3098 Output_def *p = unsmob_output_def (sid);
3101 *destination = p->self_scm ();
3103 return OUTPUT_DEF_IDENTIFIER;
3104 } else if (Text_interface::is_markup (sid)) {
3106 if (is_lyric_state ())
3107 return LYRIC_MARKUP_IDENTIFIER;
3108 return MARKUP_IDENTIFIER;
3109 } else if (Text_interface::is_markup_list (sid)) {
3111 return MARKUPLIST_IDENTIFIER;
3118 get_next_unique_context_id ()
3120 return scm_from_locale_string ("$uniqueContextId");
3125 get_next_unique_lyrics_context_id ()
3127 static int new_context_count;
3129 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3130 return scm_from_locale_string (s);
3133 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3134 SCM arg, SCM args, SCM pred)
3136 args = scm_cons (arg, args);
3137 if (scm_is_true (scm_call_1 (pred, arg)))
3139 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3140 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3141 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3145 SCM loc_on_music (Input loc, SCM arg)
3147 if (Music *m = unsmob_music (arg))
3151 return m->unprotect ();
3157 is_regular_identifier (SCM id)
3159 string str = ly_scm2string (id);
3160 char const *s = str.c_str ();
3169 v = v && isalnum (*s);
3176 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3178 if (unsmob_music (simple))
3180 if (parser->lexer_->is_note_state ()) {
3181 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3182 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3183 if (scm_is_symbol (simple))
3184 n->set_property ("drum-type", simple);
3185 else if (unsmob_pitch (simple))
3186 n->set_property ("pitch", simple);
3191 return n->unprotect ();
3192 } else if (parser->lexer_->is_lyric_state ()) {
3193 if (Text_interface::is_markup (simple))
3194 return MAKE_SYNTAX ("lyric-event", loc, simple,
3195 parser->default_duration_.smobbed_copy ());
3196 } else if (parser->lexer_->is_chord_state ()) {
3197 if (unsmob_pitch (simple))
3198 return make_chord_elements (loc, simple,
3199 parser->default_duration_.smobbed_copy (),
3206 make_music_with_input (SCM name, Input where)
3208 Music *m = make_music_by_name (name);
3209 m->set_spot (where);
3214 make_simple_markup (SCM a)
3222 return t && t == 1 << intlog2 (t);
3226 make_chord_step (SCM step_scm, Rational alter)
3228 int step = scm_to_int (step_scm);
3231 alter += FLAT_ALTERATION;
3235 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3236 return m.smobbed_copy ();
3241 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3243 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3244 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3245 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3247 unsmob_music (scm_car (s))->set_spot (loc);
3253 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3255 Lily_lexer *lex = parser->lexer_;
3259 lex->prepare_for_next_token ();
3260 return lex->yylex ();