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:
498 $$ = parser->lexer_->eval_scm_token ($1);
502 | context_modification
504 | context_def_spec_block
510 /* The generic version may end in music, or not */
518 embedded_scm_bare_arg
524 SCM_FUNCTION function_arglist {
525 $$ = MAKE_SYNTAX ("music-function", @$,
533 $$ = MAKE_SYNTAX ("void-music", @$);
536 | music_embedded music_embedded music_list {
537 $3 = scm_reverse_x ($3, SCM_EOL);
538 if (unsmob_music ($2))
539 $3 = scm_cons ($2, $3);
540 if (unsmob_music ($1))
541 $3 = scm_cons ($1, $3);
542 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
545 parser->error_level_ = 1;
546 $$ = SCM_UNSPECIFIED;
548 | INVALID embedded_lilypond {
549 parser->error_level_ = 1;
555 lilypond_header_body:
556 /* empty */ { $$ = SCM_UNSPECIFIED; }
557 | lilypond_header_body assignment {
560 | lilypond_header_body embedded_scm {
566 HEADER '{' lilypond_header_body '}' {
567 $$ = parser->lexer_->remove_scope ();
576 | LYRICS_STRING { $$ = $1; }
580 assignment_id '=' identifier_init {
581 parser->lexer_->set_identifier ($1, $3);
582 $$ = SCM_UNSPECIFIED;
584 | assignment_id property_path '=' identifier_init {
585 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
586 parser->lexer_->set_identifier (path, $4);
587 $$ = SCM_UNSPECIFIED;
597 | context_def_spec_block
599 | post_event_nofinger
605 | context_modification
608 context_def_spec_block:
609 CONTEXT '{' context_def_spec_body '}'
620 context_mod_embedded:
623 if (unsmob_music ($1)) {
624 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
625 $1 = scm_call_2 (proc, parser->self_scm (), $1);
627 if (unsmob_context_mod ($1))
630 parser->parser_error (@1, _ ("not a context mod"));
636 context_def_spec_body:
638 $$ = Context_def::make_scm ();
639 unsmob_context_def ($$)->origin ()->set_spot (@$);
641 | CONTEXT_DEF_IDENTIFIER {
643 unsmob_context_def ($$)->origin ()->set_spot (@$);
645 | context_def_spec_body context_mod {
646 unsmob_context_def ($$)->add_context_mod ($2);
648 | context_def_spec_body context_modification {
649 Context_def *td = unsmob_context_def ($$);
650 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
651 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
652 td->add_context_mod (scm_car (m));
655 | context_def_spec_body context_mod_embedded {
656 Context_def *td = unsmob_context_def ($$);
657 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
658 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
659 td->add_context_mod (scm_car (m));
667 BOOK '{' book_body '}' {
670 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
675 * Use 'handlers' like for toplevel-* stuff?
676 * grok \layout and \midi? */
679 Book *book = new Book;
680 init_papers (parser);
681 book->origin ()->set_spot (@$);
682 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
683 book->paper_->unprotect ();
684 push_paper (parser, book->paper_);
685 book->header_ = get_header (parser);
686 $$ = book->unprotect ();
687 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
690 unsmob_book ($1)->origin ()->set_spot (@$);
691 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
693 | book_body paper_block {
694 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
695 set_paper (parser, unsmob_output_def ($2));
697 | book_body bookpart_block {
698 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
699 scm_call_2 (proc, $1, $2);
701 | book_body score_block {
702 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
703 scm_call_2 (proc, $1, $2);
705 | book_body composite_music {
706 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
707 scm_call_3 (proc, parser->self_scm (), $1, $2);
709 | book_body full_markup {
710 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
711 scm_call_2 (proc, $1, scm_list_1 ($2));
713 | book_body full_markup_list {
714 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
715 scm_call_2 (proc, $1, $2);
717 | book_body SCM_TOKEN {
718 // Evaluate and ignore #xxx, as opposed to \xxx
719 parser->lexer_->eval_scm_token ($2);
721 | book_body embedded_scm_active
723 SCM out = SCM_UNDEFINED;
724 if (Text_interface::is_markup ($2))
725 out = scm_list_1 ($2);
726 else if (Text_interface::is_markup_list ($2))
728 if (scm_is_pair (out))
730 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
731 scm_call_2 (proc, $1, out);
732 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
733 parser->parser_error (@2, _("bad expression type"));
737 parser->lexer_->add_scope (unsmob_book ($1)->header_);
740 Book *book = unsmob_book ($1);
742 book->scores_ = SCM_EOL;
743 book->bookparts_ = SCM_EOL;
748 BOOKPART '{' bookpart_body '}' {
750 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
756 Book *book = new Book;
757 book->origin ()->set_spot (@$);
758 $$ = book->unprotect ();
759 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
762 unsmob_book ($1)->origin ()->set_spot (@$);
763 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
765 | bookpart_body paper_block {
766 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
768 | bookpart_body score_block {
769 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
770 scm_call_2 (proc, $1, $2);
772 | bookpart_body composite_music {
773 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
774 scm_call_3 (proc, parser->self_scm (), $1, $2);
776 | bookpart_body full_markup {
777 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
778 scm_call_2 (proc, $1, scm_list_1 ($2));
780 | bookpart_body full_markup_list {
781 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
782 scm_call_2 (proc, $1, $2);
784 | bookpart_body SCM_TOKEN {
785 // Evaluate and ignore #xxx, as opposed to \xxx
786 parser->lexer_->eval_scm_token ($2);
788 | bookpart_body embedded_scm_active
790 SCM out = SCM_UNDEFINED;
791 if (Text_interface::is_markup ($2))
792 out = scm_list_1 ($2);
793 else if (Text_interface::is_markup_list ($2))
795 if (scm_is_pair (out))
797 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
798 scm_call_2 (proc, $1, out);
799 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
800 parser->parser_error (@2, _("bad expression type"));
804 Book *book = unsmob_book ($1);
805 if (!ly_is_module (book->header_))
806 book->header_ = ly_make_module (false);
807 parser->lexer_->add_scope (book->header_);
809 | bookpart_body error {
810 Book *book = unsmob_book ($1);
812 book->scores_ = SCM_EOL;
817 SCORE '{' score_body '}' {
824 SCM scorify = ly_lily_module_constant ("scorify-music");
825 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
827 unsmob_score ($$)->origin ()->set_spot (@$);
830 unsmob_score ($$)->origin ()->set_spot (@$);
834 Score *score = unsmob_score ($1);
835 if (!ly_is_module (score->get_header ()))
836 score->set_header (ly_make_module (false));
837 parser->lexer_->add_scope (score->get_header ());
839 | score_body output_def {
840 Output_def *od = unsmob_output_def ($2);
841 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
843 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
848 unsmob_score ($1)->add_output_def (od);
852 unsmob_score ($$)->error_found_ = true;
863 Output_def *od = unsmob_output_def ($1);
865 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
867 parser->parser_error (@1, _ ("need \\paper for paper block"));
868 $$ = get_paper (parser)->unprotect ();
875 output_def_body '}' {
878 parser->lexer_->remove_scope ();
879 parser->lexer_->pop_state ();
885 Output_def *p = get_paper (parser);
886 p->input_origin_ = @$;
887 parser->lexer_->add_scope (p->scope_);
888 $$ = p->unprotect ();
891 Output_def *p = get_midi (parser);
892 $$ = p->unprotect ();
893 parser->lexer_->add_scope (p->scope_);
896 Output_def *p = get_layout (parser);
898 parser->lexer_->add_scope (p->scope_);
899 $$ = p->unprotect ();
903 output_def_head_with_mode_switch:
905 parser->lexer_->push_initial_state ();
910 // We need this weird nonterminal because both music as well as a
911 // context definition can start with \context and the difference is
912 // only apparent after looking at the next token. If it is '{', there
913 // is still time to escape from notes mode.
915 music_or_context_def:
918 parser->lexer_->pop_state ();
922 parser->lexer_->pop_state ();
923 } '{' context_def_spec_body '}'
930 output_def_head_with_mode_switch '{' {
932 unsmob_output_def ($$)->input_origin_.set_spot (@$);
934 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
935 Output_def *o = unsmob_output_def ($3);
936 o->input_origin_.set_spot (@$);
938 parser->lexer_->remove_scope ();
939 parser->lexer_->add_scope (o->scope_);
941 | output_def_body assignment {
944 | output_def_body embedded_scm {
949 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
950 parser->lexer_->push_note_state (nn);
951 } music_or_context_def
953 if (unsmob_context_def ($3))
954 assign_context_def (unsmob_output_def ($1), $3);
957 SCM proc = parser->lexer_->lookup_identifier
958 ("output-def-music-handler");
959 scm_call_3 (proc, parser->self_scm (),
963 | output_def_body error {
969 TEMPO steno_duration '=' tempo_range {
970 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
972 | TEMPO scalar_closed steno_duration '=' tempo_range {
973 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
976 $$ = MAKE_SYNTAX ("tempo", @$, $2);
981 The representation of a list is reversed to have efficient append. */
987 | music_list music_embedded {
988 if (unsmob_music ($2))
989 $$ = scm_cons ($2, $1);
992 Music *m = MY_MAKE_MUSIC("Music", @$);
994 m->set_property ("error-found", SCM_BOOL_T);
995 $$ = scm_cons (m->self_scm (), $1);
996 m->unprotect (); /* UGH */
1003 $$ = scm_reverse_x ($2, SCM_EOL);
1008 | lyric_element_music
1015 if (unsmob_music ($1)
1016 || scm_is_eq ($1, SCM_UNSPECIFIED))
1020 @$.warning (_ ("Ignoring non-music expression"));
1021 $$ = SCM_UNSPECIFIED;
1029 $$ = make_music_from_simple (parser, @1, $1);
1030 if (!unsmob_music ($$))
1031 parser->parser_error (@1, _ ("music expected"));
1033 | composite_music %prec COMPOSITE
1038 | composite_music %prec COMPOSITE
1042 REPEAT simple_string unsigned_number music
1044 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1046 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1048 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1053 SEQUENTIAL braced_music_list {
1054 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1056 | braced_music_list {
1057 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1062 SIMULTANEOUS braced_music_list {
1063 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1065 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1066 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1072 | music_property_def
1076 context_modification:
1077 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1079 parser->lexer_->pop_state ();
1082 | WITH CONTEXT_MOD_IDENTIFIER
1086 | CONTEXT_MOD_IDENTIFIER
1090 | WITH embedded_scm_closed
1092 if (unsmob_context_mod ($2))
1095 parser->parser_error (@2, _ ("not a context mod"));
1096 $$ = Context_mod ().smobbed_copy ();
1101 optional_context_mod:
1105 | context_modification
1113 $$ = Context_mod ().smobbed_copy ();
1115 | context_mod_list context_mod {
1116 unsmob_context_mod ($1)->add_context_mod ($2);
1118 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1119 Context_mod *md = unsmob_context_mod ($2);
1121 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1123 | context_mod_list context_mod_embedded {
1124 unsmob_context_mod ($1)->add_context_mods
1125 (unsmob_context_mod ($2)->get_mods ());
1134 /* Music that can be parsed without lookahead */
1137 | complex_music_prefix closed_music
1139 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1141 | music_function_call_closed
1147 | grouped_music_list
1151 simultaneous_music { $$ = $1; }
1152 | sequential_music { $$ = $1; }
1155 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1156 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1157 and this rule returns the reversed list of arguments. */
1159 function_arglist_skip:
1160 function_arglist_common
1161 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1163 $$ = scm_cons ($1, $3);
1164 } %prec FUNCTION_ARGLIST
1165 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1167 $$ = scm_cons ($1, $3);
1168 } %prec FUNCTION_ARGLIST
1169 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1171 $$ = scm_cons ($1, $3);
1172 } %prec FUNCTION_ARGLIST
1176 function_arglist_nonbackup_common:
1177 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1178 $$ = scm_cons ($4, $3);
1180 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1181 $$ = scm_cons ($4, $3);
1183 | EXPECT_OPTIONAL EXPECT_SCM function_arglist FRACTION
1185 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1187 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1189 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1191 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1193 SCM n = scm_difference ($5, SCM_UNDEFINED);
1194 if (scm_is_true (scm_call_1 ($2, n)))
1195 $$ = scm_cons (n, $3);
1197 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1198 t->set_property ("digit", $5);
1199 $$ = t->unprotect ();
1200 if (scm_is_true (scm_call_1 ($2, $$)))
1201 $$ = scm_cons ($$, $3);
1203 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1207 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1209 $$ = check_scheme_arg (parser, @4,
1210 scm_difference ($5, SCM_UNDEFINED),
1213 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1215 $$ = check_scheme_arg (parser, @4,
1216 scm_difference ($5, SCM_UNDEFINED),
1221 function_arglist_closed_nonbackup:
1222 function_arglist_nonbackup_common
1223 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1225 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1227 | EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1229 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1231 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1233 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1237 function_arglist_nonbackup:
1238 function_arglist_nonbackup_common
1239 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1241 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1243 | EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1245 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1247 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1249 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1253 function_arglist_keep:
1254 function_arglist_common
1255 | function_arglist_backup
1258 function_arglist_closed_keep:
1259 function_arglist_closed_common
1260 | function_arglist_backup
1263 function_arglist_backup:
1264 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1266 if (scm_is_true (scm_call_1 ($2, $4)))
1268 $$ = scm_cons ($4, $3);
1270 $$ = scm_cons (loc_on_music (@3, $1), $3);
1271 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1274 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep SCM_IDENTIFIER
1276 if (scm_is_true (scm_call_1 ($2, $4)))
1278 $$ = scm_cons ($4, $3);
1280 $$ = scm_cons (loc_on_music (@3, $1), $3);
1281 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1284 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1286 if (scm_is_true (scm_call_1 ($2, $4)))
1288 $$ = scm_cons ($4, $3);
1290 $$ = scm_cons (loc_on_music (@3, $1), $3);
1291 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1294 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1296 // There is no point interpreting a lyrics string as
1297 // an event, since we don't allow music possibly
1298 // followed by durations or postevent into closed
1299 // music, and we only accept closed music in optional
1300 // arguments at the moment. If this changes, more
1301 // complex schemes might become interesting here as
1302 // well: see how we do this at the mandatory argument
1304 if (scm_is_true (scm_call_1 ($2, $4)))
1305 $$ = scm_cons ($4, $3);
1307 $$ = scm_cons (loc_on_music (@3, $1), $3);
1308 MYBACKUP (LYRICS_STRING, $4, @4);
1311 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1313 if (scm_is_true (scm_call_1 ($2, $4)))
1316 MYREPARSE (@4, $2, UNSIGNED, $4);
1318 $$ = scm_cons (loc_on_music (@3, $1), $3);
1319 MYBACKUP (UNSIGNED, $4, @4);
1322 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1324 if (scm_is_true (scm_call_1 ($2, $4)))
1327 MYREPARSE (@4, $2, REAL, $4);
1329 $$ = scm_cons (loc_on_music (@3, $1), $3);
1330 MYBACKUP (REAL, $4, @4);
1333 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1335 if (scm_is_true (scm_call_1 ($2, $4)))
1337 $$ = scm_cons ($4, $3);
1339 $$ = scm_cons (loc_on_music (@3, $1), $3);
1340 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1343 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1345 if (scm_is_true (scm_call_1 ($2, $4)))
1347 $$ = scm_cons ($4, $3);
1349 $$ = scm_cons (loc_on_music (@3, $1), $3);
1350 MYBACKUP (FRACTION, $4, @4);
1353 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1355 SCM n = scm_difference ($5, SCM_UNDEFINED);
1356 if (scm_is_true (scm_call_1 ($2, n))) {
1358 MYREPARSE (@5, $2, REAL, n);
1360 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1361 t->set_property ("digit", $5);
1362 $$ = t->unprotect ();
1363 if (scm_is_true (scm_call_1 ($2, $$)))
1364 $$ = scm_cons ($$, $3);
1366 $$ = scm_cons (loc_on_music (@3, $1), $3);
1367 MYBACKUP (UNSIGNED, $5, @5);
1368 parser->lexer_->push_extra_token ('-');
1373 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1375 SCM n = scm_difference ($5, SCM_UNDEFINED);
1376 if (scm_is_true (scm_call_1 ($2, n))) {
1377 MYREPARSE (@5, $2, REAL, n);
1380 MYBACKUP (REAL, n, @5);
1383 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1385 SCM n = scm_difference ($5, SCM_UNDEFINED);
1386 if (scm_is_true (scm_call_1 ($2, n))) {
1387 $$ = scm_cons (n, $3);
1389 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1392 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1394 $$ = scm_cons ($4, $3);
1396 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1398 $$ = scm_cons ($4, $3);
1400 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1402 $$ = scm_cons ($1, $3);
1403 MYBACKUP(0, SCM_UNDEFINED, @3);
1405 | function_arglist_backup REPARSE embedded_scm_arg_closed
1407 $$ = check_scheme_arg (parser, @3,
1410 | function_arglist_backup REPARSE SCM_IDENTIFIER
1412 $$ = check_scheme_arg (parser, @3,
1415 | function_arglist_backup REPARSE bare_number
1417 $$ = check_scheme_arg (parser, @3,
1423 function_arglist_common
1424 | function_arglist_nonbackup
1427 function_arglist_common:
1428 function_arglist_bare
1429 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1431 $$ = check_scheme_arg (parser, @3,
1434 | EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1436 $$ = check_scheme_arg (parser, @3,
1439 | EXPECT_SCM function_arglist_closed_optional bare_number
1441 $$ = check_scheme_arg (parser, @3,
1444 | EXPECT_SCM function_arglist_optional FRACTION
1446 $$ = check_scheme_arg (parser, @3,
1449 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1451 $$ = check_scheme_arg (parser, @3,
1454 | function_arglist_common_minus
1455 | function_arglist_common_lyric
1458 function_arglist_common_lyric:
1459 EXPECT_SCM function_arglist_optional lyric_element
1461 // We check how the predicate thinks about a lyrics
1462 // event or about a markup. If it accepts neither, we
1463 // backup the original token. Otherwise we commit to
1464 // taking the token. Depending on what the predicate
1465 // is willing to accept, we interpret as a string, as
1466 // a lyric event, or ambiguously (meaning that if
1467 // something looking like a duration or post event
1468 // follows, we take the event, otherwise the string).
1469 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1470 parser->default_duration_.smobbed_copy ());
1471 if (scm_is_true (scm_call_1 ($1, $3)))
1472 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1475 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1477 $$ = scm_cons ($3, $2);
1479 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1482 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1484 // This is going to flag a syntax error, we
1485 // know the predicate to be false.
1486 check_scheme_arg (parser, @3,
1490 | function_arglist_common_lyric REPARSE lyric_element_arg
1492 // This should never be false
1493 $$ = check_scheme_arg (parser, @3,
1498 function_arglist_common_minus:
1499 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1501 SCM n = scm_difference ($4, SCM_UNDEFINED);
1502 if (scm_is_true (scm_call_1 ($1, n))) {
1504 MYREPARSE (@4, $1, REAL, n);
1506 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1507 t->set_property ("digit", $4);
1508 $$ = t->unprotect ();
1509 if (scm_is_true (scm_call_1 ($1, $$)))
1510 $$ = scm_cons ($$, $2);
1512 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1516 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1519 SCM n = scm_difference ($4, SCM_UNDEFINED);
1520 MYREPARSE (@4, $1, REAL, n);
1522 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1524 SCM n = scm_difference ($4, SCM_UNDEFINED);
1525 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1527 | function_arglist_common_minus REPARSE bare_number
1529 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1533 function_arglist_closed:
1534 function_arglist_closed_common
1535 | function_arglist_closed_nonbackup
1538 function_arglist_closed_common:
1539 function_arglist_bare
1540 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1542 $$ = check_scheme_arg (parser, @3,
1545 | EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1547 $$ = check_scheme_arg (parser, @3,
1550 | EXPECT_SCM function_arglist_closed_optional bare_number
1552 $$ = check_scheme_arg (parser, @3,
1555 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1557 SCM n = scm_difference ($4, SCM_UNDEFINED);
1558 if (scm_is_true (scm_call_1 ($1, n))) {
1559 $$ = scm_cons (n, $2);
1561 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1562 t->set_property ("digit", $4);
1563 $$ = t->unprotect ();
1564 if (scm_is_true (scm_call_1 ($1, $$)))
1565 $$ = scm_cons ($$, $2);
1567 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1571 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1573 $$ = check_scheme_arg (parser, @3,
1574 scm_difference ($4, SCM_UNDEFINED),
1577 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1579 $$ = check_scheme_arg (parser, @3,
1580 scm_difference ($4, SCM_UNDEFINED),
1583 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1585 $$ = check_scheme_arg (parser, @3,
1588 | EXPECT_SCM function_arglist_optional FRACTION
1590 $$ = check_scheme_arg (parser, @3,
1593 | EXPECT_SCM function_arglist_optional lyric_element
1595 $$ = check_scheme_arg (parser, @3,
1600 function_arglist_optional:
1601 function_arglist_keep %prec FUNCTION_ARGLIST
1602 | function_arglist_backup BACKUP
1603 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1605 $$ = scm_cons ($1, $3);
1607 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1609 $$ = scm_cons ($1, $3);
1613 function_arglist_closed_optional:
1614 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1615 | function_arglist_backup BACKUP
1616 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1618 $$ = scm_cons ($1, $3);
1620 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1622 $$ = scm_cons ($1, $3);
1626 embedded_scm_closed:
1628 | scm_function_call_closed
1631 embedded_scm_arg_closed:
1632 embedded_scm_bare_arg
1633 | scm_function_call_closed
1637 scm_function_call_closed:
1638 SCM_FUNCTION function_arglist_closed {
1639 $$ = MAKE_SYNTAX ("music-function", @$,
1641 } %prec FUNCTION_ARGLIST
1644 function_arglist_bare:
1645 EXPECT_NO_MORE_ARGS {
1648 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1649 $$ = scm_cons ($3, $2);
1651 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1652 $$ = scm_cons ($3, $2);
1654 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1655 $$ = scm_cons ($1, $3);
1657 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1658 $$ = scm_cons ($1, $3);
1660 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1661 $$ = scm_cons ($1, $3);
1665 music_function_call:
1666 MUSIC_FUNCTION function_arglist {
1667 $$ = MAKE_SYNTAX ("music-function", @$,
1674 /**/ { $$ = SCM_EOL; }
1675 | '=' simple_string {
1682 | repeated_music { $$ = $1; }
1683 | re_rhythmed_music { $$ = $1; }
1684 | complex_music_prefix music
1686 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1690 complex_music_prefix:
1691 CONTEXT simple_string optional_id optional_context_mod {
1692 Context_mod *ctxmod = unsmob_context_mod ($4);
1695 mods = ctxmod->get_mods ();
1696 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1698 | NEWCONTEXT simple_string optional_id optional_context_mod {
1699 Context_mod *ctxmod = unsmob_context_mod ($4);
1702 mods = ctxmod->get_mods ();
1703 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1708 mode_changing_head grouped_music_list {
1709 if ($1 == ly_symbol2scm ("chords"))
1711 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1717 parser->lexer_->pop_state ();
1719 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1720 Context_mod *ctxmod = unsmob_context_mod ($2);
1723 mods = ctxmod->get_mods ();
1724 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1725 if ($1 == ly_symbol2scm ("ChordNames"))
1727 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1729 parser->lexer_->pop_state ();
1735 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1736 parser->lexer_->push_note_state (nn);
1738 $$ = ly_symbol2scm ("notes");
1742 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1743 parser->lexer_->push_note_state (nn);
1745 $$ = ly_symbol2scm ("drums");
1748 parser->lexer_->push_figuredbass_state ();
1750 $$ = ly_symbol2scm ("figures");
1753 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1754 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1755 nn = parser->lexer_->lookup_identifier ("pitchnames");
1756 parser->lexer_->push_chord_state (nn);
1757 $$ = ly_symbol2scm ("chords");
1761 { parser->lexer_->push_lyric_state ();
1762 $$ = ly_symbol2scm ("lyrics");
1766 mode_changing_head_with_context:
1768 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1769 parser->lexer_->push_note_state (nn);
1771 $$ = ly_symbol2scm ("DrumStaff");
1774 parser->lexer_->push_figuredbass_state ();
1776 $$ = ly_symbol2scm ("FiguredBass");
1779 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1780 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1781 nn = parser->lexer_->lookup_identifier ("pitchnames");
1782 parser->lexer_->push_chord_state (nn);
1783 $$ = ly_symbol2scm ("ChordNames");
1786 { parser->lexer_->push_lyric_state ();
1787 $$ = ly_symbol2scm ("Lyrics");
1792 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1795 /* Can also use music at the expensive of two S/Rs similar to
1796 \repeat \alternative */
1797 parser->lexer_->pop_state ();
1799 $$ = scm_cons ($3, SCM_EOL);
1801 | new_lyrics ADDLYRICS {
1802 parser->lexer_->push_lyric_state ();
1804 parser->lexer_->pop_state ();
1805 $$ = scm_cons ($4, $1);
1810 composite_music new_lyrics {
1811 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1813 | LYRICSTO simple_string {
1814 parser->lexer_->push_lyric_state ();
1816 parser->lexer_->pop_state ();
1817 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1822 CHANGE STRING '=' STRING {
1823 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1828 property_path_revved:
1829 embedded_scm_closed {
1830 $$ = scm_cons ($1, SCM_EOL);
1832 | property_path_revved embedded_scm_closed {
1833 $$ = scm_cons ($2, $1);
1838 property_path_revved {
1839 $$ = scm_reverse_x ($1, SCM_EOL);
1845 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1846 scm_string_to_symbol ($1), $3);
1848 | UNSET simple_string {
1849 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1850 scm_string_to_symbol ($2));
1852 | OVERRIDE simple_string property_path '=' scalar {
1853 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1854 scm_string_to_symbol ($2), $5),
1857 | REVERT simple_string embedded_scm {
1858 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1859 scm_string_to_symbol ($2), $3);
1864 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1865 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1867 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1868 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1869 | DENIES { $$ = ly_symbol2scm ("denies"); }
1871 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1872 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1873 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1874 | NAME { $$ = ly_symbol2scm ("context-name"); }
1878 property_operation { $$ = $1; }
1879 | context_def_mod STRING {
1880 $$ = scm_list_2 ($1, $2);
1882 | context_def_mod embedded_scm
1884 if (!scm_is_string ($2)
1885 && ly_symbol2scm ("consists") != $1
1886 && ly_symbol2scm ("remove") != $1)
1889 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
1893 $$ = scm_list_2 ($1, $2);
1900 if (!is_regular_identifier ($1))
1902 @$.error (_("Grob name should be alphanumeric"));
1905 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1906 scm_string_to_symbol ($1));
1908 | simple_string '.' simple_string {
1909 $$ = scm_list_2 (scm_string_to_symbol ($1),
1910 scm_string_to_symbol ($3));
1914 simple_music_property_def:
1915 OVERRIDE context_prop_spec property_path '=' scalar {
1916 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1917 ly_symbol2scm ("OverrideProperty"),
1922 | REVERT context_prop_spec embedded_scm {
1923 $$ = scm_list_4 (scm_car ($2),
1924 ly_symbol2scm ("RevertProperty"),
1928 | SET context_prop_spec '=' scalar {
1929 $$ = scm_list_4 (scm_car ($2),
1930 ly_symbol2scm ("PropertySet"),
1934 | UNSET context_prop_spec {
1935 $$ = scm_list_3 (scm_car ($2),
1936 ly_symbol2scm ("PropertyUnset"),
1942 simple_music_property_def {
1943 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
1952 | string '+' string {
1953 if (!scm_is_string ($1)) {
1954 parser->parser_error (@1, (_ ("simple string expected")));
1955 $1 = scm_string (SCM_EOL);
1957 if (!scm_is_string ($3)) {
1958 parser->parser_error (@3, (_ ("simple string expected")));
1959 $3 = scm_string (SCM_EOL);
1961 $$ = scm_string_append (scm_list_2 ($1, $3));
1965 simple_string: STRING {
1973 if (scm_is_string ($1)) {
1976 parser->parser_error (@1, (_ ("simple string expected")));
1977 $$ = scm_string (SCM_EOL);
1991 embedded_scm_arg_closed
2000 simple_element post_events {
2001 // Let the rhythmic music iterator sort this mess out.
2002 if (scm_is_pair ($2)) {
2003 $$ = make_music_from_simple (parser, @1, $1);
2004 if (unsmob_music ($$))
2005 unsmob_music ($$)->set_property ("articulations",
2006 scm_reverse_x ($2, SCM_EOL));
2008 parser->parser_error (@1, _("music expected"));
2011 | simple_chord_elements post_events {
2012 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2015 /* why is this giving wrong start location? -ns
2017 i.set_location (@1, @2);
2018 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2020 | CHORD_REPETITION optional_notemode_duration post_events {
2022 i.set_location (@1, @3);
2023 $$ = MAKE_SYNTAX ("repetition-chord", i,
2024 $2, scm_reverse_x ($3, SCM_EOL));
2026 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2028 i.set_location (@1, @3);
2029 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2030 scm_reverse_x ($3, SCM_EOL));
2033 | note_chord_element
2038 chord_body optional_notemode_duration post_events
2040 Music *m = unsmob_music ($1);
2041 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2042 SCM es = m->get_property ("elements");
2043 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2045 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2046 unsmob_music (scm_car (s))->set_property ("duration", dur);
2047 es = ly_append2 (es, postevs);
2049 m-> set_property ("elements", es);
2051 $$ = m->self_scm ();
2056 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2058 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2062 chord_body_elements:
2063 /* empty */ { $$ = SCM_EOL; }
2064 | chord_body_elements chord_body_element {
2065 if (!SCM_UNBNDP ($2))
2066 $$ = scm_cons ($2, $1);
2071 pitch exclamations questions octave_check post_events
2073 bool q = to_boolean ($3);
2074 bool ex = to_boolean ($2);
2078 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2079 n->set_property ("pitch", $1);
2081 n->set_property ("cautionary", SCM_BOOL_T);
2083 n->set_property ("force-accidental", SCM_BOOL_T);
2085 if (scm_is_pair (post)) {
2086 SCM arts = scm_reverse_x (post, SCM_EOL);
2087 n->set_property ("articulations", arts);
2089 if (scm_is_number (check))
2091 int q = scm_to_int (check);
2092 n->set_property ("absolute-octave", scm_from_int (q-1));
2095 $$ = n->unprotect ();
2097 | DRUM_PITCH post_events {
2098 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2099 n->set_property ("drum-type", $1);
2101 if (scm_is_pair ($2)) {
2102 SCM arts = scm_reverse_x ($2, SCM_EOL);
2103 n->set_property ("articulations", arts);
2105 $$ = n->unprotect ();
2107 | music_function_chord_body
2109 Music *m = unsmob_music ($1);
2111 while (m && m->is_mus_type ("music-wrapper-music")) {
2112 $$ = m->get_property ("element");
2113 m = unsmob_music ($$);
2116 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2117 parser->parser_error (@$, _ ("not a rhythmic event"));
2123 music_function_chord_body:
2128 // Event functions may only take closed arglists, otherwise it would
2129 // not be clear whether a following postevent should be associated
2130 // with the last argument of the event function or with the expression
2131 // for which the function call acts itself as event.
2133 music_function_call_closed:
2134 MUSIC_FUNCTION function_arglist_closed {
2135 $$ = MAKE_SYNTAX ("music-function", @$,
2140 event_function_event:
2141 EVENT_FUNCTION function_arglist_closed {
2142 $$ = MAKE_SYNTAX ("music-function", @$,
2152 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2153 m->set_property ("span-direction", scm_from_int (START));
2154 $$ = m->unprotect();
2157 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2158 m->set_property ("span-direction", scm_from_int (STOP));
2159 $$ = m->unprotect ();
2162 $$ = MAKE_SYNTAX ("voice-separator", @$);
2165 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2167 Music *m = unsmob_music (pipe);
2172 $$ = m->unprotect ();
2175 $$ = MAKE_SYNTAX ("bar-check", @$);
2182 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2194 | post_events post_event {
2195 unsmob_music ($2)->set_spot (@2);
2196 $$ = scm_cons ($2, $$);
2200 post_event_nofinger:
2201 direction_less_event {
2204 | script_dir music_function_call_closed {
2206 if (!SCM_UNBNDP ($1))
2208 unsmob_music ($$)->set_property ("direction", $1);
2212 if (!parser->lexer_->is_lyric_state ())
2213 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2214 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2217 if (!parser->lexer_->is_lyric_state ())
2218 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2219 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2221 | script_dir direction_reqd_event {
2222 if (!SCM_UNBNDP ($1))
2224 Music *m = unsmob_music ($2);
2225 m->set_property ("direction", $1);
2229 | script_dir direction_less_event {
2230 if (!SCM_UNBNDP ($1))
2232 Music *m = unsmob_music ($2);
2233 m->set_property ("direction", $1);
2240 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2245 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2256 string_number_event:
2258 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2259 s->set_property ("string-number", $1);
2260 $$ = s->unprotect ();
2264 direction_less_char:
2266 $$ = ly_symbol2scm ("bracketOpenSymbol");
2269 $$ = ly_symbol2scm ("bracketCloseSymbol");
2272 $$ = ly_symbol2scm ("tildeSymbol");
2275 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2278 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2281 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2284 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2287 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2290 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2293 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2297 direction_less_event:
2298 direction_less_char {
2299 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2301 if (unsmob_music (predefd))
2303 m = unsmob_music (predefd)->clone ();
2308 m = MY_MAKE_MUSIC ("Music", @$);
2310 $$ = m->unprotect ();
2312 | string_number_event
2313 | EVENT_IDENTIFIER {
2317 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2318 a->set_property ("tremolo-type", $1);
2319 $$ = a->unprotect ();
2321 | event_function_event
2324 direction_reqd_event:
2328 | script_abbreviation {
2329 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2330 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2331 if (scm_is_string (s))
2332 a->set_property ("articulation-type", s);
2333 else parser->parser_error (@1, _ ("expecting string as script definition"));
2334 $$ = a->unprotect ();
2339 /**/ { $$ = SCM_EOL; }
2340 | '=' quotes { $$ = $2; }
2354 $$ = scm_from_int (1);
2357 $$ = scm_oneplus ($1);
2363 $$ = scm_from_int (-1);
2366 $$ = scm_oneminus ($1);
2371 NOTENAME_PITCH quotes {
2372 if (!scm_is_eq (SCM_INUM0, $2))
2374 Pitch p = *unsmob_pitch ($1);
2375 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2376 $$ = p.smobbed_copy ();
2386 TONICNAME_PITCH quotes {
2387 if (!scm_is_eq (SCM_INUM0, $2))
2389 Pitch p = *unsmob_pitch ($1);
2390 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2391 $$ = p.smobbed_copy ();
2401 pitch_also_in_chords:
2408 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2409 t->set_property ("text", $1);
2410 $$ = t->unprotect ();
2413 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2414 t->set_property ("text",
2415 make_simple_markup ($1));
2416 $$ = t->unprotect ();
2419 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2420 t->set_property ("text",
2421 make_simple_markup ($1));
2422 $$ = t->unprotect ();
2426 Music *m = unsmob_music ($1);
2427 if (m && m->is_mus_type ("post-event"))
2429 else if (Text_interface::is_markup ($1)) {
2430 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2431 t->set_property ("text", $1);
2432 $$ = t->unprotect ();
2434 parser->parser_error (@1, _ ("not an articulation"));
2440 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2441 t->set_property ("digit", $1);
2442 $$ = t->unprotect ();
2446 script_abbreviation:
2448 $$ = scm_from_locale_string ("Hat");
2451 $$ = scm_from_locale_string ("Plus");
2454 $$ = scm_from_locale_string ("Dash");
2457 $$ = scm_from_locale_string ("Bar");
2460 $$ = scm_from_locale_string ("Larger");
2463 $$ = scm_from_locale_string ("Dot");
2466 $$ = scm_from_locale_string ("Underscore");
2471 '_' { $$ = scm_from_int (DOWN); }
2472 | '^' { $$ = scm_from_int (UP); }
2473 | '-' { $$ = SCM_UNDEFINED; }
2477 multiplied_duration {
2482 maybe_notemode_duration:
2486 | multiplied_duration {
2488 parser->default_duration_ = *unsmob_duration ($$);
2493 optional_notemode_duration:
2494 maybe_notemode_duration
2496 if (SCM_UNBNDP ($$))
2497 $$ = parser->default_duration_.smobbed_copy ();
2504 int n = scm_to_int ($1);
2505 if (!is_duration (n))
2506 parser->parser_error (@1, _f ("not a duration: %d", n));
2510 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2512 | DURATION_IDENTIFIER dots {
2513 Duration *d = unsmob_duration ($1);
2514 Duration k (d->duration_log (),
2515 d->dot_count () + scm_to_int ($2));
2516 k = k.compressed (d->factor ());
2517 scm_remember_upto_here_1 ($1);
2518 $$ = k.smobbed_copy ();
2522 multiplied_duration:
2526 | multiplied_duration '*' UNSIGNED {
2527 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2529 | multiplied_duration '*' FRACTION {
2530 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2532 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2541 $$ = scm_oneplus ($1);
2550 int n = scm_to_int ($2);
2551 if (!is_duration (n))
2552 parser->parser_error (@2, _f ("not a duration: %d", n));
2558 UNSIGNED { $$ = $1; }
2559 | STRING { $$ = $1; }
2560 | full_markup { $$ = $1; }
2563 // as an integer, it needs to be non-negative, and otherwise
2564 // it needs to be suitable as a markup.
2565 if (scm_is_integer ($1)
2566 ? scm_is_true (scm_negative_p ($1))
2567 : !Text_interface::is_markup ($1))
2569 parser->parser_error (@1, _ ("bass number expected"));
2575 figured_bass_alteration:
2576 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2577 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2578 | '!' { $$ = scm_from_int (0); }
2583 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2584 $$ = bfr->unprotect ();
2587 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2588 $$ = bfr->self_scm ();
2590 if (scm_is_number ($1))
2591 bfr->set_property ("figure", $1);
2592 else if (Text_interface::is_markup ($1))
2593 bfr->set_property ("text", $1);
2599 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2601 | bass_figure figured_bass_alteration {
2602 Music *m = unsmob_music ($1);
2603 if (scm_to_double ($2)) {
2604 SCM salter = m->get_property ("alteration");
2605 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2606 m->set_property ("alteration",
2607 scm_sum (alter, $2));
2609 m->set_property ("alteration", scm_from_int (0));
2612 | bass_figure figured_bass_modification {
2613 Music *m = unsmob_music ($1);
2614 if ($2 == ly_symbol2scm ("plus"))
2616 m->set_property ("augmented", SCM_BOOL_T);
2618 else if ($2 == ly_symbol2scm ("slash"))
2620 m->set_property ("diminished", SCM_BOOL_T);
2622 else if ($2 == ly_symbol2scm ("exclamation"))
2624 m->set_property ("no-continuation", SCM_BOOL_T);
2626 else if ($2 == ly_symbol2scm ("backslash"))
2628 m->set_property ("augmented-slash", SCM_BOOL_T);
2634 figured_bass_modification:
2636 $$ = ly_symbol2scm ("plus");
2639 $$ = ly_symbol2scm ("exclamation");
2642 $$ = ly_symbol2scm ("slash");
2645 $$ = ly_symbol2scm ("backslash");
2655 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2663 | figure_list br_bass_figure {
2664 $$ = scm_cons ($2, $1);
2669 FIGURE_OPEN figure_list FIGURE_CLOSE {
2670 $$ = scm_reverse_x ($2, SCM_EOL);
2676 /**/ { $$ = SCM_BOOL_F; }
2677 | REST { $$ = SCM_BOOL_T; }
2681 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2682 if (!parser->lexer_->is_note_state ())
2683 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2684 if (!SCM_UNBNDP ($2)
2686 || scm_is_number ($4)
2688 || scm_is_true ($6))
2691 if (scm_is_true ($6))
2692 n = MY_MAKE_MUSIC ("RestEvent", @$);
2694 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2696 n->set_property ("pitch", $1);
2697 if (SCM_UNBNDP ($5))
2698 n->set_property ("duration",
2699 parser->default_duration_.smobbed_copy ());
2701 n->set_property ("duration", $5);
2703 if (scm_is_number ($4))
2705 int q = scm_to_int ($4);
2706 n->set_property ("absolute-octave", scm_from_int (q-1));
2709 if (to_boolean ($3))
2710 n->set_property ("cautionary", SCM_BOOL_T);
2711 if (to_boolean ($2) || to_boolean ($3))
2712 n->set_property ("force-accidental", SCM_BOOL_T);
2714 $$ = n->unprotect ();
2717 | DRUM_PITCH optional_notemode_duration {
2718 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2719 n->set_property ("duration", $2);
2720 n->set_property ("drum-type", $1);
2722 $$ = n->unprotect ();
2724 | RESTNAME optional_notemode_duration {
2726 if (ly_scm2string ($1) == "s") {
2728 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2731 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2734 ev->set_property ("duration", $2);
2735 $$ = ev->unprotect ();
2739 simple_chord_elements:
2741 if (!parser->lexer_->is_chord_state ())
2742 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2745 | figure_spec optional_notemode_duration {
2746 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2748 unsmob_music (scm_car (s))->set_property ("duration", $2);
2765 | lyric_element multiplied_duration post_events {
2766 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2767 if (scm_is_pair ($3))
2768 unsmob_music ($$)->set_property
2769 ("articulations", scm_reverse_x ($3, SCM_EOL));
2771 | lyric_element post_event post_events {
2772 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2773 parser->default_duration_.smobbed_copy ());
2774 unsmob_music ($$)->set_property
2775 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2777 | LYRIC_ELEMENT optional_notemode_duration post_events {
2778 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2779 if (scm_is_pair ($3))
2780 unsmob_music ($$)->set_property
2781 ("articulations", scm_reverse_x ($3, SCM_EOL));
2786 lyric_element_music:
2787 lyric_element optional_notemode_duration post_events {
2788 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2789 if (scm_is_pair ($3))
2790 unsmob_music ($$)->set_property
2791 ("articulations", scm_reverse_x ($3, SCM_EOL));
2796 steno_tonic_pitch optional_notemode_duration {
2797 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2799 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2800 SCM its = scm_reverse_x ($4, SCM_EOL);
2801 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2809 | chord_items chord_item {
2810 $$ = scm_cons ($2, $$);
2816 $$ = ly_symbol2scm ("chord-colon");
2819 $$ = ly_symbol2scm ("chord-caret");
2821 | CHORD_SLASH steno_tonic_pitch {
2822 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2824 | CHORD_BASS steno_tonic_pitch {
2825 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2834 $$ = scm_reverse_x ($1, SCM_EOL);
2842 step_number { $$ = scm_cons ($1, SCM_EOL); }
2843 | step_numbers '.' step_number {
2844 $$ = scm_cons ($3, $$);
2850 $$ = make_chord_step ($1, 0);
2853 $$ = make_chord_step ($1, SHARP_ALTERATION);
2855 | UNSIGNED CHORD_MINUS {
2856 $$ = make_chord_step ($1, FLAT_ALTERATION);
2864 | UNSIGNED '~' UNSIGNED {
2865 $$ = scm_cons ($1, $3);
2872 TODO: should deprecate in favor of Scheme?
2876 number_expression '+' number_term {
2877 $$ = scm_sum ($1, $3);
2879 | number_expression '-' number_term {
2880 $$ = scm_difference ($1, $3);
2889 | number_factor '*' number_factor {
2890 $$ = scm_product ($1, $3);
2892 | number_factor '/' number_factor {
2893 $$ = scm_divide ($1, $3);
2898 '-' number_factor { /* %prec UNARY_MINUS */
2899 $$ = scm_difference ($2, SCM_UNDEFINED);
2907 | UNSIGNED NUMBER_IDENTIFIER {
2908 $$ = scm_product ($1, $2);
2910 | REAL NUMBER_IDENTIFIER {
2911 $$ = scm_product ($1, $2);
2927 { $$ = SCM_UNDEFINED; }
2930 if (SCM_UNBNDP ($1))
2938 { $$ = SCM_UNDEFINED; }
2941 if (SCM_UNBNDP ($1))
2949 This should be done more dynamically if possible.
2954 { parser->lexer_->push_markup_state (); }
2957 parser->lexer_->pop_state ();
2963 { parser->lexer_->push_markup_state (); }
2966 parser->lexer_->pop_state ();
2972 { parser->lexer_->push_markup_state (); }
2975 parser->lexer_->pop_state ();
2981 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2983 | markup_head_1_list simple_markup {
2984 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2994 if (Text_interface::is_markup ($1))
2995 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
2996 else if (Text_interface::is_markup_list ($1))
2997 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
2999 parser->parser_error (@1, _ ("not a markup"));
3000 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3007 markup_composed_list {
3010 | markup_braced_list {
3013 | markup_command_list {
3014 $$ = scm_list_1 ($1);
3016 | markup_scm MARKUPLIST_IDENTIFIER
3022 markup_composed_list:
3023 markup_head_1_list markup_braced_list {
3024 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3030 '{' markup_braced_list_body '}' {
3031 $$ = scm_reverse_x ($2, SCM_EOL);
3035 markup_braced_list_body:
3036 /* empty */ { $$ = SCM_EOL; }
3037 | markup_braced_list_body markup {
3038 $$ = scm_cons ($2, $1);
3040 | markup_braced_list_body markup_list {
3041 $$ = scm_reverse_x ($2, $1);
3045 markup_command_list:
3046 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3047 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3051 markup_command_basic_arguments:
3052 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3053 $$ = scm_cons ($3, $2);
3055 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3056 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3058 | EXPECT_NO_MORE_ARGS {
3063 markup_command_list_arguments:
3064 markup_command_basic_arguments { $$ = $1; }
3065 | EXPECT_MARKUP markup_command_list_arguments markup {
3066 $$ = scm_cons ($3, $2);
3071 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3072 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3077 markup_head_1_item {
3078 $$ = scm_list_1 ($1);
3080 | markup_head_1_list markup_head_1_item {
3081 $$ = scm_cons ($2, $1);
3087 $$ = make_simple_markup ($1);
3090 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3091 parser->lexer_->push_note_state (nn);
3092 } '{' score_body '}' {
3093 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3094 parser->lexer_->pop_state ();
3096 | MARKUP_FUNCTION markup_command_basic_arguments {
3097 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3099 | markup_scm MARKUP_IDENTIFIER
3106 markup_head_1_list simple_markup {
3107 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3108 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3118 Lily_parser::set_yydebug (bool x)
3124 Lily_parser::do_yyparse ()
3126 SCM retval = SCM_UNDEFINED;
3127 yyparse (this, &retval);
3137 It is a little strange to have this function in this file, but
3138 otherwise, we have to import music classes into the lexer.
3142 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3144 if (unsmob_book (sid)) {
3145 Book *book = unsmob_book (sid)->clone ();
3146 *destination = book->self_scm ();
3149 return BOOK_IDENTIFIER;
3150 } else if (scm_is_number (sid)) {
3152 return NUMBER_IDENTIFIER;
3153 } else if (unsmob_context_def (sid)) {
3154 Context_def *def= unsmob_context_def (sid)->clone ();
3156 *destination = def->self_scm ();
3159 return CONTEXT_DEF_IDENTIFIER;
3160 } else if (unsmob_context_mod (sid)) {
3161 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3163 return CONTEXT_MOD_IDENTIFIER;
3164 } else if (unsmob_score (sid)) {
3165 Score *score = new Score (*unsmob_score (sid));
3166 *destination = score->self_scm ();
3168 score->unprotect ();
3169 return SCORE_IDENTIFIER;
3170 } else if (Music *mus = unsmob_music (sid)) {
3171 mus = mus->clone ();
3172 *destination = mus->self_scm ();
3173 unsmob_music (*destination)->
3174 set_property ("origin", make_input (last_input_));
3176 bool is_event = mus->is_mus_type ("post-event");
3178 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3179 } else if (unsmob_pitch (sid)) {
3180 *destination = unsmob_pitch (sid)->smobbed_copy ();
3181 return PITCH_IDENTIFIER;
3182 } else if (unsmob_duration (sid)) {
3183 *destination = unsmob_duration (sid)->smobbed_copy ();
3184 return DURATION_IDENTIFIER;
3185 } else if (unsmob_output_def (sid)) {
3186 Output_def *p = unsmob_output_def (sid);
3189 *destination = p->self_scm ();
3191 return OUTPUT_DEF_IDENTIFIER;
3198 get_next_unique_context_id ()
3200 return scm_from_locale_string ("$uniqueContextId");
3205 get_next_unique_lyrics_context_id ()
3207 static int new_context_count;
3209 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3210 return scm_from_locale_string (s);
3213 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3214 SCM arg, SCM args, SCM pred)
3216 args = scm_cons (arg, args);
3217 if (scm_is_true (scm_call_1 (pred, arg)))
3219 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3220 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3221 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3225 SCM loc_on_music (Input loc, SCM arg)
3227 if (Music *m = unsmob_music (arg))
3231 return m->unprotect ();
3237 is_regular_identifier (SCM id)
3239 string str = ly_scm2string (id);
3241 bool middle = false;
3243 for (string::iterator it=str.begin(); it != str.end (); it++)
3246 if ((c >= 'a' && c <= 'z')
3247 || (c >= 'A' && c <= 'Z')
3250 else if (middle && (c == '-' || c == '_'))
3259 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3261 if (unsmob_music (simple))
3263 if (parser->lexer_->is_note_state ()) {
3264 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3265 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3266 if (scm_is_symbol (simple))
3267 n->set_property ("drum-type", simple);
3268 else if (unsmob_pitch (simple))
3269 n->set_property ("pitch", simple);
3274 return n->unprotect ();
3275 } else if (parser->lexer_->is_lyric_state ()) {
3276 if (Text_interface::is_markup (simple))
3277 return MAKE_SYNTAX ("lyric-event", loc, simple,
3278 parser->default_duration_.smobbed_copy ());
3279 } else if (parser->lexer_->is_chord_state ()) {
3280 if (unsmob_pitch (simple))
3281 return make_chord_elements (loc, simple,
3282 parser->default_duration_.smobbed_copy (),
3289 make_music_with_input (SCM name, Input where)
3291 Music *m = make_music_by_name (name);
3292 m->set_spot (where);
3297 make_simple_markup (SCM a)
3305 return t && t == 1 << intlog2 (t);
3309 make_chord_step (SCM step_scm, Rational alter)
3311 int step = scm_to_int (step_scm);
3314 alter += FLAT_ALTERATION;
3318 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3319 return m.smobbed_copy ();
3324 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3326 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3327 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3328 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3330 unsmob_music (scm_car (s))->set_spot (loc);
3336 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3338 Lily_lexer *lex = parser->lexer_;
3342 lex->prepare_for_next_token ();
3343 return lex->yylex ();