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 %right ':' UNSIGNED REAL E_UNSIGNED EVENT_IDENTIFIER EVENT_FUNCTION '^' '_'
84 HYPHEN EXTENDER DURATION_IDENTIFIER '!'
86 /* The above are needed for collecting tremoli and other items (that
87 could otherwise be interpreted as belonging to the next function
88 argument) greedily, and together with the next rule will serve to
89 join numbers and units greedily instead of allowing them into
90 separate function arguments
93 %nonassoc NUMBER_IDENTIFIER
105 %{ // -*-Fundamental-*-
110 * The rules for who is protecting what are very shady. Uniformise
113 * There are too many lexical modes?
124 #include "context-def.hh"
125 #include "context-mod.hh"
126 #include "dimensions.hh"
127 #include "file-path.hh"
129 #include "international.hh"
130 #include "lily-guile.hh"
131 #include "lily-lexer.hh"
132 #include "lily-parser.hh"
136 #include "output-def.hh"
137 #include "paper-book.hh"
138 #include "scm-hash.hh"
140 #include "text-interface.hh"
144 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
146 parser->parser_error (*i, s);
149 // The following are somewhat precarious constructs as they may change
150 // the value of the lookahead token. That implies that the lookahead
151 // token must not yet have made an impact on the state stack other
152 // than causing the reduction of the current rule, or switching the
153 // lookahead token while Bison is mulling it over will cause trouble.
155 #define MYBACKUP(Token, Value, Location) \
157 if (yychar != YYEMPTY) \
158 parser->lexer_->push_extra_token \
159 (yylloc, yychar, yylval); \
161 parser->lexer_->push_extra_token \
162 (Location, Token, Value); \
163 parser->lexer_->push_extra_token (Location, BACKUP); \
168 #define MYREPARSE(Location, Pred, Token, Value) \
170 if (yychar != YYEMPTY) \
171 parser->lexer_->push_extra_token \
172 (yylloc, yychar, yylval); \
173 parser->lexer_->push_extra_token \
174 (Location, Token, Value); \
175 parser->lexer_->push_extra_token \
176 (Location, REPARSE, Pred); \
185 #define MY_MAKE_MUSIC(x, spot) \
186 make_music_with_input (ly_symbol2scm (x), \
187 parser->lexer_->override_input (spot))
190 - Don't use lily module, create a new module instead.
191 - delay application of the function
193 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
194 scm_apply_0 (proc, args)
195 /* Syntactic Sugar. */
196 #define MAKE_SYNTAX(name, location, ...) \
197 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (parser->lexer_->override_input (location)), ##__VA_ARGS__, SCM_UNDEFINED))
198 #define START_MAKE_SYNTAX(name, ...) \
199 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
200 #define FINISH_MAKE_SYNTAX(start, location, ...) \
201 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (parser->lexer_->override_input (location)), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
203 SCM get_next_unique_context_id ();
204 SCM get_next_unique_lyrics_context_id ();
211 #define _(x) gettext (x)
215 static Music *make_music_with_input (SCM name, Input where);
216 SCM check_scheme_arg (Lily_parser *parser, Input loc,
217 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
218 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
219 SCM loc_on_music (Input loc, SCM arg);
220 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
221 SCM make_chord_step (SCM step, Rational alter);
222 SCM make_simple_markup (SCM a);
223 SCM make_duration (SCM t, int dots = 0);
224 bool is_regular_identifier (SCM id, bool multiple=false);
225 SCM try_string_variants (SCM pred, SCM str);
226 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
230 /* The third option is an alias that will be used to display the
231 syntax error. Bison CVS now correctly handles backslash escapes.
233 FIXME: Bison needs to translate some of these, eg, STRING.
237 /* Keyword tokens with plain escaped name. */
238 %token END_OF_FILE 0 "end of input"
239 %token ACCEPTS "\\accepts"
240 %token ADDLYRICS "\\addlyrics"
241 %token ALIAS "\\alias"
242 %token ALTERNATIVE "\\alternative"
244 %token BOOKPART "\\bookpart"
245 %token CHANGE "\\change"
246 %token CHORDMODE "\\chordmode"
247 %token CHORDS "\\chords"
248 %token CONSISTS "\\consists"
249 %token CONTEXT "\\context"
250 %token DEFAULT "\\default"
251 %token DEFAULTCHILD "\\defaultchild"
252 %token DENIES "\\denies"
253 %token DESCRIPTION "\\description"
254 %token DRUMMODE "\\drummode"
255 %token DRUMS "\\drums"
256 %token FIGUREMODE "\\figuremode"
257 %token FIGURES "\\figures"
258 %token HEADER "\\header"
259 %token INVALID "\\version-error"
260 %token LAYOUT "\\layout"
261 %token LYRICMODE "\\lyricmode"
262 %token LYRICS "\\lyrics"
263 %token LYRICSTO "\\lyricsto"
264 %token MARKUP "\\markup"
265 %token MARKUPLIST "\\markuplist"
268 %token NOTEMODE "\\notemode"
269 %token OVERRIDE "\\override"
270 %token PAPER "\\paper"
271 %token REMOVE "\\remove"
272 %token REPEAT "\\repeat"
274 %token REVERT "\\revert"
275 %token SCORE "\\score"
276 %token SCORELINES "\\score-lines"
277 %token SEQUENTIAL "\\sequential"
279 %token SIMULTANEOUS "\\simultaneous"
280 %token TEMPO "\\tempo"
282 %token UNSET "\\unset"
285 /* Keyword token exceptions. */
286 %token NEWCONTEXT "\\new"
289 /* Other string tokens. */
291 %token CHORD_BASS "/+"
292 %token CHORD_CARET "^"
293 %token CHORD_COLON ":"
294 %token CHORD_MINUS "-"
295 %token CHORD_SLASH "/"
296 %token ANGLE_OPEN "<"
297 %token ANGLE_CLOSE ">"
298 %token DOUBLE_ANGLE_OPEN "<<"
299 %token DOUBLE_ANGLE_CLOSE ">>"
300 %token E_BACKSLASH "\\"
301 %token E_EXCLAMATION "\\!"
306 If we give names, Bison complains.
308 %token FIGURE_CLOSE /* "\\>" */
309 %token FIGURE_OPEN /* "\\<" */
310 %token FIGURE_SPACE "_"
313 %token MULTI_MEASURE_REST
319 /* Artificial tokens, for more generic function syntax */
320 %token EXPECT_MARKUP "markup?"
321 %token EXPECT_SCM "scheme?"
322 %token BACKUP "(backed-up?)"
323 %token REPARSE "(reparsed?)"
324 %token EXPECT_MARKUP_LIST "markup-list?"
325 %token EXPECT_OPTIONAL "optional?"
326 /* After the last argument. */
327 %token EXPECT_NO_MORE_ARGS;
329 /* An artificial token for parsing embedded Lilypond */
330 %token EMBEDDED_LILY "#{"
332 %token BOOK_IDENTIFIER
333 %token CHORD_MODIFIER
334 %token CHORD_REPETITION
335 %token CONTEXT_DEF_IDENTIFIER
336 %token CONTEXT_MOD_IDENTIFIER
338 %token PITCH_IDENTIFIER
339 %token DURATION_IDENTIFIER
340 %token EVENT_IDENTIFIER
341 %token EVENT_FUNCTION
344 %token MARKUP_FUNCTION
345 %token MARKUP_LIST_FUNCTION
346 %token MARKUP_IDENTIFIER
347 %token MARKUPLIST_IDENTIFIER
348 %token MUSIC_FUNCTION
349 %token MUSIC_IDENTIFIER
350 %token NOTENAME_PITCH
351 %token NUMBER_IDENTIFIER
352 %token OUTPUT_DEF_IDENTIFIER
357 %token SCM_IDENTIFIER
361 %token TONICNAME_PITCH
365 /* We don't assign precedence to / and *, because we might need varied
366 prec levels in different prods */
375 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
376 parser->lexer_->push_note_state (nn);
377 } embedded_lilypond {
378 parser->lexer_->pop_state ();
383 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
384 | lilypond toplevel_expression {
386 | lilypond assignment {
389 parser->error_level_ = 1;
392 parser->error_level_ = 1;
399 parser->lexer_->add_scope (get_header (parser));
401 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
404 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
405 scm_call_2 (proc, parser->self_scm (), $1);
408 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
409 scm_call_2 (proc, parser->self_scm (), $1);
412 SCM proc = parser->lexer_->lookup_identifier
413 (unsmob_book($1)->paper_
414 ? "toplevel-book-handler"
415 : "toplevel-bookpart-handler");
416 scm_call_2 (proc, parser->self_scm (), $1);
419 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
420 scm_call_2 (proc, parser->self_scm (), $1);
423 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
424 scm_call_2 (proc, parser->self_scm (), $1);
427 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
428 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
431 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
432 scm_call_2 (proc, parser->self_scm (), $1);
435 // Evaluate and ignore #xxx, as opposed to \xxx
436 parser->lexer_->eval_scm_token ($1);
438 | embedded_scm_active
440 SCM out = SCM_UNDEFINED;
441 if (Text_interface::is_markup ($1))
442 out = scm_list_1 ($1);
443 else if (Text_interface::is_markup_list ($1))
445 if (scm_is_pair (out))
447 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
448 scm_call_2 (proc, parser->self_scm (), out);
449 } else if (unsmob_score ($1))
451 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
452 scm_call_2 (proc, parser->self_scm (), $1);
453 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
454 parser->parser_error (@1, _("bad expression type"));
458 Output_def * od = unsmob_output_def ($1);
460 if (od->c_variable ("is-paper") == SCM_BOOL_T)
461 id = ly_symbol2scm ("$defaultpaper");
462 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
463 id = ly_symbol2scm ("$defaultmidi");
464 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
465 id = ly_symbol2scm ("$defaultlayout");
467 parser->lexer_->set_identifier (id, $1);
474 $$ = parser->lexer_->eval_scm_token ($1);
484 embedded_scm_bare_arg:
488 $$ = parser->lexer_->eval_scm_token ($1);
492 | context_modification
494 | context_def_spec_block
500 /* The generic version may end in music, or not */
507 /* embedded_scm_arg is _not_ casting pitches to music by default, this
508 * has to be done by the function itself. Note that this may cause
509 * the results of scm_function_call or embedded_scm_bare_arg to be
510 * turned into music from pitches as well. Note that this creates a
511 * distinctly awkward situation for calculated drum pitches. Those
512 * are at the current point of time rejected as music constituents as
513 * they can't be distinguished from "proper" symbols.
517 embedded_scm_bare_arg
523 SCM_FUNCTION function_arglist {
524 $$ = MAKE_SYNTAX ("music-function", @$,
529 embedded_lilypond_number:
530 '-' embedded_lilypond_number
532 $$ = scm_difference ($2, SCM_UNDEFINED);
535 | UNSIGNED NUMBER_IDENTIFIER
537 $$ = scm_product ($1, $2);
544 // FIXME: @$ does not contain a useful source location
545 // for empty rules, and the only token in the whole
546 // production, EMBEDDED_LILY, is synthetic and also
547 // contains no source location.
548 $$ = MAKE_SYNTAX ("void-music", @$);
550 | identifier_init_nonumber
551 | embedded_lilypond_number
552 | post_event post_events
554 $$ = scm_reverse_x ($2, SCM_EOL);
555 if (Music *m = unsmob_music ($1))
557 if (m->is_mus_type ("post-event-wrapper"))
559 (scm_list_2 (m->get_property ("elements"),
562 $$ = scm_cons ($1, $$);
565 && scm_is_null (scm_cdr ($$)))
569 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
570 m->set_property ("elements", $$);
571 $$ = m->unprotect ();
574 | multiplied_duration
575 | music_embedded music_embedded music_list {
576 $3 = scm_reverse_x ($3, SCM_EOL);
577 if (unsmob_music ($2))
578 $3 = scm_cons ($2, $3);
579 if (unsmob_music ($1))
580 $3 = scm_cons ($1, $3);
581 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
584 parser->error_level_ = 1;
585 $$ = SCM_UNSPECIFIED;
587 | INVALID embedded_lilypond {
588 parser->error_level_ = 1;
594 lilypond_header_body:
595 /* empty */ { $$ = SCM_UNSPECIFIED; }
596 | lilypond_header_body assignment {
599 | lilypond_header_body embedded_scm {
605 HEADER '{' lilypond_header_body '}' {
606 $$ = parser->lexer_->remove_scope ();
618 assignment_id '=' identifier_init {
619 parser->lexer_->set_identifier ($1, $3);
620 $$ = SCM_UNSPECIFIED;
622 | assignment_id property_path '=' identifier_init {
623 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
624 parser->lexer_->set_identifier (path, $4);
625 $$ = SCM_UNSPECIFIED;
631 identifier_init_nonumber
633 | post_event_nofinger post_events
635 $$ = scm_reverse_x ($2, SCM_EOL);
636 if (Music *m = unsmob_music ($1))
638 if (m->is_mus_type ("post-event-wrapper"))
640 (scm_list_2 (m->get_property ("elements"),
643 $$ = scm_cons ($1, $$);
646 && scm_is_null (scm_cdr ($$)))
650 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
651 m->set_property ("elements", $$);
652 $$ = m->unprotect ();
657 identifier_init_nonumber:
662 | context_def_spec_block
668 | context_modification
671 context_def_spec_block:
672 CONTEXT '{' context_def_spec_body '}'
675 unsmob_context_def ($$)->origin ()->set_spot (@$);
683 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
684 parser->lexer_->push_note_state (nn);
688 parser->lexer_->pop_state ();
693 context_mod_embedded:
696 if (unsmob_music ($1)) {
697 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
698 $1 = scm_call_2 (proc, parser->self_scm (), $1);
700 if (unsmob_context_mod ($1))
703 parser->parser_error (@1, _ ("not a context mod"));
704 $$ = Context_mod ().smobbed_copy ();
710 context_def_spec_body:
712 $$ = Context_def::make_scm ();
714 | CONTEXT_DEF_IDENTIFIER {
717 | context_def_spec_body context_mod {
718 if (!SCM_UNBNDP ($2))
719 unsmob_context_def ($$)->add_context_mod ($2);
721 | context_def_spec_body context_modification {
722 Context_def *td = unsmob_context_def ($$);
723 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
724 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
725 td->add_context_mod (scm_car (m));
728 | context_def_spec_body context_mod_embedded {
729 Context_def *td = unsmob_context_def ($$);
730 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
731 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
732 td->add_context_mod (scm_car (m));
740 BOOK '{' book_body '}' {
742 unsmob_book ($$)->origin ()->set_spot (@$);
744 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
749 * Use 'handlers' like for toplevel-* stuff?
750 * grok \layout and \midi? */
753 Book *book = new Book;
754 init_papers (parser);
755 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
756 book->paper_->unprotect ();
757 push_paper (parser, book->paper_);
758 book->header_ = get_header (parser);
759 $$ = book->unprotect ();
760 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
763 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
765 | book_body paper_block {
766 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
767 set_paper (parser, unsmob_output_def ($2));
769 | book_body bookpart_block {
770 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
771 scm_call_2 (proc, $1, $2);
773 | book_body score_block {
774 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
775 scm_call_2 (proc, $1, $2);
777 | book_body composite_music {
778 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
779 scm_call_3 (proc, parser->self_scm (), $1, $2);
781 | book_body full_markup {
782 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
783 scm_call_2 (proc, $1, scm_list_1 ($2));
785 | book_body full_markup_list {
786 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
787 scm_call_2 (proc, $1, $2);
789 | book_body SCM_TOKEN {
790 // Evaluate and ignore #xxx, as opposed to \xxx
791 parser->lexer_->eval_scm_token ($2);
793 | book_body embedded_scm_active
795 SCM out = SCM_UNDEFINED;
796 if (Text_interface::is_markup ($2))
797 out = scm_list_1 ($2);
798 else if (Text_interface::is_markup_list ($2))
800 if (scm_is_pair (out))
802 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
803 scm_call_2 (proc, $1, out);
804 } else if (unsmob_score ($2))
806 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
807 scm_call_2 (proc, $1, $2);
808 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
809 parser->parser_error (@2, _("bad expression type"));
813 parser->lexer_->add_scope (unsmob_book ($1)->header_);
816 Book *book = unsmob_book ($1);
818 book->scores_ = SCM_EOL;
819 book->bookparts_ = SCM_EOL;
824 BOOKPART '{' bookpart_body '}' {
826 unsmob_book ($$)->origin ()->set_spot (@$);
827 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
833 Book *book = new Book;
834 $$ = book->unprotect ();
835 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
838 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
840 | bookpart_body paper_block {
841 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
843 | bookpart_body score_block {
844 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
845 scm_call_2 (proc, $1, $2);
847 | bookpart_body composite_music {
848 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
849 scm_call_3 (proc, parser->self_scm (), $1, $2);
851 | bookpart_body full_markup {
852 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
853 scm_call_2 (proc, $1, scm_list_1 ($2));
855 | bookpart_body full_markup_list {
856 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
857 scm_call_2 (proc, $1, $2);
859 | bookpart_body SCM_TOKEN {
860 // Evaluate and ignore #xxx, as opposed to \xxx
861 parser->lexer_->eval_scm_token ($2);
863 | bookpart_body embedded_scm_active
865 SCM out = SCM_UNDEFINED;
866 if (Text_interface::is_markup ($2))
867 out = scm_list_1 ($2);
868 else if (Text_interface::is_markup_list ($2))
870 if (scm_is_pair (out))
872 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
873 scm_call_2 (proc, $1, out);
874 } else if (unsmob_score ($2))
876 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
877 scm_call_2 (proc, $1, $2);
878 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
879 parser->parser_error (@2, _("bad expression type"));
883 Book *book = unsmob_book ($1);
884 if (!ly_is_module (book->header_))
885 book->header_ = ly_make_module (false);
886 parser->lexer_->add_scope (book->header_);
888 | bookpart_body error {
889 Book *book = unsmob_book ($1);
891 book->scores_ = SCM_EOL;
896 SCORE '{' score_body '}' {
897 unsmob_score ($3)->origin ()->set_spot (@$);
909 if (!scm_is_pair ($1)
910 || !ly_is_module (scm_car ($1)))
911 $1 = scm_cons (ly_make_module (false), $1);
912 parser->lexer_->add_scope (scm_car ($1));
917 | score_headers output_def
919 Output_def *od = unsmob_output_def ($2);
920 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
922 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
927 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
928 scm_set_cdr_x ($1, scm_cons ($2, scm_cdr ($1)));
930 $$ = scm_cons ($2, $1);
938 score_headers music {
939 SCM scorify = ly_lily_module_constant ("scorify-music");
940 $$ = scm_call_2 (scorify, $2, parser->self_scm ());
942 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
944 unsmob_score ($$)->set_header (scm_car ($1));
947 for (SCM p = scm_reverse_x ($1, SCM_EOL);
948 scm_is_pair (p); p = scm_cdr (p))
951 add_output_def (unsmob_output_def (scm_car (p)));
954 | embedded_scm_active {
955 if (!unsmob_score ($1))
957 $$ = (new Score)->unprotect ();
958 parser->parser_error (@1, _("score expected"));
963 Score *score = unsmob_score ($1);
964 if (!ly_is_module (score->get_header ()))
965 score->set_header (ly_make_module (false));
966 parser->lexer_->add_scope (score->get_header ());
968 | score_body output_def {
969 Output_def *od = unsmob_output_def ($2);
970 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
972 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
977 unsmob_score ($1)->add_output_def (od);
981 unsmob_score ($$)->error_found_ = true;
992 Output_def *od = unsmob_output_def ($1);
994 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
996 parser->parser_error (@1, _ ("need \\paper for paper block"));
997 $$ = get_paper (parser)->unprotect ();
1004 output_def_body '}' {
1007 parser->lexer_->remove_scope ();
1008 parser->lexer_->pop_state ();
1014 Output_def *p = get_paper (parser);
1015 p->input_origin_ = @$;
1016 parser->lexer_->add_scope (p->scope_);
1017 $$ = p->unprotect ();
1020 Output_def *p = get_midi (parser);
1021 $$ = p->unprotect ();
1022 parser->lexer_->add_scope (p->scope_);
1025 Output_def *p = get_layout (parser);
1027 parser->lexer_->add_scope (p->scope_);
1028 $$ = p->unprotect ();
1032 output_def_head_with_mode_switch:
1034 parser->lexer_->push_initial_state ();
1039 // We need this weird nonterminal because both music as well as a
1040 // context definition can start with \context and the difference is
1041 // only apparent after looking at the next token. If it is '{', there
1042 // is still time to escape from notes mode.
1044 music_or_context_def:
1046 | context_def_spec_block
1050 output_def_head_with_mode_switch '{' {
1052 unsmob_output_def ($$)->input_origin_.set_spot (@$);
1054 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1055 Output_def *o = unsmob_output_def ($3);
1056 o->input_origin_.set_spot (@$);
1057 $$ = o->self_scm ();
1058 parser->lexer_->remove_scope ();
1059 parser->lexer_->add_scope (o->scope_);
1061 | output_def_body assignment {
1064 | output_def_body embedded_scm {
1069 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1070 parser->lexer_->push_note_state (nn);
1071 } music_or_context_def
1073 parser->lexer_->pop_state ();
1074 if (unsmob_context_def ($3))
1075 assign_context_def (unsmob_output_def ($1), $3);
1078 SCM proc = parser->lexer_->lookup_identifier
1079 ("output-def-music-handler");
1080 scm_call_3 (proc, parser->self_scm (),
1084 | output_def_body error {
1090 TEMPO steno_duration '=' tempo_range {
1091 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1093 | TEMPO scalar steno_duration '=' tempo_range {
1094 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1097 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1102 The representation of a list is reversed to have efficient append. */
1108 | music_list music_embedded {
1109 if (unsmob_music ($2))
1110 $$ = scm_cons ($2, $1);
1112 | music_list error {
1113 Music *m = MY_MAKE_MUSIC("Music", @$);
1115 m->set_property ("error-found", SCM_BOOL_T);
1116 $$ = scm_cons (m->self_scm (), $1);
1117 m->unprotect (); /* UGH */
1124 $$ = scm_reverse_x ($2, SCM_EOL);
1129 | lyric_element_music
1135 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1136 parser->parser_error (@1, _ ("unexpected post-event"));
1137 $$ = SCM_UNSPECIFIED;
1140 | music_embedded_backup
1144 | music_embedded_backup BACKUP lyric_element_music
1148 | multiplied_duration post_events
1150 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1152 parser->default_duration_ = *unsmob_duration ($1);
1153 n->set_property ("duration", $1);
1155 if (scm_is_pair ($2))
1156 n->set_property ("articulations",
1157 scm_reverse_x ($2, SCM_EOL));
1158 $$ = n->unprotect ();
1162 music_embedded_backup:
1165 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1167 else if (Music *m = unsmob_music ($1)) {
1168 if (m->is_mus_type ("post-event")) {
1169 parser->parser_error
1170 (@1, _ ("unexpected post-event"));
1171 $$ = SCM_UNSPECIFIED;
1174 } else if (parser->lexer_->is_lyric_state ()
1175 && Text_interface::is_markup ($1))
1176 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1178 @$.warning (_ ("Ignoring non-music expression"));
1187 $$ = make_music_from_simple (parser, @1, $1);
1188 if (!unsmob_music ($$))
1190 parser->parser_error (@1, _ ("music expected"));
1191 $$ = MAKE_SYNTAX ("void-music", @$);
1194 | composite_music %prec COMPOSITE
1199 | composite_music %prec COMPOSITE
1203 REPEAT simple_string unsigned_number music
1205 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1207 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1209 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1214 SEQUENTIAL braced_music_list {
1215 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1217 | braced_music_list {
1218 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1223 SIMULTANEOUS braced_music_list {
1224 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1226 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1227 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1233 | music_property_def
1237 context_modification:
1240 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1241 parser->lexer_->push_note_state (nn);
1242 } '{' context_mod_list '}'
1244 parser->lexer_->pop_state ();
1247 | WITH CONTEXT_MOD_IDENTIFIER
1251 | CONTEXT_MOD_IDENTIFIER
1255 | WITH context_modification_arg
1257 if (unsmob_music ($2)) {
1258 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1259 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1261 if (unsmob_context_mod ($2))
1264 parser->parser_error (@2, _ ("not a context mod"));
1265 $$ = Context_mod ().smobbed_copy ();
1270 context_modification_arg:
1275 optional_context_mod:
1279 | context_modification
1287 $$ = Context_mod ().smobbed_copy ();
1289 | context_mod_list context_mod {
1290 if (!SCM_UNBNDP ($2))
1291 unsmob_context_mod ($1)->add_context_mod ($2);
1293 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1294 Context_mod *md = unsmob_context_mod ($2);
1296 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1298 | context_mod_list context_mod_embedded {
1299 unsmob_context_mod ($1)->add_context_mods
1300 (unsmob_context_mod ($2)->get_mods ());
1312 | grouped_music_list
1316 simultaneous_music { $$ = $1; }
1317 | sequential_music { $$ = $1; }
1320 /* Function argument lists are arguably the most complex part in the
1321 * parser. They are pretty tricky to understand because of the way
1322 * they are processed, and because of optional arguments that can be
1323 * omitted. When there are several optional arguments in a row,
1324 * omitting one automatically omits all following arguments. Optional
1325 * arguments can only be omitted when either
1327 * a) the omission is explicitly started with \default
1328 * b) the omission is implicitly started by an argument not matching
1329 * its predicate, and there is a mandatory argument later that can
1330 * "catch" the argument that does not fit.
1332 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1333 * (corresponding to mandatory arguments and having a predicate
1334 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1335 * the semantic value of the EXPECT_OPTIONAL token is the default to
1336 * use when the optional argument is omitted, and EXPECT_SCM again has
1337 * the argument predicate as semantic value) in reverse order to the
1338 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1339 * processed inside-out while actual tokens are consumed.
1341 * This means that the argument list tokens determine the actions
1342 * taken as they arrive. The structure of the argument list is known
1343 * to the parser and stored in its parse stack when the first argument
1344 * is being parsed. What the parser does not know is which predicates
1345 * will match and whether or not \default will be appearing in the
1346 * argument list, and where.
1348 * Sequences of 0 or more optional arguments are scanned using either
1349 * function_arglist_backup or function_arglist_nonbackup. The first
1350 * is used when optional arguments are followed by at least one
1351 * mandatory argument: in that case optional arguments may be skipped
1352 * by either a false predicate (in which case the expression will be
1353 * pushed back as one or more tokens, preceded by a BACKUP token) or
1354 * by using \default.
1356 * If optional arguments are at the end of the argument list, they are
1357 * instead scanned using function_arglist_nonbackup: here the only
1358 * manner to enter into skipping of optional arguments is the use of
1361 * The argument list of a normal function call is parsed using
1362 * function_arglist. The part of an argument list before a mandatory
1363 * argument is parsed using function_arglist_optional.
1365 * The difference is that leading optional arguments are scanned using
1366 * function_arglist_nonbackup and function_arglist_backup,
1369 * Most other details are obvious in the rules themselves.
1375 | SYMBOL_LIST '.' symbol_list_rev
1377 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1383 | symbol_list_rev '.' symbol_list_part
1385 $$ = scm_append_x (scm_list_2 ($3, $1));
1389 // symbol_list_part delivers elements in reverse copy.
1394 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1395 $$ = try_string_variants (sym_l_p, $1);
1396 if (SCM_UNBNDP ($$)) {
1397 parser->parser_error (@1, _("not a symbol"));
1400 $$ = scm_reverse ($$);
1405 symbol_list_element:
1411 function_arglist_nonbackup:
1412 function_arglist_common
1413 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1415 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1417 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1419 SCM n = scm_difference ($5, SCM_UNDEFINED);
1420 if (scm_is_true (scm_call_1 ($2, n)))
1421 $$ = scm_cons (n, $3);
1423 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1424 t->set_property ("digit", $5);
1425 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1430 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1432 $$ = check_scheme_arg (parser, @4,
1433 scm_difference ($5, SCM_UNDEFINED),
1436 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1438 $$ = check_scheme_arg (parser, @4,
1439 scm_difference ($5, SCM_UNDEFINED),
1442 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1444 if (scm_is_true (scm_call_1 ($2, $4)))
1445 $$ = scm_cons ($4, $3);
1447 $$ = check_scheme_arg (parser, @4,
1448 make_music_from_simple
1452 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1454 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1456 | function_arglist_nonbackup_reparse REPARSE duration_length
1458 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1460 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1462 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1464 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1466 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1468 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1470 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1472 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1474 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1478 function_arglist_nonbackup_reparse:
1479 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1482 SCM res = try_string_variants ($2, $4);
1483 if (!SCM_UNBNDP (res))
1484 if (scm_is_pair (res))
1485 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1487 MYREPARSE (@4, $2, SCM_ARG, res);
1488 else if (scm_is_true
1490 ($2, make_music_from_simple
1492 MYREPARSE (@4, $2, STRING, $4);
1494 MYREPARSE (@4, $2, SCM_ARG, $4);
1496 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1499 SCM res = try_string_variants ($2, $4);
1500 if (!SCM_UNBNDP (res))
1501 if (scm_is_pair (res))
1502 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1504 MYREPARSE (@4, $2, SCM_ARG, res);
1505 else if (scm_is_true
1507 ($2, make_music_from_simple
1509 MYREPARSE (@4, $2, STRING, $4);
1511 MYREPARSE (@4, $2, SCM_ARG, $4);
1513 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1516 if (scm_is_true (scm_call_1 ($2, $4)))
1517 MYREPARSE (@4, $2, SCM_ARG, $4);
1518 else if (scm_is_true
1520 ($2, make_music_from_simple
1522 MYREPARSE (@4, $2, STRING, $4);
1524 MYREPARSE (@4, $2, SCM_ARG, $4);
1526 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1529 if (scm_is_true (scm_call_1 ($2, $4)))
1530 MYREPARSE (@4, $2, REAL, $4);
1532 SCM d = make_duration ($4);
1533 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1534 MYREPARSE (@4, $2, REAL, $4); // trigger error
1536 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1539 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1541 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1546 // function_arglist_backup can't occur at the end of an argument
1548 function_arglist_backup:
1549 function_arglist_common
1550 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1552 if (scm_is_true (scm_call_1 ($2, $4)))
1553 $$ = scm_cons ($4, $3);
1555 $$ = make_music_from_simple (parser, @4, $4);
1556 if (scm_is_true (scm_call_1 ($2, $$)))
1557 $$ = scm_cons ($$, $3);
1560 $$ = scm_cons (loc_on_music (@3, $1), $3);
1561 MYBACKUP (SCM_ARG, $4, @4);
1565 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1567 if (scm_is_true (scm_call_1 ($2, $4)))
1569 $$ = scm_cons ($4, $3);
1571 $$ = scm_cons (loc_on_music (@3, $1), $3);
1572 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1575 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1577 if (scm_is_true (scm_call_1 ($2, $4)))
1578 $$ = scm_cons ($4, $3);
1580 $$ = scm_cons (loc_on_music (@3, $1), $3);
1581 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1584 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1586 if (scm_is_true (scm_call_1 ($2, $4)))
1588 MYREPARSE (@4, $2, REAL, $4);
1591 SCM d = make_duration ($4);
1592 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1594 $$ = scm_cons (loc_on_music (@3, $1), $3);
1595 MYBACKUP (UNSIGNED, $4, @4);
1597 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1602 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1604 if (scm_is_true (scm_call_1 ($2, $4)))
1607 MYREPARSE (@4, $2, REAL, $4);
1609 $$ = scm_cons (loc_on_music (@3, $1), $3);
1610 MYBACKUP (REAL, $4, @4);
1613 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1615 if (scm_is_true (scm_call_1 ($2, $4)))
1617 $$ = scm_cons ($4, $3);
1619 $$ = scm_cons (loc_on_music (@3, $1), $3);
1620 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1623 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1625 SCM n = scm_difference ($5, SCM_UNDEFINED);
1626 if (scm_is_true (scm_call_1 ($2, n))) {
1628 MYREPARSE (@5, $2, REAL, n);
1630 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1631 t->set_property ("digit", $5);
1632 $$ = t->unprotect ();
1633 if (scm_is_true (scm_call_1 ($2, $$)))
1634 $$ = scm_cons ($$, $3);
1636 $$ = scm_cons (loc_on_music (@3, $1), $3);
1637 MYBACKUP (UNSIGNED, $5, @5);
1638 parser->lexer_->push_extra_token (@4, '-');
1643 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1645 SCM n = scm_difference ($5, SCM_UNDEFINED);
1646 if (scm_is_true (scm_call_1 ($2, n))) {
1647 MYREPARSE (@5, $2, REAL, n);
1650 $$ = scm_cons (loc_on_music (@3, $1), $3);
1651 MYBACKUP (REAL, n, @5);
1654 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1656 SCM n = scm_difference ($5, SCM_UNDEFINED);
1657 if (scm_is_true (scm_call_1 ($2, n))) {
1658 $$ = scm_cons (n, $3);
1660 $$ = scm_cons (loc_on_music (@3, $1), $3);
1661 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1664 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1666 if (scm_is_true (scm_call_1 ($2, $4)))
1668 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1671 $$ = scm_cons (loc_on_music (@3, $1), $3);
1672 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1675 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1677 SCM res = try_string_variants ($2, $4);
1678 if (!SCM_UNBNDP (res))
1679 if (scm_is_pair (res)) {
1681 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1684 $$ = scm_cons (res, $3);
1686 $$ = scm_cons (loc_on_music (@3, $1), $3);
1687 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1690 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1692 SCM res = try_string_variants ($2, $4);
1693 if (!SCM_UNBNDP (res))
1694 if (scm_is_pair (res)) {
1696 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1699 $$ = scm_cons (res, $3);
1701 $$ = scm_cons (loc_on_music (@3, $1), $3);
1702 MYBACKUP (STRING, $4, @4);
1705 | function_arglist_backup REPARSE music_assign
1707 if (scm_is_true (scm_call_1 ($2, $3)))
1708 $$ = scm_cons ($3, $1);
1710 $$ = check_scheme_arg (parser, @3,
1711 make_music_from_simple
1715 | function_arglist_backup REPARSE bare_number_common
1717 $$ = check_scheme_arg (parser, @3,
1720 | function_arglist_backup REPARSE duration_length
1722 $$ = check_scheme_arg (parser, @3,
1725 | function_arglist_backup REPARSE symbol_list_arg
1727 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1732 function_arglist_nonbackup
1733 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1735 $$ = scm_cons (loc_on_music (@4, $1), $3);
1739 function_arglist_skip_nonbackup:
1740 function_arglist_nonbackup
1741 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1743 $$ = scm_cons (loc_on_music (@3, $1), $3);
1747 function_arglist_common:
1748 EXPECT_NO_MORE_ARGS {
1751 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1753 if (scm_is_true (scm_call_1 ($1, $3)))
1754 $$ = scm_cons ($3, $2);
1756 $$ = check_scheme_arg (parser, @3,
1757 make_music_from_simple
1761 | EXPECT_SCM function_arglist_optional bare_number_common
1763 $$ = check_scheme_arg (parser, @3,
1766 | EXPECT_SCM function_arglist_optional post_event_nofinger
1768 $$ = check_scheme_arg (parser, @3,
1771 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1773 SCM n = scm_difference ($4, SCM_UNDEFINED);
1774 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1776 | function_arglist_common_reparse REPARSE SCM_ARG
1778 $$ = check_scheme_arg (parser, @3,
1781 | function_arglist_common_reparse REPARSE lyric_element_music
1783 $$ = check_scheme_arg (parser, @3,
1786 | function_arglist_common_reparse REPARSE bare_number_common
1788 $$ = check_scheme_arg (parser, @3,
1791 | function_arglist_common_reparse REPARSE duration_length
1793 $$ = check_scheme_arg (parser, @3,
1796 | function_arglist_common_reparse REPARSE symbol_list_arg
1798 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1802 function_arglist_common_reparse:
1803 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1806 SCM res = try_string_variants ($1, $3);
1807 if (!SCM_UNBNDP (res))
1808 if (scm_is_pair (res))
1809 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1811 MYREPARSE (@3, $1, SCM_ARG, res);
1812 else if (scm_is_true
1814 ($1, make_music_from_simple (parser, @3, $3))))
1815 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1817 // This is going to flag a syntax error, we
1818 // know the predicate to be false.
1819 MYREPARSE (@3, $1, SCM_ARG, $3);
1821 | EXPECT_SCM function_arglist_optional STRING
1824 SCM res = try_string_variants ($1, $3);
1825 if (!SCM_UNBNDP (res))
1826 if (scm_is_pair (res))
1827 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1829 MYREPARSE (@3, $1, SCM_ARG, res);
1830 else if (scm_is_true
1832 ($1, make_music_from_simple (parser, @3, $3))))
1833 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1835 // This is going to flag a syntax error, we
1836 // know the predicate to be false.
1837 MYREPARSE (@3, $1, SCM_ARG, $3);
1839 | EXPECT_SCM function_arglist_optional full_markup
1842 if (scm_is_true (scm_call_1 ($1, $3)))
1843 MYREPARSE (@3, $1, SCM_ARG, $3);
1844 else if (scm_is_true
1846 ($1, make_music_from_simple (parser, @3, $3))))
1847 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1849 // This is going to flag a syntax error, we
1850 // know the predicate to be false.
1851 MYREPARSE (@3, $1, SCM_ARG, $3);
1853 | EXPECT_SCM function_arglist_optional UNSIGNED
1856 if (scm_is_true (scm_call_1 ($1, $3)))
1857 MYREPARSE (@3, $1, REAL, $3);
1859 SCM d = make_duration ($3);
1860 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
1861 MYREPARSE (@3, $1, REAL, $3);
1863 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
1866 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
1869 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
1871 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
1874 SCM n = scm_difference ($4, SCM_UNDEFINED);
1875 if (scm_is_true (scm_call_1 ($1, n)))
1876 MYREPARSE (@4, $1, REAL, n);
1878 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1879 t->set_property ("digit", $4);
1880 SCM m = t->unprotect ();
1881 if (scm_is_true (scm_call_1 ($1, m)))
1882 MYREPARSE (@4, $1, SCM_ARG, m);
1884 MYREPARSE (@4, $1, SCM_ARG, $4);
1888 | EXPECT_SCM function_arglist_optional '-' REAL
1891 SCM n = scm_difference ($4, SCM_UNDEFINED);
1892 MYREPARSE (@4, $1, REAL, n);
1896 function_arglist_optional:
1897 function_arglist_backup
1898 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
1900 $$ = scm_cons (loc_on_music (@4, $1), $3);
1902 | function_arglist_skip_backup BACKUP
1905 function_arglist_skip_backup:
1906 function_arglist_backup
1907 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
1909 $$ = scm_cons (loc_on_music (@3, $1), $3);
1913 music_function_call:
1914 MUSIC_FUNCTION function_arglist {
1915 $$ = MAKE_SYNTAX ("music-function", @$,
1922 /**/ { $$ = SCM_EOL; }
1923 | '=' simple_string {
1930 | repeated_music { $$ = $1; }
1931 | re_rhythmed_music { $$ = $1; }
1932 | complex_music_prefix music
1934 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1938 complex_music_prefix:
1939 CONTEXT symbol optional_id optional_context_mod {
1940 Context_mod *ctxmod = unsmob_context_mod ($4);
1943 mods = ctxmod->get_mods ();
1944 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1946 | NEWCONTEXT symbol optional_id optional_context_mod {
1947 Context_mod *ctxmod = unsmob_context_mod ($4);
1950 mods = ctxmod->get_mods ();
1951 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1956 mode_changing_head grouped_music_list {
1957 if ($1 == ly_symbol2scm ("chords"))
1959 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1965 parser->lexer_->pop_state ();
1967 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1968 Context_mod *ctxmod = unsmob_context_mod ($2);
1971 mods = ctxmod->get_mods ();
1972 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1973 if ($1 == ly_symbol2scm ("ChordNames"))
1975 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1977 parser->lexer_->pop_state ();
1983 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1984 parser->lexer_->push_note_state (nn);
1986 $$ = ly_symbol2scm ("notes");
1990 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1991 parser->lexer_->push_note_state (nn);
1993 $$ = ly_symbol2scm ("drums");
1996 parser->lexer_->push_figuredbass_state ();
1998 $$ = ly_symbol2scm ("figures");
2001 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2002 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2003 nn = parser->lexer_->lookup_identifier ("pitchnames");
2004 parser->lexer_->push_chord_state (nn);
2005 $$ = ly_symbol2scm ("chords");
2009 { parser->lexer_->push_lyric_state ();
2010 $$ = ly_symbol2scm ("lyrics");
2014 mode_changing_head_with_context:
2016 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2017 parser->lexer_->push_note_state (nn);
2019 $$ = ly_symbol2scm ("DrumStaff");
2022 parser->lexer_->push_figuredbass_state ();
2024 $$ = ly_symbol2scm ("FiguredBass");
2027 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2028 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2029 nn = parser->lexer_->lookup_identifier ("pitchnames");
2030 parser->lexer_->push_chord_state (nn);
2031 $$ = ly_symbol2scm ("ChordNames");
2034 { parser->lexer_->push_lyric_state ();
2035 $$ = ly_symbol2scm ("Lyrics");
2040 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2043 /* Can also use music at the expensive of two S/Rs similar to
2044 \repeat \alternative */
2045 parser->lexer_->pop_state ();
2047 $$ = scm_cons ($3, SCM_EOL);
2049 | new_lyrics ADDLYRICS {
2050 parser->lexer_->push_lyric_state ();
2052 parser->lexer_->pop_state ();
2053 $$ = scm_cons ($4, $1);
2058 composite_music new_lyrics {
2059 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2061 | LYRICSTO simple_string {
2062 parser->lexer_->push_lyric_state ();
2064 parser->lexer_->pop_state ();
2065 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2070 CHANGE symbol '=' simple_string {
2071 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2078 $$ = scm_reverse_x ($1, SCM_EOL);
2080 | symbol_list_rev property_path {
2081 $$ = scm_reverse_x ($1, $2);
2087 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2090 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2092 | OVERRIDE property_path '=' scalar {
2093 if (scm_ilength ($2) < 2) {
2094 parser->parser_error (@2, _("bad grob property path"));
2097 $$ = scm_cons (ly_symbol2scm ("push"),
2098 scm_cons2 (scm_car ($2),
2103 | REVERT revert_arg {
2104 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2108 // This is all quite awkward for the sake of substantial backward
2109 // compatibility while at the same time allowing a more "natural" form
2110 // of specification not separating grob specification from grob
2111 // property path. The purpose of this definition of revert_arg is to
2112 // allow the symbol list which specifies grob and property to revert
2113 // to be optionally be split into two parts after the grob (which in
2114 // this case is just the first element of the list). symbol_list_part
2115 // is only one path component, but it can be parsed without lookahead,
2116 // so we can follow it with a synthetic BACKUP token when needed. If
2117 // the first symbol_list_part already contains multiple elements (only
2118 // possible if a Scheme expression provides them), we just parse for
2119 // additional elements introduced by '.', which is what the
2120 // SYMBOL_LIST backup in connection with the immediately following
2121 // rule using symbol_list_arg does.
2123 // As long as we don't have our coffers filled with both grob and at
2124 // least one grob property specification, the rest of the required
2125 // symbol list chain may be provided either with or without a leading
2126 // dot. This is for both allowing the traditional
2127 // \revert Accidental #'color
2128 // as well as well as the "naive" form
2129 // \revert Accidental.color
2132 revert_arg_backup BACKUP symbol_list_arg
2141 if (scm_is_null ($1)
2142 || scm_is_null (scm_cdr ($1)))
2143 MYBACKUP (SCM_ARG, $1, @1);
2145 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2149 // revert_arg_part delivers results in reverse
2152 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2154 $$ = scm_append_x (scm_list_2 ($5, $3));
2156 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2158 $$ = scm_append_x (scm_list_2 ($4, $3));
2163 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2164 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2166 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2167 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2168 | DENIES { $$ = ly_symbol2scm ("denies"); }
2170 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2171 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2172 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2173 | NAME { $$ = ly_symbol2scm ("context-name"); }
2177 property_operation { $$ = $1; }
2178 | context_def_mod STRING {
2179 $$ = scm_list_2 ($1, $2);
2181 | context_def_mod embedded_scm
2183 if (!scm_is_string ($2)
2184 && ly_symbol2scm ("consists") != $1
2185 && ly_symbol2scm ("remove") != $1)
2188 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2192 $$ = scm_list_2 ($1, $2);
2197 // If defined, at least two members.
2201 SCM l = scm_reverse_x ($1, SCM_EOL);
2204 (scm_object_property (scm_car (l),
2205 ly_symbol2scm ("is-grob?"))))
2206 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2207 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2208 parser->parser_error (@1, _ ("bad grob property path"));
2215 // If defined, at least three members
2219 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2221 parser->parser_error (@1, _ ("bad grob property path"));
2225 | grob_prop_spec property_path
2227 if (!SCM_UNBNDP ($1)) {
2228 $$ = scm_append_x (scm_list_2 ($1, $2));
2229 if (scm_is_null (scm_cddr ($$))) {
2230 parser->parser_error (@$, _ ("bad grob property path"));
2238 // Exactly two elements or undefined
2242 SCM l = scm_reverse_x ($1, SCM_EOL);
2243 switch (scm_ilength (l)) {
2245 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2249 parser->parser_error (@1, _ ("bad context property path"));
2256 simple_music_property_def:
2257 OVERRIDE grob_prop_path '=' scalar {
2258 if (SCM_UNBNDP ($2))
2261 $$ = scm_list_5 (scm_car ($2),
2262 ly_symbol2scm ("OverrideProperty"),
2268 | REVERT simple_revert_context revert_arg {
2269 $$ = scm_list_4 ($2,
2270 ly_symbol2scm ("RevertProperty"),
2274 | SET context_prop_spec '=' scalar {
2275 if (SCM_UNBNDP ($2))
2278 $$ = scm_list_4 (scm_car ($2),
2279 ly_symbol2scm ("PropertySet"),
2283 | UNSET context_prop_spec {
2284 if (SCM_UNBNDP ($2))
2287 $$ = scm_list_3 (scm_car ($2),
2288 ly_symbol2scm ("PropertyUnset"),
2294 // This is all quite awkward for the sake of substantial backward
2295 // compatibility while at the same time allowing a more "natural" form
2296 // of specification not separating grob specification from grob
2297 // property path. The purpose of this definition of
2298 // simple_revert_context is to allow the symbol list which specifies
2299 // grob and property to revert to be optionally be split into two
2300 // parts after the grob (which may be preceded by a context
2301 // specification, a case which we distinguish by checking whether the
2302 // first symbol is a valid grob symbol instead).
2304 // See revert_arg above for the main work horse of this arrangement.
2305 // simple_revert_context just caters for the context and delegates the
2306 // rest of the job to revert_arg.
2308 simple_revert_context:
2311 $1 = scm_reverse_x ($1, SCM_EOL);
2312 if (scm_is_null ($1)
2314 (scm_object_property (scm_car ($1),
2315 ly_symbol2scm ("is-grob?")))) {
2316 $$ = ly_symbol2scm ("Bottom");
2317 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2320 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2327 simple_music_property_def {
2328 if (SCM_UNBNDP ($1))
2329 $$ = MAKE_SYNTAX ("void-music", @1);
2331 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2342 simple_string: STRING {
2347 if (scm_is_string ($1)) {
2350 parser->parser_error (@1, (_ ("simple string expected")));
2351 $$ = scm_string (SCM_EOL);
2358 $$ = scm_string_to_symbol ($1);
2362 // This is a bit of overkill but makes the same
2363 // routine responsible for all symbol interpretations.
2364 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2366 if (SCM_UNBNDP ($$))
2368 parser->parser_error (@1, (_ ("symbol expected")));
2369 // Generate a unique symbol in case it is used
2370 // for an assignment or similar
2371 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2380 // The following is a rather defensive variant of admitting
2381 // negative numbers: the grammar would permit number_factor or
2382 // even number_expression. However, function arguments allow
2383 // only this simple kind of negative number, so to have things
2384 // like \tweak and \override behave reasonably similar, it
2385 // makes sense to rule out things like -- which are rather an
2386 // accent in function argument contexts.
2389 $$ = scm_difference ($2, SCM_UNDEFINED);
2396 simple_element post_events {
2397 // Let the rhythmic music iterator sort this mess out.
2398 if (scm_is_pair ($2)) {
2399 $$ = make_music_from_simple (parser, @1, $1);
2400 if (unsmob_music ($$))
2401 unsmob_music ($$)->set_property ("articulations",
2402 scm_reverse_x ($2, SCM_EOL));
2405 parser->parser_error (@1, _("music expected"));
2406 $$ = MAKE_SYNTAX ("void-music", @1);
2410 | simple_chord_elements post_events {
2411 if (scm_is_pair ($2)) {
2412 if (unsmob_pitch ($1))
2413 $1 = make_chord_elements (@1,
2415 parser->default_duration_.smobbed_copy (),
2418 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2420 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
2421 } else if (!unsmob_pitch ($1))
2422 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
2423 // A mere pitch drops through.
2425 | CHORD_REPETITION optional_notemode_duration post_events {
2427 i.set_location (@1, @3);
2428 $$ = MAKE_SYNTAX ("repetition-chord", i,
2429 $2, scm_reverse_x ($3, SCM_EOL));
2431 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2433 i.set_location (@1, @3);
2434 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2435 scm_reverse_x ($3, SCM_EOL));
2438 | note_chord_element
2443 chord_body optional_notemode_duration post_events
2445 Music *m = unsmob_music ($1);
2446 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2447 SCM es = m->get_property ("elements");
2448 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2450 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2451 unsmob_music (scm_car (s))->set_property ("duration", dur);
2452 es = ly_append2 (es, postevs);
2454 m-> set_property ("elements", es);
2456 $$ = m->self_scm ();
2461 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2463 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2467 chord_body_elements:
2468 /* empty */ { $$ = SCM_EOL; }
2469 | chord_body_elements chord_body_element {
2470 if (!SCM_UNBNDP ($2))
2471 $$ = scm_cons ($2, $1);
2476 pitch exclamations questions octave_check post_events
2478 bool q = to_boolean ($3);
2479 bool ex = to_boolean ($2);
2483 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2484 n->set_property ("pitch", $1);
2486 n->set_property ("cautionary", SCM_BOOL_T);
2488 n->set_property ("force-accidental", SCM_BOOL_T);
2490 if (scm_is_pair (post)) {
2491 SCM arts = scm_reverse_x (post, SCM_EOL);
2492 n->set_property ("articulations", arts);
2494 if (scm_is_number (check))
2496 int q = scm_to_int (check);
2497 n->set_property ("absolute-octave", scm_from_int (q-1));
2500 $$ = n->unprotect ();
2502 | DRUM_PITCH post_events {
2503 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2504 n->set_property ("drum-type", $1);
2506 if (scm_is_pair ($2)) {
2507 SCM arts = scm_reverse_x ($2, SCM_EOL);
2508 n->set_property ("articulations", arts);
2510 $$ = n->unprotect ();
2512 | music_function_chord_body
2514 Music *m = unsmob_music ($1);
2516 while (m && m->is_mus_type ("music-wrapper-music")) {
2517 $$ = m->get_property ("element");
2518 m = unsmob_music ($$);
2521 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2522 parser->parser_error (@$, _ ("not a rhythmic event"));
2528 music_function_chord_body:
2533 event_function_event:
2534 EVENT_FUNCTION function_arglist {
2535 $$ = MAKE_SYNTAX ("music-function", @$,
2544 | post_events post_event {
2546 if (Music *m = unsmob_music ($2))
2548 if (m->is_mus_type ("post-event-wrapper"))
2550 for (SCM p = m->get_property ("elements");
2554 $$ = scm_cons (scm_car (p), $$);
2558 $$ = scm_cons ($2, $$);
2564 post_event_nofinger:
2565 direction_less_event {
2568 | script_dir music_function_call {
2570 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2571 parser->parser_error (@2, _ ("post-event expected"));
2572 $$ = SCM_UNSPECIFIED;
2573 } else if (!SCM_UNBNDP ($1))
2575 unsmob_music ($$)->set_property ("direction", $1);
2579 if (!parser->lexer_->is_lyric_state ())
2580 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2581 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2584 if (!parser->lexer_->is_lyric_state ())
2585 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2586 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2588 | script_dir direction_reqd_event {
2589 if (!SCM_UNBNDP ($1))
2591 Music *m = unsmob_music ($2);
2592 m->set_property ("direction", $1);
2596 | script_dir direction_less_event {
2597 if (!SCM_UNBNDP ($1))
2599 Music *m = unsmob_music ($2);
2600 m->set_property ("direction", $1);
2607 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2612 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2623 string_number_event:
2625 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2626 s->set_property ("string-number", $1);
2627 $$ = s->unprotect ();
2631 direction_less_event:
2633 | EVENT_IDENTIFIER {
2637 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2638 a->set_property ("tremolo-type", $1);
2639 $$ = a->unprotect ();
2641 | event_function_event
2644 direction_reqd_event:
2648 | script_abbreviation {
2649 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2650 if (scm_is_string (s)) {
2651 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2652 a->set_property ("articulation-type", s);
2653 $$ = a->unprotect ();
2655 Music *original = unsmob_music (s);
2656 if (original && original->is_mus_type ("post-event")) {
2657 Music *a = original->clone ();
2658 a->set_spot (parser->lexer_->override_input (@$));
2659 $$ = a->unprotect ();
2661 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2662 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2669 /**/ { $$ = SCM_EOL; }
2670 | '=' quotes { $$ = $2; }
2684 $$ = scm_from_int (1);
2687 $$ = scm_oneplus ($1);
2693 $$ = scm_from_int (-1);
2696 $$ = scm_oneminus ($1);
2701 NOTENAME_PITCH quotes {
2702 if (!scm_is_eq (SCM_INUM0, $2))
2704 Pitch p = *unsmob_pitch ($1);
2705 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2706 $$ = p.smobbed_copy ();
2716 TONICNAME_PITCH quotes {
2717 if (!scm_is_eq (SCM_INUM0, $2))
2719 Pitch p = *unsmob_pitch ($1);
2720 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2721 $$ = p.smobbed_copy ();
2728 | PITCH_IDENTIFIER quotes {
2729 if (!scm_is_eq (SCM_INUM0, $2))
2731 Pitch p = *unsmob_pitch ($1);
2732 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2733 $$ = p.smobbed_copy ();
2740 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2741 t->set_property ("text", $1);
2742 $$ = t->unprotect ();
2745 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2746 t->set_property ("text",
2747 make_simple_markup ($1));
2748 $$ = t->unprotect ();
2752 Music *m = unsmob_music ($1);
2753 if (m && m->is_mus_type ("post-event"))
2755 else if (Text_interface::is_markup ($1)) {
2756 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2757 t->set_property ("text", $1);
2758 $$ = t->unprotect ();
2760 parser->parser_error (@1, _ ("not an articulation"));
2766 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2767 t->set_property ("digit", $1);
2768 $$ = t->unprotect ();
2772 script_abbreviation:
2774 $$ = scm_from_locale_string ("Hat");
2777 $$ = scm_from_locale_string ("Plus");
2780 $$ = scm_from_locale_string ("Dash");
2783 $$ = scm_from_locale_string ("Bang");
2786 $$ = scm_from_locale_string ("Larger");
2789 $$ = scm_from_locale_string ("Dot");
2792 $$ = scm_from_locale_string ("Underscore");
2797 '_' { $$ = scm_from_int (DOWN); }
2798 | '^' { $$ = scm_from_int (UP); }
2799 | '-' { $$ = SCM_UNDEFINED; }
2803 multiplied_duration {
2808 maybe_notemode_duration:
2812 | multiplied_duration {
2814 parser->default_duration_ = *unsmob_duration ($$);
2819 optional_notemode_duration:
2820 maybe_notemode_duration
2822 if (SCM_UNBNDP ($$))
2823 $$ = parser->default_duration_.smobbed_copy ();
2829 $$ = make_duration ($1, scm_to_int ($2));
2830 if (SCM_UNBNDP ($$))
2832 parser->parser_error (@1, _ ("not a duration"));
2833 $$ = Duration ().smobbed_copy ();
2836 | DURATION_IDENTIFIER dots {
2837 Duration *d = unsmob_duration ($1);
2838 Duration k (d->duration_log (),
2839 d->dot_count () + scm_to_int ($2));
2840 k = k.compressed (d->factor ());
2841 scm_remember_upto_here_1 ($1);
2842 $$ = k.smobbed_copy ();
2846 multiplied_duration:
2850 | multiplied_duration '*' UNSIGNED {
2851 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2853 | multiplied_duration '*' FRACTION {
2854 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2856 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2865 $$ = scm_oneplus ($1);
2874 if (SCM_UNBNDP (make_duration ($2)))
2875 parser->parser_error (@2, _ ("not a duration"));
2881 UNSIGNED { $$ = $1; }
2882 | STRING { $$ = $1; }
2883 | full_markup { $$ = $1; }
2886 // as an integer, it needs to be non-negative, and otherwise
2887 // it needs to be suitable as a markup.
2888 if (scm_is_integer ($1)
2889 ? scm_is_true (scm_negative_p ($1))
2890 : !Text_interface::is_markup ($1))
2892 parser->parser_error (@1, _ ("bass number expected"));
2898 figured_bass_alteration:
2899 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2900 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2901 | '!' { $$ = scm_from_int (0); }
2906 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2907 $$ = bfr->unprotect ();
2910 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2911 $$ = bfr->self_scm ();
2913 if (scm_is_number ($1))
2914 bfr->set_property ("figure", $1);
2915 else if (Text_interface::is_markup ($1))
2916 bfr->set_property ("text", $1);
2922 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2924 | bass_figure figured_bass_alteration {
2925 Music *m = unsmob_music ($1);
2926 if (scm_to_double ($2)) {
2927 SCM salter = m->get_property ("alteration");
2928 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2929 m->set_property ("alteration",
2930 scm_sum (alter, $2));
2932 m->set_property ("alteration", scm_from_int (0));
2935 | bass_figure figured_bass_modification {
2936 Music *m = unsmob_music ($1);
2937 m->set_property ($2, SCM_BOOL_T);
2942 figured_bass_modification:
2944 $$ = ly_symbol2scm ("augmented");
2947 $$ = ly_symbol2scm ("no-continuation");
2950 $$ = ly_symbol2scm ("diminished");
2953 $$ = ly_symbol2scm ("augmented-slash");
2963 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2971 | figure_list br_bass_figure {
2972 $$ = scm_cons ($2, $1);
2977 FIGURE_OPEN figure_list FIGURE_CLOSE {
2978 $$ = scm_reverse_x ($2, SCM_EOL);
2984 /**/ { $$ = SCM_BOOL_F; }
2985 | REST { $$ = SCM_BOOL_T; }
2989 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2990 if (!parser->lexer_->is_note_state ())
2991 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2992 if (!SCM_UNBNDP ($2)
2994 || scm_is_number ($4)
2996 || scm_is_true ($6))
2999 if (scm_is_true ($6))
3000 n = MY_MAKE_MUSIC ("RestEvent", @$);
3002 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3004 n->set_property ("pitch", $1);
3005 if (SCM_UNBNDP ($5))
3006 n->set_property ("duration",
3007 parser->default_duration_.smobbed_copy ());
3009 n->set_property ("duration", $5);
3011 if (scm_is_number ($4))
3013 int q = scm_to_int ($4);
3014 n->set_property ("absolute-octave", scm_from_int (q-1));
3017 if (to_boolean ($3))
3018 n->set_property ("cautionary", SCM_BOOL_T);
3019 if (to_boolean ($2) || to_boolean ($3))
3020 n->set_property ("force-accidental", SCM_BOOL_T);
3022 $$ = n->unprotect ();
3025 | DRUM_PITCH optional_notemode_duration {
3026 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3027 n->set_property ("duration", $2);
3028 n->set_property ("drum-type", $1);
3030 $$ = n->unprotect ();
3032 | RESTNAME optional_notemode_duration {
3034 if (ly_scm2string ($1) == "s") {
3036 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3039 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3042 ev->set_property ("duration", $2);
3043 $$ = ev->unprotect ();
3047 // Can return a single pitch rather than a list.
3048 simple_chord_elements:
3050 if (!parser->lexer_->is_chord_state ())
3051 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3054 | figure_spec optional_notemode_duration {
3055 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3057 unsmob_music (scm_car (s))->set_property ("duration", $2);
3065 if (!parser->lexer_->is_lyric_state ())
3066 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3070 if (!parser->lexer_->is_lyric_state ())
3071 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3077 lyric_element_music:
3078 lyric_element optional_notemode_duration post_events {
3079 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3080 if (scm_is_pair ($3))
3081 unsmob_music ($$)->set_property
3082 ("articulations", scm_reverse_x ($3, SCM_EOL));
3086 // Can return a single pitch rather than a list.
3088 steno_tonic_pitch maybe_notemode_duration {
3089 if (SCM_UNBNDP ($2))
3092 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3094 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3095 SCM its = scm_reverse_x ($4, SCM_EOL);
3096 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3104 | chord_items chord_item {
3105 $$ = scm_cons ($2, $$);
3111 $$ = ly_symbol2scm ("chord-colon");
3114 $$ = ly_symbol2scm ("chord-caret");
3116 | CHORD_SLASH steno_tonic_pitch {
3117 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3119 | CHORD_BASS steno_tonic_pitch {
3120 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3129 $$ = scm_reverse_x ($1, SCM_EOL);
3137 step_number { $$ = scm_cons ($1, SCM_EOL); }
3138 | step_numbers '.' step_number {
3139 $$ = scm_cons ($3, $$);
3145 $$ = make_chord_step ($1, 0);
3148 $$ = make_chord_step ($1, SHARP_ALTERATION);
3150 | UNSIGNED CHORD_MINUS {
3151 $$ = make_chord_step ($1, FLAT_ALTERATION);
3159 | unsigned_number '-' unsigned_number {
3160 $$ = scm_cons ($1, $3);
3167 TODO: should deprecate in favor of Scheme?
3171 number_expression '+' number_term {
3172 $$ = scm_sum ($1, $3);
3174 | number_expression '-' number_term {
3175 $$ = scm_difference ($1, $3);
3184 | number_factor '*' number_factor {
3185 $$ = scm_product ($1, $3);
3187 | number_factor '/' number_factor {
3188 $$ = scm_divide ($1, $3);
3193 '-' number_factor { /* %prec UNARY_MINUS */
3194 $$ = scm_difference ($2, SCM_UNDEFINED);
3202 | REAL NUMBER_IDENTIFIER
3204 $$ = scm_product ($1, $2);
3211 | UNSIGNED NUMBER_IDENTIFIER {
3212 $$ = scm_product ($1, $2);
3220 if (!scm_is_integer ($1)
3221 || scm_is_true (scm_negative_p ($1)))
3223 parser->parser_error (@1, _("not an unsigned integer"));
3229 if (!scm_is_integer ($1)
3230 || scm_is_true (scm_negative_p ($1)))
3232 parser->parser_error (@1, _("not an unsigned integer"));
3239 { $$ = SCM_UNDEFINED; }
3242 if (SCM_UNBNDP ($1))
3250 // This precedence rule is rather weird. It triggers when '!' is
3251 // encountered after a pitch, and is used for deciding whether to save
3252 // this instead for a figure modification. This should not actually
3253 // occur in practice as pitches and figures are generated in different
3254 // modes. Using a greedy (%right) precedence makes sure that we don't
3255 // get stuck in a wrong interpretation.
3256 { $$ = SCM_UNDEFINED; } %prec ':'
3259 if (SCM_UNBNDP ($1))
3268 { parser->lexer_->push_markup_state (); }
3271 parser->lexer_->pop_state ();
3277 { parser->lexer_->push_markup_state (); }
3280 parser->lexer_->pop_state ();
3286 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3288 | markup_head_1_list simple_markup
3290 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3291 @2, $1, scm_list_1 ($2)));
3301 if (Text_interface::is_markup ($1))
3302 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3303 else if (Text_interface::is_markup_list ($1))
3304 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3306 parser->parser_error (@1, _ ("not a markup"));
3307 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3314 markup_composed_list {
3317 | markup_uncomposed_list
3320 markup_uncomposed_list:
3321 markup_braced_list {
3324 | markup_command_list {
3325 $$ = scm_list_1 ($1);
3327 | markup_scm MARKUPLIST_IDENTIFIER
3332 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3333 parser->lexer_->push_note_state (nn);
3334 } '{' score_body '}' {
3335 unsmob_score ($4)->origin ()->set_spot (@$);
3336 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3337 parser->lexer_->pop_state ();
3341 markup_composed_list:
3342 markup_head_1_list markup_uncomposed_list {
3343 $$ = MAKE_SYNTAX ("composed-markup-list",
3349 '{' markup_braced_list_body '}' {
3350 $$ = scm_reverse_x ($2, SCM_EOL);
3354 markup_braced_list_body:
3355 /* empty */ { $$ = SCM_EOL; }
3356 | markup_braced_list_body markup {
3357 $$ = scm_cons ($2, $1);
3359 | markup_braced_list_body markup_list {
3360 $$ = scm_reverse_x ($2, $1);
3364 markup_command_list:
3365 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3366 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3370 markup_command_basic_arguments:
3371 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3372 $$ = scm_cons ($3, $2);
3374 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3375 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3377 | EXPECT_NO_MORE_ARGS {
3382 markup_command_list_arguments:
3383 markup_command_basic_arguments { $$ = $1; }
3384 | EXPECT_MARKUP markup_command_list_arguments markup {
3385 $$ = scm_cons ($3, $2);
3390 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3391 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3396 markup_head_1_item {
3397 $$ = scm_list_1 ($1);
3399 | markup_head_1_list markup_head_1_item {
3400 $$ = scm_cons ($2, $1);
3406 $$ = make_simple_markup ($1);
3409 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3410 parser->lexer_->push_note_state (nn);
3411 } '{' score_body '}' {
3412 unsmob_score ($4)->origin ()->set_spot (@$);
3413 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3414 parser->lexer_->pop_state ();
3416 | MARKUP_FUNCTION markup_command_basic_arguments {
3417 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3419 | markup_scm MARKUP_IDENTIFIER
3426 markup_head_1_list simple_markup
3428 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3429 @2, $1, scm_list_1 ($2)));
3439 Lily_parser::set_yydebug (bool x)
3445 Lily_parser::do_yyparse ()
3447 SCM retval = SCM_UNDEFINED;
3448 yyparse (this, &retval);
3458 It is a little strange to have this function in this file, but
3459 otherwise, we have to import music classes into the lexer.
3463 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3465 if (unsmob_book (sid)) {
3466 Book *book = unsmob_book (sid)->clone ();
3467 *destination = book->self_scm ();
3470 return BOOK_IDENTIFIER;
3471 } else if (scm_is_number (sid)) {
3473 return NUMBER_IDENTIFIER;
3474 } else if (unsmob_context_def (sid)) {
3475 Context_def *def= unsmob_context_def (sid)->clone ();
3477 *destination = def->self_scm ();
3480 return CONTEXT_DEF_IDENTIFIER;
3481 } else if (unsmob_context_mod (sid)) {
3482 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3484 return CONTEXT_MOD_IDENTIFIER;
3485 } else if (Music *mus = unsmob_music (sid)) {
3486 mus = mus->clone ();
3487 *destination = mus->self_scm ();
3488 bool is_event = mus->is_mus_type ("post-event");
3490 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3491 } else if (unsmob_pitch (sid)) {
3492 *destination = unsmob_pitch (sid)->smobbed_copy ();
3493 return PITCH_IDENTIFIER;
3494 } else if (unsmob_duration (sid)) {
3495 *destination = unsmob_duration (sid)->smobbed_copy ();
3496 return DURATION_IDENTIFIER;
3497 } else if (unsmob_output_def (sid)) {
3498 Output_def *p = unsmob_output_def (sid);
3501 *destination = p->self_scm ();
3503 return OUTPUT_DEF_IDENTIFIER;
3504 } else if (unsmob_score (sid)) {
3505 *destination = unsmob_score (sid)->clone ()->unprotect ();
3506 return SCM_IDENTIFIER;
3513 get_next_unique_context_id ()
3515 return scm_from_locale_string ("$uniqueContextId");
3520 get_next_unique_lyrics_context_id ()
3522 static int new_context_count;
3524 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3525 return scm_from_locale_string (s);
3528 // check_scheme_arg checks one argument with a given predicate for use
3529 // in an argument list and throws a syntax error if it is unusable.
3530 // The argument is prepended to the argument list in any case. After
3531 // throwing a syntax error, the argument list is terminated with #f as
3532 // its last cdr in order to mark it as uncallable while not losing
3533 // track of its total length.
3535 // There are a few special considerations: if optional argument disp
3536 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3537 // instead of arg in a prospective error message. This is useful if
3538 // arg is not the actual argument but rather a transformation of it.
3540 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3541 // and an error message using disp is produced unconditionally.
3543 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3544 SCM arg, SCM args, SCM pred, SCM disp)
3546 if (SCM_UNBNDP (arg))
3547 args = scm_cons (disp, args);
3549 args = scm_cons (arg, args);
3550 if (scm_is_true (scm_call_1 (pred, arg)))
3553 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3554 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3555 SCM_UNBNDP (disp) ? arg : disp);
3556 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3560 SCM loc_on_music (Input loc, SCM arg)
3562 if (Music *m = unsmob_music (arg))
3566 return m->unprotect ();
3572 try_string_variants (SCM pred, SCM str)
3574 // a matching predicate is always ok
3575 if (scm_is_true (scm_call_1 (pred, str)))
3577 // a symbol may be interpreted as a list of symbols if it helps
3578 if (scm_is_symbol (str)) {
3579 str = scm_list_1 (str);
3580 if (scm_is_true (scm_call_1 (pred, str)))
3582 return SCM_UNDEFINED;
3585 // If this cannot be a string representation of a symbol list,
3588 if (!is_regular_identifier (str, true))
3589 return SCM_UNDEFINED;
3591 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3592 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3593 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3595 // Let's attempt the symbol list interpretation first.
3597 if (scm_is_true (scm_call_1 (pred, str)))
3600 // If there is just one symbol in the list, we might interpret
3601 // it as a single symbol
3603 if (scm_is_null (scm_cdr (str)))
3605 str = scm_car (str);
3606 if (scm_is_true (scm_call_1 (pred, str)))
3610 return SCM_UNDEFINED;
3614 is_regular_identifier (SCM id, bool multiple)
3616 if (!scm_is_string (id))
3619 string str = ly_scm2string (id);
3621 bool middle = false;
3623 for (string::iterator it=str.begin(); it != str.end (); it++)
3626 if ((c >= 'a' && c <= 'z')
3627 || (c >= 'A' && c <= 'Z')
3630 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3639 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3641 if (unsmob_music (simple))
3643 if (parser->lexer_->is_note_state ()) {
3644 if (scm_is_symbol (simple)) {
3645 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3646 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3647 n->set_property ("drum-type", simple);
3648 return n->unprotect ();
3650 if (unsmob_pitch (simple)) {
3651 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3652 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3653 n->set_property ("pitch", simple);
3654 return n->unprotect ();
3657 } else if (parser->lexer_->is_lyric_state ()) {
3658 if (Text_interface::is_markup (simple))
3659 return MAKE_SYNTAX ("lyric-event", loc, simple,
3660 parser->default_duration_.smobbed_copy ());
3661 } else if (parser->lexer_->is_chord_state ()) {
3662 if (unsmob_pitch (simple))
3666 make_chord_elements (loc, simple,
3667 parser->default_duration_.smobbed_copy (),
3674 make_music_with_input (SCM name, Input where)
3676 Music *m = make_music_by_name (name);
3677 m->set_spot (where);
3682 make_simple_markup (SCM a)
3688 make_duration (SCM d, int dots)
3690 int t = scm_to_int (d);
3691 if (t > 0 && (t & (t-1)) == 0)
3692 return Duration (intlog2 (t), dots).smobbed_copy ();
3694 return SCM_UNDEFINED;
3698 make_chord_step (SCM step_scm, Rational alter)
3700 int step = scm_to_int (step_scm);
3703 alter += FLAT_ALTERATION;
3707 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3708 return m.smobbed_copy ();
3713 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3715 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3716 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3717 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3719 unsmob_music (scm_car (s))->set_spot (loc);
3725 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3727 Lily_lexer *lex = parser->lexer_;
3731 int tok = lex->pop_extra_token ();
3734 lex->prepare_for_next_token ();
3735 return lex->yylex ();