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 MARKUP_FUNCTION
367 %token MARKUP_LIST_FUNCTION
368 %token MARKUP_IDENTIFIER
369 %token MARKUPLIST_IDENTIFIER
370 %token MUSIC_FUNCTION
371 %token MUSIC_IDENTIFIER
372 %token NOTENAME_PITCH
373 %token NUMBER_IDENTIFIER
374 %token OUTPUT_DEF_IDENTIFIER
378 %token SCM_IDENTIFIER
380 %token SCORE_IDENTIFIER
382 %token TONICNAME_PITCH
386 /* We don't assign precedence to / and *, because we might need varied
387 prec levels in different prods */
396 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
397 parser->lexer_->push_note_state (nn);
398 } embedded_lilypond {
399 parser->lexer_->pop_state ();
404 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
405 | lilypond toplevel_expression {
407 | lilypond assignment {
410 parser->error_level_ = 1;
413 parser->error_level_ = 1;
420 parser->lexer_->add_scope (get_header (parser));
422 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
425 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
426 scm_call_2 (proc, parser->self_scm (), $1);
429 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
430 scm_call_2 (proc, parser->self_scm (), $1);
433 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
434 scm_call_2 (proc, parser->self_scm (), $1);
437 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
438 scm_call_2 (proc, parser->self_scm (), $1);
441 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
442 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
445 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
446 scm_call_2 (proc, parser->self_scm (), $1);
449 // Evaluate and ignore #xxx, as opposed to \xxx
450 parser->lexer_->eval_scm_token ($1);
452 | embedded_scm_active
454 SCM out = SCM_UNDEFINED;
455 if (Text_interface::is_markup ($1))
456 out = scm_list_1 ($1);
457 else if (Text_interface::is_markup_list ($1))
459 if (scm_is_pair (out))
461 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
462 scm_call_2 (proc, parser->self_scm (), out);
463 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
464 parser->parser_error (@1, _("bad expression type"));
468 Output_def * od = unsmob_output_def ($1);
470 if (od->c_variable ("is-paper") == SCM_BOOL_T)
471 id = ly_symbol2scm ("$defaultpaper");
472 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
473 id = ly_symbol2scm ("$defaultmidi");
474 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
475 id = ly_symbol2scm ("$defaultlayout");
477 parser->lexer_->set_identifier (id, $1);
484 $$ = parser->lexer_->eval_scm_token ($1);
494 embedded_scm_bare_arg:
499 | context_modification
501 | context_def_spec_block
507 /* The generic version may end in music, or not */
515 embedded_scm_bare_arg
521 SCM_FUNCTION function_arglist {
522 $$ = MAKE_SYNTAX ("music-function", @$,
530 $$ = MAKE_SYNTAX ("void-music", @$);
533 | music_embedded music_embedded music_list {
534 $3 = scm_reverse_x ($3, SCM_EOL);
535 if (unsmob_music ($2))
536 $3 = scm_cons ($2, $3);
537 if (unsmob_music ($1))
538 $3 = scm_cons ($1, $3);
539 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
542 parser->error_level_ = 1;
543 $$ = SCM_UNSPECIFIED;
545 | INVALID embedded_lilypond {
546 parser->error_level_ = 1;
552 lilypond_header_body:
553 /* empty */ { $$ = SCM_UNSPECIFIED; }
554 | lilypond_header_body assignment {
557 | lilypond_header_body embedded_scm {
563 HEADER '{' lilypond_header_body '}' {
564 $$ = parser->lexer_->remove_scope ();
573 | LYRICS_STRING { $$ = $1; }
577 assignment_id '=' identifier_init {
578 parser->lexer_->set_identifier ($1, $3);
579 $$ = SCM_UNSPECIFIED;
581 | assignment_id property_path '=' identifier_init {
582 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
583 parser->lexer_->set_identifier (path, $4);
584 $$ = SCM_UNSPECIFIED;
594 | context_def_spec_block
596 | post_event_nofinger
602 | context_modification
605 context_def_spec_block:
606 CONTEXT '{' context_def_spec_body '}'
617 context_mod_embedded:
620 if (unsmob_music ($1)) {
621 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
622 $1 = scm_call_2 (proc, parser->self_scm (), $1);
624 if (unsmob_context_mod ($1))
627 parser->parser_error (@1, _ ("not a context mod"));
633 context_def_spec_body:
635 $$ = Context_def::make_scm ();
636 unsmob_context_def ($$)->origin ()->set_spot (@$);
638 | CONTEXT_DEF_IDENTIFIER {
640 unsmob_context_def ($$)->origin ()->set_spot (@$);
642 | context_def_spec_body context_mod {
643 unsmob_context_def ($$)->add_context_mod ($2);
645 | context_def_spec_body context_modification {
646 Context_def *td = unsmob_context_def ($$);
647 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
648 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
649 td->add_context_mod (scm_car (m));
652 | context_def_spec_body context_mod_embedded {
653 Context_def *td = unsmob_context_def ($$);
654 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
655 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
656 td->add_context_mod (scm_car (m));
664 BOOK '{' book_body '}' {
667 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
672 * Use 'handlers' like for toplevel-* stuff?
673 * grok \layout and \midi? */
676 Book *book = new Book;
677 init_papers (parser);
678 book->origin ()->set_spot (@$);
679 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
680 book->paper_->unprotect ();
681 push_paper (parser, book->paper_);
682 book->header_ = get_header (parser);
683 $$ = book->unprotect ();
684 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
687 unsmob_book ($1)->origin ()->set_spot (@$);
688 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
690 | book_body paper_block {
691 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
692 set_paper (parser, unsmob_output_def ($2));
694 | book_body bookpart_block {
695 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
696 scm_call_2 (proc, $1, $2);
698 | book_body score_block {
699 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
700 scm_call_2 (proc, $1, $2);
702 | book_body composite_music {
703 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
704 scm_call_3 (proc, parser->self_scm (), $1, $2);
706 | book_body full_markup {
707 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
708 scm_call_2 (proc, $1, scm_list_1 ($2));
710 | book_body full_markup_list {
711 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
712 scm_call_2 (proc, $1, $2);
714 | book_body SCM_TOKEN {
715 // Evaluate and ignore #xxx, as opposed to \xxx
716 parser->lexer_->eval_scm_token ($2);
718 | book_body embedded_scm_active
720 SCM out = SCM_UNDEFINED;
721 if (Text_interface::is_markup ($2))
722 out = scm_list_1 ($2);
723 else if (Text_interface::is_markup_list ($2))
725 if (scm_is_pair (out))
727 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
728 scm_call_2 (proc, $1, out);
729 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
730 parser->parser_error (@2, _("bad expression type"));
734 parser->lexer_->add_scope (unsmob_book ($1)->header_);
737 Book *book = unsmob_book ($1);
739 book->scores_ = SCM_EOL;
740 book->bookparts_ = SCM_EOL;
745 BOOKPART '{' bookpart_body '}' {
747 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
753 Book *book = new Book;
754 book->origin ()->set_spot (@$);
755 $$ = book->unprotect ();
756 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
759 unsmob_book ($1)->origin ()->set_spot (@$);
760 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
762 | bookpart_body paper_block {
763 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
765 | bookpart_body score_block {
766 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
767 scm_call_2 (proc, $1, $2);
769 | bookpart_body composite_music {
770 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
771 scm_call_3 (proc, parser->self_scm (), $1, $2);
773 | bookpart_body full_markup {
774 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
775 scm_call_2 (proc, $1, scm_list_1 ($2));
777 | bookpart_body full_markup_list {
778 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
779 scm_call_2 (proc, $1, $2);
781 | bookpart_body SCM_TOKEN {
782 // Evaluate and ignore #xxx, as opposed to \xxx
783 parser->lexer_->eval_scm_token ($2);
785 | bookpart_body embedded_scm_active
787 SCM out = SCM_UNDEFINED;
788 if (Text_interface::is_markup ($2))
789 out = scm_list_1 ($2);
790 else if (Text_interface::is_markup_list ($2))
792 if (scm_is_pair (out))
794 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
795 scm_call_2 (proc, $1, out);
796 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
797 parser->parser_error (@2, _("bad expression type"));
801 Book *book = unsmob_book ($1);
802 if (!ly_is_module (book->header_))
803 book->header_ = ly_make_module (false);
804 parser->lexer_->add_scope (book->header_);
806 | bookpart_body error {
807 Book *book = unsmob_book ($1);
809 book->scores_ = SCM_EOL;
814 SCORE '{' score_body '}' {
821 SCM scorify = ly_lily_module_constant ("scorify-music");
822 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
824 unsmob_score ($$)->origin ()->set_spot (@$);
827 unsmob_score ($$)->origin ()->set_spot (@$);
831 Score *score = unsmob_score ($1);
832 if (!ly_is_module (score->get_header ()))
833 score->set_header (ly_make_module (false));
834 parser->lexer_->add_scope (score->get_header ());
836 | score_body output_def {
837 Output_def *od = unsmob_output_def ($2);
838 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
840 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
845 unsmob_score ($1)->add_output_def (od);
849 unsmob_score ($$)->error_found_ = true;
860 Output_def *od = unsmob_output_def ($1);
862 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
864 parser->parser_error (@1, _ ("need \\paper for paper block"));
865 $$ = get_paper (parser)->unprotect ();
872 output_def_body '}' {
875 parser->lexer_->remove_scope ();
876 parser->lexer_->pop_state ();
882 Output_def *p = get_paper (parser);
883 p->input_origin_ = @$;
884 parser->lexer_->add_scope (p->scope_);
885 $$ = p->unprotect ();
888 Output_def *p = get_midi (parser);
889 $$ = p->unprotect ();
890 parser->lexer_->add_scope (p->scope_);
893 Output_def *p = get_layout (parser);
895 parser->lexer_->add_scope (p->scope_);
896 $$ = p->unprotect ();
900 output_def_head_with_mode_switch:
902 parser->lexer_->push_initial_state ();
907 // We need this weird nonterminal because both music as well as a
908 // context definition can start with \context and the difference is
909 // only apparent after looking at the next token. If it is '{', there
910 // is still time to escape from notes mode.
912 music_or_context_def:
915 parser->lexer_->pop_state ();
919 parser->lexer_->pop_state ();
920 } '{' context_def_spec_body '}'
927 output_def_head_with_mode_switch '{' {
929 unsmob_output_def ($$)->input_origin_.set_spot (@$);
931 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
932 Output_def *o = unsmob_output_def ($3);
933 o->input_origin_.set_spot (@$);
935 parser->lexer_->remove_scope ();
936 parser->lexer_->add_scope (o->scope_);
938 | output_def_body assignment {
941 | output_def_body embedded_scm {
946 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
947 parser->lexer_->push_note_state (nn);
948 } music_or_context_def
950 if (unsmob_context_def ($3))
951 assign_context_def (unsmob_output_def ($1), $3);
954 SCM proc = parser->lexer_->lookup_identifier
955 ("output-def-music-handler");
956 scm_call_3 (proc, parser->self_scm (),
960 | output_def_body error {
966 TEMPO steno_duration '=' tempo_range {
967 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
969 | TEMPO scalar_closed steno_duration '=' tempo_range {
970 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
973 $$ = MAKE_SYNTAX ("tempo", @$, $2);
978 The representation of a list is reversed to have efficient append. */
984 | music_list music_embedded {
985 if (unsmob_music ($2))
986 $$ = scm_cons ($2, $1);
989 Music *m = MY_MAKE_MUSIC("Music", @$);
991 m->set_property ("error-found", SCM_BOOL_T);
992 $$ = scm_cons (m->self_scm (), $1);
993 m->unprotect (); /* UGH */
1000 $$ = scm_reverse_x ($2, SCM_EOL);
1005 | lyric_element_music
1012 if (unsmob_music ($1)
1013 || scm_is_eq ($1, SCM_UNSPECIFIED))
1017 @$.warning (_ ("Ignoring non-music expression"));
1018 $$ = SCM_UNSPECIFIED;
1026 $$ = make_music_from_simple (parser, @1, $1);
1027 if (!unsmob_music ($$))
1028 parser->parser_error (@1, _ ("music expected"));
1030 | composite_music %prec COMPOSITE
1035 | composite_music %prec COMPOSITE
1039 REPEAT simple_string unsigned_number music
1041 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1043 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1045 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1050 SEQUENTIAL braced_music_list {
1051 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1053 | braced_music_list {
1054 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1059 SIMULTANEOUS braced_music_list {
1060 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1062 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1063 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1069 | music_property_def
1073 context_modification:
1074 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1076 parser->lexer_->pop_state ();
1079 | WITH CONTEXT_MOD_IDENTIFIER
1083 | CONTEXT_MOD_IDENTIFIER
1087 | WITH embedded_scm_closed
1089 if (unsmob_context_mod ($2))
1092 parser->parser_error (@2, _ ("not a context mod"));
1093 $$ = Context_mod ().smobbed_copy ();
1098 optional_context_mod:
1102 | context_modification
1110 $$ = Context_mod ().smobbed_copy ();
1112 | context_mod_list context_mod {
1113 unsmob_context_mod ($1)->add_context_mod ($2);
1115 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1116 Context_mod *md = unsmob_context_mod ($2);
1118 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1120 | context_mod_list context_mod_embedded {
1121 unsmob_context_mod ($1)->add_context_mods
1122 (unsmob_context_mod ($2)->get_mods ());
1131 /* Music that can be parsed without lookahead */
1134 | complex_music_prefix closed_music
1136 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1138 | music_function_call_closed
1144 | grouped_music_list
1148 simultaneous_music { $$ = $1; }
1149 | sequential_music { $$ = $1; }
1152 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1153 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1154 and this rule returns the reversed list of arguments. */
1156 function_arglist_skip:
1157 function_arglist_common
1158 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1160 $$ = scm_cons ($1, $3);
1161 } %prec FUNCTION_ARGLIST
1162 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1164 $$ = scm_cons ($1, $3);
1165 } %prec FUNCTION_ARGLIST
1166 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1168 $$ = scm_cons ($1, $3);
1169 } %prec FUNCTION_ARGLIST
1173 function_arglist_nonbackup_common:
1174 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1175 $$ = scm_cons ($4, $3);
1177 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1178 $$ = scm_cons ($4, $3);
1180 | EXPECT_OPTIONAL EXPECT_SCM function_arglist FRACTION
1182 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1184 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1186 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1188 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1190 SCM n = scm_difference ($5, SCM_UNDEFINED);
1191 if (scm_is_true (scm_call_1 ($2, n)))
1192 $$ = scm_cons (n, $3);
1194 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1195 t->set_property ("digit", $5);
1196 $$ = t->unprotect ();
1197 if (scm_is_true (scm_call_1 ($2, $$)))
1198 $$ = scm_cons ($$, $3);
1200 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1204 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1206 $$ = check_scheme_arg (parser, @4,
1207 scm_difference ($5, SCM_UNDEFINED),
1210 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1212 $$ = check_scheme_arg (parser, @4,
1213 scm_difference ($5, SCM_UNDEFINED),
1218 function_arglist_closed_nonbackup:
1219 function_arglist_nonbackup_common
1220 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1222 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1224 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1226 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1230 function_arglist_nonbackup:
1231 function_arglist_nonbackup_common
1232 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1234 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1236 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1238 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1242 function_arglist_keep:
1243 function_arglist_common
1244 | function_arglist_backup
1247 function_arglist_closed_keep:
1248 function_arglist_closed_common
1249 | function_arglist_backup
1252 function_arglist_backup:
1253 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1255 if (scm_is_true (scm_call_1 ($2, $4)))
1257 $$ = scm_cons ($4, $3);
1259 $$ = scm_cons (loc_on_music (@3, $1), $3);
1260 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1263 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1265 if (scm_is_true (scm_call_1 ($2, $4)))
1267 $$ = scm_cons ($4, $3);
1269 $$ = scm_cons (loc_on_music (@3, $1), $3);
1270 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1273 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1275 // There is no point interpreting a lyrics string as
1276 // an event, since we don't allow music possibly
1277 // followed by durations or postevent into closed
1278 // music, and we only accept closed music in optional
1279 // arguments at the moment. If this changes, more
1280 // complex schemes might become interesting here as
1281 // well: see how we do this at the mandatory argument
1283 if (scm_is_true (scm_call_1 ($2, $4)))
1284 $$ = scm_cons ($4, $3);
1286 $$ = scm_cons (loc_on_music (@3, $1), $3);
1287 MYBACKUP (LYRICS_STRING, $4, @4);
1290 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1292 if (scm_is_true (scm_call_1 ($2, $4)))
1295 MYREPARSE (@4, $2, UNSIGNED, $4);
1297 $$ = scm_cons (loc_on_music (@3, $1), $3);
1298 MYBACKUP (UNSIGNED, $4, @4);
1301 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1303 if (scm_is_true (scm_call_1 ($2, $4)))
1306 MYREPARSE (@4, $2, REAL, $4);
1308 $$ = scm_cons (loc_on_music (@3, $1), $3);
1309 MYBACKUP (REAL, $4, @4);
1312 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1314 if (scm_is_true (scm_call_1 ($2, $4)))
1316 $$ = scm_cons ($4, $3);
1318 $$ = scm_cons (loc_on_music (@3, $1), $3);
1319 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1322 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1324 if (scm_is_true (scm_call_1 ($2, $4)))
1326 $$ = scm_cons ($4, $3);
1328 $$ = scm_cons (loc_on_music (@3, $1), $3);
1329 MYBACKUP (FRACTION, $4, @4);
1332 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1334 SCM n = scm_difference ($5, SCM_UNDEFINED);
1335 if (scm_is_true (scm_call_1 ($2, n))) {
1337 MYREPARSE (@5, $2, REAL, n);
1339 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1340 t->set_property ("digit", $5);
1341 $$ = t->unprotect ();
1342 if (scm_is_true (scm_call_1 ($2, $$)))
1343 $$ = scm_cons ($$, $3);
1345 $$ = scm_cons (loc_on_music (@3, $1), $3);
1346 MYBACKUP (UNSIGNED, $5, @5);
1347 parser->lexer_->push_extra_token ('-');
1352 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1354 SCM n = scm_difference ($5, SCM_UNDEFINED);
1355 if (scm_is_true (scm_call_1 ($2, n))) {
1356 MYREPARSE (@5, $2, REAL, n);
1359 MYBACKUP (REAL, n, @5);
1362 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1364 SCM n = scm_difference ($5, SCM_UNDEFINED);
1365 if (scm_is_true (scm_call_1 ($2, n))) {
1366 $$ = scm_cons (n, $3);
1368 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1371 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1373 $$ = scm_cons ($4, $3);
1375 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1377 $$ = scm_cons ($4, $3);
1379 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1381 $$ = scm_cons ($1, $3);
1382 MYBACKUP(0, SCM_UNDEFINED, @3);
1384 | function_arglist_backup REPARSE embedded_scm_arg_closed
1386 $$ = check_scheme_arg (parser, @3,
1389 | function_arglist_backup REPARSE bare_number
1391 $$ = check_scheme_arg (parser, @3,
1397 function_arglist_common
1398 | function_arglist_nonbackup
1401 function_arglist_common:
1402 function_arglist_bare
1403 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1405 $$ = check_scheme_arg (parser, @3,
1408 | EXPECT_SCM function_arglist_closed_optional bare_number
1410 $$ = check_scheme_arg (parser, @3,
1413 | EXPECT_SCM function_arglist_optional FRACTION
1415 $$ = check_scheme_arg (parser, @3,
1418 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1420 $$ = check_scheme_arg (parser, @3,
1423 | function_arglist_common_minus
1424 | function_arglist_common_lyric
1427 function_arglist_common_lyric:
1428 EXPECT_SCM function_arglist_optional lyric_element
1430 // We check how the predicate thinks about a lyrics
1431 // event or about a markup. If it accepts neither, we
1432 // backup the original token. Otherwise we commit to
1433 // taking the token. Depending on what the predicate
1434 // is willing to accept, we interpret as a string, as
1435 // a lyric event, or ambiguously (meaning that if
1436 // something looking like a duration or post event
1437 // follows, we take the event, otherwise the string).
1438 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1439 parser->default_duration_.smobbed_copy ());
1440 if (scm_is_true (scm_call_1 ($1, $3)))
1441 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1444 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1446 $$ = scm_cons ($3, $2);
1448 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1451 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1453 // This is going to flag a syntax error, we
1454 // know the predicate to be false.
1455 check_scheme_arg (parser, @3,
1459 | function_arglist_common_lyric REPARSE lyric_element_arg
1461 // This should never be false
1462 $$ = check_scheme_arg (parser, @3,
1467 function_arglist_common_minus:
1468 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1470 SCM n = scm_difference ($4, SCM_UNDEFINED);
1471 if (scm_is_true (scm_call_1 ($1, n))) {
1473 MYREPARSE (@4, $1, REAL, n);
1475 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1476 t->set_property ("digit", $4);
1477 $$ = t->unprotect ();
1478 if (scm_is_true (scm_call_1 ($1, $$)))
1479 $$ = scm_cons ($$, $2);
1481 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1485 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1488 SCM n = scm_difference ($4, SCM_UNDEFINED);
1489 MYREPARSE (@4, $1, REAL, n);
1491 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1493 SCM n = scm_difference ($4, SCM_UNDEFINED);
1494 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1496 | function_arglist_common_minus REPARSE bare_number
1498 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1502 function_arglist_closed:
1503 function_arglist_closed_common
1504 | function_arglist_closed_nonbackup
1507 function_arglist_closed_common:
1508 function_arglist_bare
1509 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1511 $$ = check_scheme_arg (parser, @3,
1514 | EXPECT_SCM function_arglist_closed_optional bare_number
1516 $$ = check_scheme_arg (parser, @3,
1519 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1521 SCM n = scm_difference ($4, SCM_UNDEFINED);
1522 if (scm_is_true (scm_call_1 ($1, n))) {
1523 $$ = scm_cons (n, $2);
1525 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1526 t->set_property ("digit", $4);
1527 $$ = t->unprotect ();
1528 if (scm_is_true (scm_call_1 ($1, $$)))
1529 $$ = scm_cons ($$, $2);
1531 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1535 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1537 $$ = check_scheme_arg (parser, @3,
1538 scm_difference ($4, SCM_UNDEFINED),
1541 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1543 $$ = check_scheme_arg (parser, @3,
1544 scm_difference ($4, SCM_UNDEFINED),
1547 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1549 $$ = check_scheme_arg (parser, @3,
1552 | EXPECT_SCM function_arglist_optional FRACTION
1554 $$ = check_scheme_arg (parser, @3,
1557 | EXPECT_SCM function_arglist_optional lyric_element
1559 $$ = check_scheme_arg (parser, @3,
1564 function_arglist_optional:
1565 function_arglist_keep %prec FUNCTION_ARGLIST
1566 | function_arglist_backup BACKUP
1567 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1569 $$ = scm_cons ($1, $3);
1571 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1573 $$ = scm_cons ($1, $3);
1577 function_arglist_closed_optional:
1578 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1579 | function_arglist_backup BACKUP
1580 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1582 $$ = scm_cons ($1, $3);
1584 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1586 $$ = scm_cons ($1, $3);
1590 embedded_scm_closed:
1592 | scm_function_call_closed
1595 embedded_scm_arg_closed:
1596 embedded_scm_bare_arg
1597 | scm_function_call_closed
1601 scm_function_call_closed:
1602 SCM_FUNCTION function_arglist_closed {
1603 $$ = MAKE_SYNTAX ("music-function", @$,
1605 } %prec FUNCTION_ARGLIST
1608 function_arglist_bare:
1609 EXPECT_NO_MORE_ARGS {
1612 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1613 $$ = scm_cons ($3, $2);
1615 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1616 $$ = scm_cons ($3, $2);
1618 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1619 $$ = scm_cons ($1, $3);
1621 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1622 $$ = scm_cons ($1, $3);
1624 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1625 $$ = scm_cons ($1, $3);
1629 music_function_call:
1630 MUSIC_FUNCTION function_arglist {
1631 $$ = MAKE_SYNTAX ("music-function", @$,
1638 /**/ { $$ = SCM_EOL; }
1639 | '=' simple_string {
1646 | repeated_music { $$ = $1; }
1647 | re_rhythmed_music { $$ = $1; }
1648 | complex_music_prefix music
1650 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1654 complex_music_prefix:
1655 CONTEXT simple_string optional_id optional_context_mod {
1656 Context_mod *ctxmod = unsmob_context_mod ($4);
1659 mods = ctxmod->get_mods ();
1660 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1662 | NEWCONTEXT simple_string optional_id optional_context_mod {
1663 Context_mod *ctxmod = unsmob_context_mod ($4);
1666 mods = ctxmod->get_mods ();
1667 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1672 mode_changing_head grouped_music_list {
1673 if ($1 == ly_symbol2scm ("chords"))
1675 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1681 parser->lexer_->pop_state ();
1683 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1684 Context_mod *ctxmod = unsmob_context_mod ($2);
1687 mods = ctxmod->get_mods ();
1688 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1689 if ($1 == ly_symbol2scm ("ChordNames"))
1691 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1693 parser->lexer_->pop_state ();
1699 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1700 parser->lexer_->push_note_state (nn);
1702 $$ = ly_symbol2scm ("notes");
1706 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1707 parser->lexer_->push_note_state (nn);
1709 $$ = ly_symbol2scm ("drums");
1712 parser->lexer_->push_figuredbass_state ();
1714 $$ = ly_symbol2scm ("figures");
1717 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1718 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1719 nn = parser->lexer_->lookup_identifier ("pitchnames");
1720 parser->lexer_->push_chord_state (nn);
1721 $$ = ly_symbol2scm ("chords");
1725 { parser->lexer_->push_lyric_state ();
1726 $$ = ly_symbol2scm ("lyrics");
1730 mode_changing_head_with_context:
1732 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1733 parser->lexer_->push_note_state (nn);
1735 $$ = ly_symbol2scm ("DrumStaff");
1738 parser->lexer_->push_figuredbass_state ();
1740 $$ = ly_symbol2scm ("FiguredBass");
1743 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1744 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1745 nn = parser->lexer_->lookup_identifier ("pitchnames");
1746 parser->lexer_->push_chord_state (nn);
1747 $$ = ly_symbol2scm ("ChordNames");
1750 { parser->lexer_->push_lyric_state ();
1751 $$ = ly_symbol2scm ("Lyrics");
1756 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1759 /* Can also use music at the expensive of two S/Rs similar to
1760 \repeat \alternative */
1761 parser->lexer_->pop_state ();
1763 $$ = scm_cons ($3, SCM_EOL);
1765 | new_lyrics ADDLYRICS {
1766 parser->lexer_->push_lyric_state ();
1768 parser->lexer_->pop_state ();
1769 $$ = scm_cons ($4, $1);
1774 composite_music new_lyrics {
1775 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1777 | LYRICSTO simple_string {
1778 parser->lexer_->push_lyric_state ();
1780 parser->lexer_->pop_state ();
1781 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1786 CHANGE STRING '=' STRING {
1787 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1792 property_path_revved:
1793 embedded_scm_closed {
1794 $$ = scm_cons ($1, SCM_EOL);
1796 | property_path_revved embedded_scm_closed {
1797 $$ = scm_cons ($2, $1);
1802 property_path_revved {
1803 $$ = scm_reverse_x ($1, SCM_EOL);
1809 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1810 scm_string_to_symbol ($1), $3);
1812 | UNSET simple_string {
1813 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1814 scm_string_to_symbol ($2));
1816 | OVERRIDE simple_string property_path '=' scalar {
1817 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1818 scm_string_to_symbol ($2), $5),
1821 | REVERT simple_string embedded_scm {
1822 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1823 scm_string_to_symbol ($2), $3);
1828 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1829 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1831 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1832 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1833 | DENIES { $$ = ly_symbol2scm ("denies"); }
1835 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1836 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1837 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1838 | NAME { $$ = ly_symbol2scm ("context-name"); }
1842 property_operation { $$ = $1; }
1843 | context_def_mod STRING {
1844 $$ = scm_list_2 ($1, $2);
1846 | context_def_mod embedded_scm
1848 if (!scm_is_string ($2)
1849 && ly_symbol2scm ("consists") != $1
1850 && ly_symbol2scm ("remove") != $1)
1853 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
1857 $$ = scm_list_2 ($1, $2);
1864 if (!is_regular_identifier ($1))
1866 @$.error (_("Grob name should be alphanumeric"));
1869 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1870 scm_string_to_symbol ($1));
1872 | simple_string '.' simple_string {
1873 $$ = scm_list_2 (scm_string_to_symbol ($1),
1874 scm_string_to_symbol ($3));
1878 simple_music_property_def:
1879 OVERRIDE context_prop_spec property_path '=' scalar {
1880 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1881 ly_symbol2scm ("OverrideProperty"),
1886 | REVERT context_prop_spec embedded_scm {
1887 $$ = scm_list_4 (scm_car ($2),
1888 ly_symbol2scm ("RevertProperty"),
1892 | SET context_prop_spec '=' scalar {
1893 $$ = scm_list_4 (scm_car ($2),
1894 ly_symbol2scm ("PropertySet"),
1898 | UNSET context_prop_spec {
1899 $$ = scm_list_3 (scm_car ($2),
1900 ly_symbol2scm ("PropertyUnset"),
1906 simple_music_property_def {
1907 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
1916 | string '+' string {
1917 if (!scm_is_string ($1)) {
1918 parser->parser_error (@1, (_ ("simple string expected")));
1919 $1 = scm_string (SCM_EOL);
1921 if (!scm_is_string ($3)) {
1922 parser->parser_error (@3, (_ ("simple string expected")));
1923 $3 = scm_string (SCM_EOL);
1925 $$ = scm_string_append (scm_list_2 ($1, $3));
1929 simple_string: STRING {
1937 if (scm_is_string ($1)) {
1940 parser->parser_error (@1, (_ ("simple string expected")));
1941 $$ = scm_string (SCM_EOL);
1954 embedded_scm_arg_closed
1962 simple_element post_events {
1963 // Let the rhythmic music iterator sort this mess out.
1964 if (scm_is_pair ($2)) {
1965 $$ = make_music_from_simple (parser, @1, $1);
1966 if (unsmob_music ($$))
1967 unsmob_music ($$)->set_property ("articulations",
1968 scm_reverse_x ($2, SCM_EOL));
1970 parser->parser_error (@1, _("music expected"));
1973 | simple_chord_elements post_events {
1974 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1977 /* why is this giving wrong start location? -ns
1979 i.set_location (@1, @2);
1980 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1982 | CHORD_REPETITION optional_notemode_duration post_events {
1984 i.set_location (@1, @3);
1985 $$ = MAKE_SYNTAX ("repetition-chord", i,
1986 $2, scm_reverse_x ($3, SCM_EOL));
1988 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1990 i.set_location (@1, @3);
1991 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1992 scm_reverse_x ($3, SCM_EOL));
1995 | note_chord_element
2000 chord_body optional_notemode_duration post_events
2002 Music *m = unsmob_music ($1);
2003 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2004 SCM es = m->get_property ("elements");
2005 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2007 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2008 unsmob_music (scm_car (s))->set_property ("duration", dur);
2009 es = ly_append2 (es, postevs);
2011 m-> set_property ("elements", es);
2013 $$ = m->self_scm ();
2018 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2020 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2024 chord_body_elements:
2025 /* empty */ { $$ = SCM_EOL; }
2026 | chord_body_elements chord_body_element {
2027 if (!SCM_UNBNDP ($2))
2028 $$ = scm_cons ($2, $1);
2033 pitch exclamations questions octave_check post_events
2035 bool q = to_boolean ($3);
2036 bool ex = to_boolean ($2);
2040 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2041 n->set_property ("pitch", $1);
2043 n->set_property ("cautionary", SCM_BOOL_T);
2045 n->set_property ("force-accidental", SCM_BOOL_T);
2047 if (scm_is_pair (post)) {
2048 SCM arts = scm_reverse_x (post, SCM_EOL);
2049 n->set_property ("articulations", arts);
2051 if (scm_is_number (check))
2053 int q = scm_to_int (check);
2054 n->set_property ("absolute-octave", scm_from_int (q-1));
2057 $$ = n->unprotect ();
2059 | DRUM_PITCH post_events {
2060 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2061 n->set_property ("drum-type", $1);
2063 if (scm_is_pair ($2)) {
2064 SCM arts = scm_reverse_x ($2, SCM_EOL);
2065 n->set_property ("articulations", arts);
2067 $$ = n->unprotect ();
2069 | music_function_chord_body
2071 Music *m = unsmob_music ($1);
2073 while (m && m->is_mus_type ("music-wrapper-music")) {
2074 $$ = m->get_property ("element");
2075 m = unsmob_music ($$);
2078 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2079 parser->parser_error (@$, _ ("not a rhythmic event"));
2085 music_function_chord_body:
2090 // Event functions may only take closed arglists, otherwise it would
2091 // not be clear whether a following postevent should be associated
2092 // with the last argument of the event function or with the expression
2093 // for which the function call acts itself as event.
2095 music_function_call_closed:
2096 MUSIC_FUNCTION function_arglist_closed {
2097 $$ = MAKE_SYNTAX ("music-function", @$,
2102 event_function_event:
2103 EVENT_FUNCTION function_arglist_closed {
2104 $$ = MAKE_SYNTAX ("music-function", @$,
2114 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2115 m->set_property ("span-direction", scm_from_int (START));
2116 $$ = m->unprotect();
2119 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2120 m->set_property ("span-direction", scm_from_int (STOP));
2121 $$ = m->unprotect ();
2124 $$ = MAKE_SYNTAX ("voice-separator", @$);
2127 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2129 Music *m = unsmob_music (pipe);
2134 $$ = m->unprotect ();
2137 $$ = MAKE_SYNTAX ("bar-check", @$);
2144 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2156 | post_events post_event {
2157 unsmob_music ($2)->set_spot (@2);
2158 $$ = scm_cons ($2, $$);
2162 post_event_nofinger:
2163 direction_less_event {
2166 | script_dir music_function_call_closed {
2168 if (!SCM_UNBNDP ($1))
2170 unsmob_music ($$)->set_property ("direction", $1);
2174 if (!parser->lexer_->is_lyric_state ())
2175 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2176 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2179 if (!parser->lexer_->is_lyric_state ())
2180 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2181 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2183 | script_dir direction_reqd_event {
2184 if (!SCM_UNBNDP ($1))
2186 Music *m = unsmob_music ($2);
2187 m->set_property ("direction", $1);
2191 | script_dir direction_less_event {
2192 if (!SCM_UNBNDP ($1))
2194 Music *m = unsmob_music ($2);
2195 m->set_property ("direction", $1);
2202 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2207 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2218 string_number_event:
2220 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2221 s->set_property ("string-number", $1);
2222 $$ = s->unprotect ();
2226 direction_less_char:
2228 $$ = ly_symbol2scm ("bracketOpenSymbol");
2231 $$ = ly_symbol2scm ("bracketCloseSymbol");
2234 $$ = ly_symbol2scm ("tildeSymbol");
2237 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2240 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2243 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2246 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2249 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2252 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2255 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2259 direction_less_event:
2260 direction_less_char {
2261 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2263 if (unsmob_music (predefd))
2265 m = unsmob_music (predefd)->clone ();
2270 m = MY_MAKE_MUSIC ("Music", @$);
2272 $$ = m->unprotect ();
2274 | string_number_event
2275 | EVENT_IDENTIFIER {
2279 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2280 a->set_property ("tremolo-type", $1);
2281 $$ = a->unprotect ();
2283 | event_function_event
2286 direction_reqd_event:
2290 | script_abbreviation {
2291 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2292 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2293 if (scm_is_string (s))
2294 a->set_property ("articulation-type", s);
2295 else parser->parser_error (@1, _ ("expecting string as script definition"));
2296 $$ = a->unprotect ();
2301 /**/ { $$ = SCM_EOL; }
2302 | '=' quotes { $$ = $2; }
2316 $$ = scm_from_int (1);
2319 $$ = scm_oneplus ($1);
2325 $$ = scm_from_int (-1);
2328 $$ = scm_oneminus ($1);
2333 NOTENAME_PITCH quotes {
2334 if (!scm_is_eq (SCM_INUM0, $2))
2336 Pitch p = *unsmob_pitch ($1);
2337 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2338 $$ = p.smobbed_copy ();
2348 TONICNAME_PITCH quotes {
2349 if (!scm_is_eq (SCM_INUM0, $2))
2351 Pitch p = *unsmob_pitch ($1);
2352 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2353 $$ = p.smobbed_copy ();
2363 pitch_also_in_chords:
2370 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2371 t->set_property ("text", $1);
2372 $$ = t->unprotect ();
2375 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2376 t->set_property ("text",
2377 make_simple_markup ($1));
2378 $$ = t->unprotect ();
2381 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2382 t->set_property ("text",
2383 make_simple_markup ($1));
2384 $$ = t->unprotect ();
2388 Music *m = unsmob_music ($1);
2389 if (m && m->is_mus_type ("post-event"))
2391 else if (Text_interface::is_markup ($1)) {
2392 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2393 t->set_property ("text", $1);
2394 $$ = t->unprotect ();
2396 parser->parser_error (@1, _ ("not an articulation"));
2402 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2403 t->set_property ("digit", $1);
2404 $$ = t->unprotect ();
2408 script_abbreviation:
2410 $$ = scm_from_locale_string ("Hat");
2413 $$ = scm_from_locale_string ("Plus");
2416 $$ = scm_from_locale_string ("Dash");
2419 $$ = scm_from_locale_string ("Bar");
2422 $$ = scm_from_locale_string ("Larger");
2425 $$ = scm_from_locale_string ("Dot");
2428 $$ = scm_from_locale_string ("Underscore");
2433 '_' { $$ = scm_from_int (DOWN); }
2434 | '^' { $$ = scm_from_int (UP); }
2435 | '-' { $$ = SCM_UNDEFINED; }
2439 multiplied_duration {
2444 maybe_notemode_duration:
2448 | multiplied_duration {
2450 parser->default_duration_ = *unsmob_duration ($$);
2455 optional_notemode_duration:
2456 maybe_notemode_duration
2458 if (SCM_UNBNDP ($$))
2459 $$ = parser->default_duration_.smobbed_copy ();
2466 int n = scm_to_int ($1);
2467 if (!is_duration (n))
2468 parser->parser_error (@1, _f ("not a duration: %d", n));
2472 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2474 | DURATION_IDENTIFIER dots {
2475 Duration *d = unsmob_duration ($1);
2476 Duration k (d->duration_log (),
2477 d->dot_count () + scm_to_int ($2));
2478 k = k.compressed (d->factor ());
2479 scm_remember_upto_here_1 ($1);
2480 $$ = k.smobbed_copy ();
2484 multiplied_duration:
2488 | multiplied_duration '*' UNSIGNED {
2489 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2491 | multiplied_duration '*' FRACTION {
2492 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2494 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2503 $$ = scm_oneplus ($1);
2512 int n = scm_to_int ($2);
2513 if (!is_duration (n))
2514 parser->parser_error (@2, _f ("not a duration: %d", n));
2520 UNSIGNED { $$ = $1; }
2521 | STRING { $$ = $1; }
2522 | full_markup { $$ = $1; }
2525 // as an integer, it needs to be non-negative, and otherwise
2526 // it needs to be suitable as a markup.
2527 if (scm_is_integer ($1)
2528 ? scm_is_true (scm_negative_p ($1))
2529 : !Text_interface::is_markup ($1))
2531 parser->parser_error (@1, _ ("bass number expected"));
2537 figured_bass_alteration:
2538 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2539 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2540 | '!' { $$ = scm_from_int (0); }
2545 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2546 $$ = bfr->unprotect ();
2549 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2550 $$ = bfr->self_scm ();
2552 if (scm_is_number ($1))
2553 bfr->set_property ("figure", $1);
2554 else if (Text_interface::is_markup ($1))
2555 bfr->set_property ("text", $1);
2561 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2563 | bass_figure figured_bass_alteration {
2564 Music *m = unsmob_music ($1);
2565 if (scm_to_double ($2)) {
2566 SCM salter = m->get_property ("alteration");
2567 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2568 m->set_property ("alteration",
2569 scm_sum (alter, $2));
2571 m->set_property ("alteration", scm_from_int (0));
2574 | bass_figure figured_bass_modification {
2575 Music *m = unsmob_music ($1);
2576 if ($2 == ly_symbol2scm ("plus"))
2578 m->set_property ("augmented", SCM_BOOL_T);
2580 else if ($2 == ly_symbol2scm ("slash"))
2582 m->set_property ("diminished", SCM_BOOL_T);
2584 else if ($2 == ly_symbol2scm ("exclamation"))
2586 m->set_property ("no-continuation", SCM_BOOL_T);
2588 else if ($2 == ly_symbol2scm ("backslash"))
2590 m->set_property ("augmented-slash", SCM_BOOL_T);
2596 figured_bass_modification:
2598 $$ = ly_symbol2scm ("plus");
2601 $$ = ly_symbol2scm ("exclamation");
2604 $$ = ly_symbol2scm ("slash");
2607 $$ = ly_symbol2scm ("backslash");
2617 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2625 | figure_list br_bass_figure {
2626 $$ = scm_cons ($2, $1);
2631 FIGURE_OPEN figure_list FIGURE_CLOSE {
2632 $$ = scm_reverse_x ($2, SCM_EOL);
2638 /**/ { $$ = SCM_BOOL_F; }
2639 | REST { $$ = SCM_BOOL_T; }
2643 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2644 if (!parser->lexer_->is_note_state ())
2645 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2646 if (!SCM_UNBNDP ($2)
2648 || scm_is_number ($4)
2650 || scm_is_true ($6))
2653 if (scm_is_true ($6))
2654 n = MY_MAKE_MUSIC ("RestEvent", @$);
2656 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2658 n->set_property ("pitch", $1);
2659 if (SCM_UNBNDP ($5))
2660 n->set_property ("duration",
2661 parser->default_duration_.smobbed_copy ());
2663 n->set_property ("duration", $5);
2665 if (scm_is_number ($4))
2667 int q = scm_to_int ($4);
2668 n->set_property ("absolute-octave", scm_from_int (q-1));
2671 if (to_boolean ($3))
2672 n->set_property ("cautionary", SCM_BOOL_T);
2673 if (to_boolean ($2) || to_boolean ($3))
2674 n->set_property ("force-accidental", SCM_BOOL_T);
2676 $$ = n->unprotect ();
2679 | DRUM_PITCH optional_notemode_duration {
2680 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2681 n->set_property ("duration", $2);
2682 n->set_property ("drum-type", $1);
2684 $$ = n->unprotect ();
2686 | RESTNAME optional_notemode_duration {
2688 if (ly_scm2string ($1) == "s") {
2690 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2693 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2696 ev->set_property ("duration", $2);
2697 $$ = ev->unprotect ();
2701 simple_chord_elements:
2703 if (!parser->lexer_->is_chord_state ())
2704 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2707 | figure_spec optional_notemode_duration {
2708 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2710 unsmob_music (scm_car (s))->set_property ("duration", $2);
2727 | lyric_element multiplied_duration post_events {
2728 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2729 if (scm_is_pair ($3))
2730 unsmob_music ($$)->set_property
2731 ("articulations", scm_reverse_x ($3, SCM_EOL));
2733 | lyric_element post_event post_events {
2734 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2735 parser->default_duration_.smobbed_copy ());
2736 unsmob_music ($$)->set_property
2737 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2739 | LYRIC_ELEMENT optional_notemode_duration post_events {
2740 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2741 if (scm_is_pair ($3))
2742 unsmob_music ($$)->set_property
2743 ("articulations", scm_reverse_x ($3, SCM_EOL));
2748 lyric_element_music:
2749 lyric_element optional_notemode_duration post_events {
2750 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2751 if (scm_is_pair ($3))
2752 unsmob_music ($$)->set_property
2753 ("articulations", scm_reverse_x ($3, SCM_EOL));
2758 steno_tonic_pitch optional_notemode_duration {
2759 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2761 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2762 SCM its = scm_reverse_x ($4, SCM_EOL);
2763 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2771 | chord_items chord_item {
2772 $$ = scm_cons ($2, $$);
2778 $$ = ly_symbol2scm ("chord-colon");
2781 $$ = ly_symbol2scm ("chord-caret");
2783 | CHORD_SLASH steno_tonic_pitch {
2784 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2786 | CHORD_BASS steno_tonic_pitch {
2787 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2796 $$ = scm_reverse_x ($1, SCM_EOL);
2804 step_number { $$ = scm_cons ($1, SCM_EOL); }
2805 | step_numbers '.' step_number {
2806 $$ = scm_cons ($3, $$);
2812 $$ = make_chord_step ($1, 0);
2815 $$ = make_chord_step ($1, SHARP_ALTERATION);
2817 | UNSIGNED CHORD_MINUS {
2818 $$ = make_chord_step ($1, FLAT_ALTERATION);
2826 | UNSIGNED '~' UNSIGNED {
2827 $$ = scm_cons ($1, $3);
2834 TODO: should deprecate in favor of Scheme?
2838 number_expression '+' number_term {
2839 $$ = scm_sum ($1, $3);
2841 | number_expression '-' number_term {
2842 $$ = scm_difference ($1, $3);
2851 | number_factor '*' number_factor {
2852 $$ = scm_product ($1, $3);
2854 | number_factor '/' number_factor {
2855 $$ = scm_divide ($1, $3);
2860 '-' number_factor { /* %prec UNARY_MINUS */
2861 $$ = scm_difference ($2, SCM_UNDEFINED);
2869 | UNSIGNED NUMBER_IDENTIFIER {
2870 $$ = scm_product ($1, $2);
2872 | REAL NUMBER_IDENTIFIER {
2873 $$ = scm_product ($1, $2);
2889 { $$ = SCM_UNDEFINED; }
2892 if (SCM_UNBNDP ($1))
2900 { $$ = SCM_UNDEFINED; }
2903 if (SCM_UNBNDP ($1))
2911 This should be done more dynamically if possible.
2916 { parser->lexer_->push_markup_state (); }
2919 parser->lexer_->pop_state ();
2925 { parser->lexer_->push_markup_state (); }
2928 parser->lexer_->pop_state ();
2934 { parser->lexer_->push_markup_state (); }
2937 parser->lexer_->pop_state ();
2943 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2945 | markup_head_1_list simple_markup {
2946 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2956 if (Text_interface::is_markup ($1))
2957 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
2958 else if (Text_interface::is_markup_list ($1))
2959 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
2961 parser->parser_error (@1, _ ("not a markup"));
2962 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
2969 markup_composed_list {
2972 | markup_braced_list {
2975 | markup_command_list {
2976 $$ = scm_list_1 ($1);
2978 | markup_scm MARKUPLIST_IDENTIFIER
2984 markup_composed_list:
2985 markup_head_1_list markup_braced_list {
2986 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2992 '{' markup_braced_list_body '}' {
2993 $$ = scm_reverse_x ($2, SCM_EOL);
2997 markup_braced_list_body:
2998 /* empty */ { $$ = SCM_EOL; }
2999 | markup_braced_list_body markup {
3000 $$ = scm_cons ($2, $1);
3002 | markup_braced_list_body markup_list {
3003 $$ = scm_reverse_x ($2, $1);
3007 markup_command_list:
3008 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3009 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3013 markup_command_basic_arguments:
3014 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3015 $$ = scm_cons ($3, $2);
3017 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3018 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3020 | EXPECT_NO_MORE_ARGS {
3025 markup_command_list_arguments:
3026 markup_command_basic_arguments { $$ = $1; }
3027 | EXPECT_MARKUP markup_command_list_arguments markup {
3028 $$ = scm_cons ($3, $2);
3033 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3034 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3039 markup_head_1_item {
3040 $$ = scm_list_1 ($1);
3042 | markup_head_1_list markup_head_1_item {
3043 $$ = scm_cons ($2, $1);
3049 $$ = make_simple_markup ($1);
3052 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3053 parser->lexer_->push_note_state (nn);
3054 } '{' score_body '}' {
3055 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3056 parser->lexer_->pop_state ();
3058 | MARKUP_FUNCTION markup_command_basic_arguments {
3059 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3061 | markup_scm MARKUP_IDENTIFIER
3068 markup_head_1_list simple_markup {
3069 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3070 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3080 Lily_parser::set_yydebug (bool x)
3086 Lily_parser::do_yyparse ()
3088 SCM retval = SCM_UNDEFINED;
3089 yyparse (this, &retval);
3099 It is a little strange to have this function in this file, but
3100 otherwise, we have to import music classes into the lexer.
3104 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3106 if (unsmob_book (sid)) {
3107 Book *book = unsmob_book (sid)->clone ();
3108 *destination = book->self_scm ();
3111 return BOOK_IDENTIFIER;
3112 } else if (scm_is_number (sid)) {
3114 return NUMBER_IDENTIFIER;
3115 } else if (unsmob_context_def (sid)) {
3116 Context_def *def= unsmob_context_def (sid)->clone ();
3118 *destination = def->self_scm ();
3121 return CONTEXT_DEF_IDENTIFIER;
3122 } else if (unsmob_context_mod (sid)) {
3123 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3125 return CONTEXT_MOD_IDENTIFIER;
3126 } else if (unsmob_score (sid)) {
3127 Score *score = new Score (*unsmob_score (sid));
3128 *destination = score->self_scm ();
3130 score->unprotect ();
3131 return SCORE_IDENTIFIER;
3132 } else if (Music *mus = unsmob_music (sid)) {
3133 mus = mus->clone ();
3134 *destination = mus->self_scm ();
3135 unsmob_music (*destination)->
3136 set_property ("origin", make_input (last_input_));
3138 bool is_event = mus->is_mus_type ("post-event");
3140 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3141 } else if (unsmob_pitch (sid)) {
3142 *destination = unsmob_pitch (sid)->smobbed_copy ();
3143 return PITCH_IDENTIFIER;
3144 } else if (unsmob_duration (sid)) {
3145 *destination = unsmob_duration (sid)->smobbed_copy ();
3146 return DURATION_IDENTIFIER;
3147 } else if (unsmob_output_def (sid)) {
3148 Output_def *p = unsmob_output_def (sid);
3151 *destination = p->self_scm ();
3153 return OUTPUT_DEF_IDENTIFIER;
3160 get_next_unique_context_id ()
3162 return scm_from_locale_string ("$uniqueContextId");
3167 get_next_unique_lyrics_context_id ()
3169 static int new_context_count;
3171 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3172 return scm_from_locale_string (s);
3175 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3176 SCM arg, SCM args, SCM pred)
3178 args = scm_cons (arg, args);
3179 if (scm_is_true (scm_call_1 (pred, arg)))
3181 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3182 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3183 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3187 SCM loc_on_music (Input loc, SCM arg)
3189 if (Music *m = unsmob_music (arg))
3193 return m->unprotect ();
3199 is_regular_identifier (SCM id)
3201 string str = ly_scm2string (id);
3202 char const *s = str.c_str ();
3211 v = v && isalnum (*s);
3218 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3220 if (unsmob_music (simple))
3222 if (parser->lexer_->is_note_state ()) {
3223 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3224 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3225 if (scm_is_symbol (simple))
3226 n->set_property ("drum-type", simple);
3227 else if (unsmob_pitch (simple))
3228 n->set_property ("pitch", simple);
3233 return n->unprotect ();
3234 } else if (parser->lexer_->is_lyric_state ()) {
3235 if (Text_interface::is_markup (simple))
3236 return MAKE_SYNTAX ("lyric-event", loc, simple,
3237 parser->default_duration_.smobbed_copy ());
3238 } else if (parser->lexer_->is_chord_state ()) {
3239 if (unsmob_pitch (simple))
3240 return make_chord_elements (loc, simple,
3241 parser->default_duration_.smobbed_copy (),
3248 make_music_with_input (SCM name, Input where)
3250 Music *m = make_music_by_name (name);
3251 m->set_spot (where);
3256 make_simple_markup (SCM a)
3264 return t && t == 1 << intlog2 (t);
3268 make_chord_step (SCM step_scm, Rational alter)
3270 int step = scm_to_int (step_scm);
3273 alter += FLAT_ALTERATION;
3277 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3278 return m.smobbed_copy ();
3283 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3285 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3286 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3287 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3289 unsmob_music (scm_car (s))->set_spot (loc);
3295 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3297 Lily_lexer *lex = parser->lexer_;
3301 lex->prepare_for_next_token ();
3302 return lex->yylex ();