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--2014 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 SCM s = scm_call_2 (ly_lily_module_constant ("value->lily-string"), \
46 parser->self_scm ()); \
47 char *p = scm_to_locale_string (s); \
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_MOD_IDENTIFIER
337 %token PITCH_IDENTIFIER
338 %token DURATION_IDENTIFIER
339 %token EVENT_IDENTIFIER
340 %token EVENT_FUNCTION
343 %token MARKUP_FUNCTION
344 %token MARKUP_LIST_FUNCTION
345 %token MARKUP_IDENTIFIER
346 %token MARKUPLIST_IDENTIFIER
347 %token MUSIC_FUNCTION
348 %token MUSIC_IDENTIFIER
349 %token NOTENAME_PITCH
350 %token NUMBER_IDENTIFIER
355 %token SCM_IDENTIFIER
359 %token TONICNAME_PITCH
363 /* We don't assign precedence to / and *, because we might need varied
364 prec levels in different prods */
373 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
374 parser->lexer_->push_note_state (nn);
375 } embedded_lilypond {
376 parser->lexer_->pop_state ();
381 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
382 | lilypond toplevel_expression {
384 | lilypond assignment {
387 parser->error_level_ = 1;
390 parser->error_level_ = 1;
397 parser->lexer_->add_scope (get_header (parser));
399 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
402 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
403 scm_call_2 (proc, parser->self_scm (), $1);
406 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
407 scm_call_2 (proc, parser->self_scm (), $1);
410 SCM proc = parser->lexer_->lookup_identifier
411 (unsmob_book($1)->paper_
412 ? "toplevel-book-handler"
413 : "toplevel-bookpart-handler");
414 scm_call_2 (proc, parser->self_scm (), $1);
417 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
418 scm_call_2 (proc, parser->self_scm (), $1);
421 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
422 scm_call_2 (proc, parser->self_scm (), $1);
425 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
426 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
429 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
430 scm_call_2 (proc, parser->self_scm (), $1);
433 // Evaluate and ignore #xxx, as opposed to \xxx
434 parser->lexer_->eval_scm_token ($1, @1);
436 | embedded_scm_active
438 SCM out = SCM_UNDEFINED;
439 if (Text_interface::is_markup ($1))
440 out = scm_list_1 ($1);
441 else if (Text_interface::is_markup_list ($1))
443 if (scm_is_pair (out))
445 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
446 scm_call_2 (proc, parser->self_scm (), out);
447 } else if (unsmob_score ($1))
449 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
450 scm_call_2 (proc, parser->self_scm (), $1);
451 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
452 parser->parser_error (@1, _("bad expression type"));
456 Output_def * od = unsmob_output_def ($1);
458 if (od->c_variable ("is-paper") == SCM_BOOL_T)
459 id = ly_symbol2scm ("$defaultpaper");
460 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
461 id = ly_symbol2scm ("$defaultmidi");
462 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
463 id = ly_symbol2scm ("$defaultlayout");
465 parser->lexer_->set_identifier (id, $1);
472 $$ = parser->lexer_->eval_scm_token ($1, @1);
482 embedded_scm_bare_arg:
486 $$ = parser->lexer_->eval_scm_token ($1, @1);
490 | context_modification
492 | context_def_spec_block
498 /* The generic version may end in music, or not */
505 /* embedded_scm_arg is _not_ casting pitches to music by default, this
506 * has to be done by the function itself. Note that this may cause
507 * the results of scm_function_call or embedded_scm_bare_arg to be
508 * turned into music from pitches as well. Note that this creates a
509 * distinctly awkward situation for calculated drum pitches. Those
510 * are at the current point of time rejected as music constituents as
511 * they can't be distinguished from "proper" symbols.
515 embedded_scm_bare_arg
521 SCM_FUNCTION function_arglist {
522 $$ = MAKE_SYNTAX ("music-function", @$,
527 embedded_lilypond_number:
528 '-' embedded_lilypond_number
530 $$ = scm_difference ($2, SCM_UNDEFINED);
533 | UNSIGNED NUMBER_IDENTIFIER
535 $$ = scm_product ($1, $2);
542 // FIXME: @$ does not contain a useful source location
543 // for empty rules, and the only token in the whole
544 // production, EMBEDDED_LILY, is synthetic and also
545 // contains no source location.
546 $$ = MAKE_SYNTAX ("void-music", @$);
548 | identifier_init_nonumber
549 | embedded_lilypond_number
550 | post_event post_events
552 $$ = scm_reverse_x ($2, SCM_EOL);
553 if (Music *m = unsmob_music ($1))
555 if (m->is_mus_type ("post-event-wrapper"))
557 (scm_list_2 (m->get_property ("elements"),
560 $$ = scm_cons ($1, $$);
563 && scm_is_null (scm_cdr ($$)))
567 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
568 m->set_property ("elements", $$);
569 $$ = m->unprotect ();
572 | multiplied_duration
573 | music_embedded music_embedded music_list {
574 $3 = scm_reverse_x ($3, SCM_EOL);
575 if (unsmob_music ($2))
576 $3 = scm_cons ($2, $3);
577 if (unsmob_music ($1))
578 $3 = scm_cons ($1, $3);
579 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
582 parser->error_level_ = 1;
583 $$ = SCM_UNSPECIFIED;
585 | INVALID embedded_lilypond {
586 parser->error_level_ = 1;
592 lilypond_header_body:
593 /* empty */ { $$ = SCM_UNSPECIFIED; }
594 | lilypond_header_body assignment {
597 | lilypond_header_body embedded_scm {
603 HEADER '{' lilypond_header_body '}' {
604 $$ = parser->lexer_->remove_scope ();
616 assignment_id '=' identifier_init {
617 parser->lexer_->set_identifier ($1, $3);
618 $$ = SCM_UNSPECIFIED;
620 | assignment_id property_path '=' identifier_init {
621 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
622 parser->lexer_->set_identifier (path, $4);
623 $$ = SCM_UNSPECIFIED;
625 | assignment_id '.' property_path '=' identifier_init {
626 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
627 parser->lexer_->set_identifier (path, $5);
628 $$ = SCM_UNSPECIFIED;
634 identifier_init_nonumber
636 | post_event_nofinger post_events
638 $$ = scm_reverse_x ($2, SCM_EOL);
639 if (Music *m = unsmob_music ($1))
641 if (m->is_mus_type ("post-event-wrapper"))
643 (scm_list_2 (m->get_property ("elements"),
646 $$ = scm_cons ($1, $$);
649 && scm_is_null (scm_cdr ($$)))
653 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
654 m->set_property ("elements", $$);
655 $$ = m->unprotect ();
660 identifier_init_nonumber:
665 | context_def_spec_block
672 | context_modification
675 context_def_spec_block:
676 CONTEXT '{' context_def_spec_body '}'
679 Context_def *td = unsmob_context_def ($$);
681 $$ = Context_def::make_scm ();
682 td = unsmob_context_def ($$);
684 td->origin ()->set_spot (@$);
692 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
693 parser->lexer_->push_note_state (nn);
697 parser->lexer_->pop_state ();
703 context_def_spec_body:
705 $$ = SCM_UNSPECIFIED;
707 | context_def_spec_body context_mod {
708 if (!SCM_UNBNDP ($2)) {
709 Context_def *td = unsmob_context_def ($$);
711 $$ = Context_def::make_scm ();
712 td = unsmob_context_def ($$);
714 unsmob_context_def ($$)->add_context_mod ($2);
717 | context_def_spec_body context_modification {
718 Context_def *td = unsmob_context_def ($$);
720 $$ = Context_def::make_scm ();
721 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_arg {
729 Context_def *td = unsmob_context_def ($1);
730 if (scm_is_eq ($2, SCM_UNSPECIFIED))
732 else if (!td && unsmob_context_def ($2))
736 $$ = Context_def::make_scm ();
737 td = unsmob_context_def ($$);
739 if (unsmob_music ($2)) {
740 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
741 $2 = scm_call_2 (proc, parser->self_scm (), $2);
743 if (Context_mod *cm = unsmob_context_mod ($2)) {
744 for (SCM m = cm->get_mods (); scm_is_pair (m); m = scm_cdr (m)) {
745 td->add_context_mod (scm_car (m));
748 parser->parser_error (@2, _ ("not a context mod"));
756 BOOK '{' book_body '}' {
758 unsmob_book ($$)->origin ()->set_spot (@$);
760 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
765 * Use 'handlers' like for toplevel-* stuff?
766 * grok \layout and \midi? */
769 Book *book = new Book;
770 init_papers (parser);
771 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
772 book->paper_->unprotect ();
773 push_paper (parser, book->paper_);
774 book->header_ = get_header (parser);
775 $$ = book->unprotect ();
776 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
779 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
781 | book_body paper_block {
782 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
783 set_paper (parser, unsmob_output_def ($2));
785 | book_body bookpart_block {
786 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
787 scm_call_2 (proc, $1, $2);
789 | book_body score_block {
790 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
791 scm_call_2 (proc, $1, $2);
793 | book_body composite_music {
794 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
795 scm_call_3 (proc, parser->self_scm (), $1, $2);
797 | book_body full_markup {
798 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
799 scm_call_2 (proc, $1, scm_list_1 ($2));
801 | book_body full_markup_list {
802 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
803 scm_call_2 (proc, $1, $2);
805 | book_body SCM_TOKEN {
806 // Evaluate and ignore #xxx, as opposed to \xxx
807 parser->lexer_->eval_scm_token ($2, @2);
809 | book_body embedded_scm_active
811 SCM out = SCM_UNDEFINED;
812 if (Text_interface::is_markup ($2))
813 out = scm_list_1 ($2);
814 else if (Text_interface::is_markup_list ($2))
816 if (scm_is_pair (out))
818 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
819 scm_call_2 (proc, $1, out);
820 } else if (unsmob_score ($2))
822 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
823 scm_call_2 (proc, $1, $2);
824 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
825 parser->parser_error (@2, _("bad expression type"));
829 parser->lexer_->add_scope (unsmob_book ($1)->header_);
832 Book *book = unsmob_book ($1);
834 book->scores_ = SCM_EOL;
835 book->bookparts_ = SCM_EOL;
840 BOOKPART '{' bookpart_body '}' {
842 unsmob_book ($$)->origin ()->set_spot (@$);
843 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
849 Book *book = new Book;
850 $$ = book->unprotect ();
851 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
854 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
856 | bookpart_body paper_block {
857 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
859 | bookpart_body score_block {
860 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
861 scm_call_2 (proc, $1, $2);
863 | bookpart_body composite_music {
864 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
865 scm_call_3 (proc, parser->self_scm (), $1, $2);
867 | bookpart_body full_markup {
868 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
869 scm_call_2 (proc, $1, scm_list_1 ($2));
871 | bookpart_body full_markup_list {
872 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
873 scm_call_2 (proc, $1, $2);
875 | bookpart_body SCM_TOKEN {
876 // Evaluate and ignore #xxx, as opposed to \xxx
877 parser->lexer_->eval_scm_token ($2, @2);
879 | bookpart_body embedded_scm_active
881 SCM out = SCM_UNDEFINED;
882 if (Text_interface::is_markup ($2))
883 out = scm_list_1 ($2);
884 else if (Text_interface::is_markup_list ($2))
886 if (scm_is_pair (out))
888 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
889 scm_call_2 (proc, $1, out);
890 } else if (unsmob_score ($2))
892 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
893 scm_call_2 (proc, $1, $2);
894 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
895 parser->parser_error (@2, _("bad expression type"));
899 Book *book = unsmob_book ($1);
900 if (!ly_is_module (book->header_))
901 book->header_ = ly_make_module (false);
902 parser->lexer_->add_scope (book->header_);
904 | bookpart_body error {
905 Book *book = unsmob_book ($1);
907 book->scores_ = SCM_EOL;
912 SCORE '{' score_body '}' {
913 unsmob_score ($3)->origin ()->set_spot (@$);
925 if (!scm_is_pair ($1)
926 || !ly_is_module (scm_car ($1)))
927 $1 = scm_cons (ly_make_module (false), $1);
928 parser->lexer_->add_scope (scm_car ($1));
933 | score_headers output_def
935 Output_def *od = unsmob_output_def ($2);
936 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
938 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
943 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
944 scm_set_cdr_x ($1, scm_cons ($2, scm_cdr ($1)));
946 $$ = scm_cons ($2, $1);
954 score_headers music {
955 SCM scorify = ly_lily_module_constant ("scorify-music");
956 $$ = scm_call_2 (scorify, $2, parser->self_scm ());
958 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
960 unsmob_score ($$)->set_header (scm_car ($1));
963 for (SCM p = scm_reverse_x ($1, SCM_EOL);
964 scm_is_pair (p); p = scm_cdr (p))
967 add_output_def (unsmob_output_def (scm_car (p)));
970 | embedded_scm_active {
971 if (!unsmob_score ($1))
973 $$ = (new Score)->unprotect ();
974 parser->parser_error (@1, _("score expected"));
979 Score *score = unsmob_score ($1);
980 if (!ly_is_module (score->get_header ()))
981 score->set_header (ly_make_module (false));
982 parser->lexer_->add_scope (score->get_header ());
984 | score_body output_def {
985 Output_def *od = unsmob_output_def ($2);
986 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
988 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
993 unsmob_score ($1)->add_output_def (od);
997 unsmob_score ($$)->error_found_ = true;
1008 Output_def *od = unsmob_output_def ($1);
1010 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1012 parser->parser_error (@1, _ ("need \\paper for paper block"));
1013 $$ = get_paper (parser)->unprotect ();
1020 output_def_body '}' {
1021 if (scm_is_pair ($1))
1024 parser->lexer_->remove_scope ();
1025 parser->lexer_->pop_state ();
1031 Output_def *p = get_paper (parser);
1032 p->input_origin_ = @$;
1033 parser->lexer_->add_scope (p->scope_);
1034 $$ = p->unprotect ();
1037 Output_def *p = get_midi (parser);
1038 $$ = p->unprotect ();
1039 parser->lexer_->add_scope (p->scope_);
1042 Output_def *p = get_layout (parser);
1044 parser->lexer_->add_scope (p->scope_);
1045 $$ = p->unprotect ();
1049 output_def_head_with_mode_switch:
1051 parser->lexer_->push_initial_state ();
1056 // We need this weird nonterminal because both music as well as a
1057 // context definition can start with \context and the difference is
1058 // only apparent after looking at the next token. If it is '{', there
1059 // is still time to escape from notes mode.
1061 music_or_context_def:
1063 | context_def_spec_block
1067 output_def_head_with_mode_switch '{' {
1068 unsmob_output_def ($1)->input_origin_.set_spot (@$);
1069 // This is a stupid trick to mark the beginning of the
1070 // body for deciding whether to allow
1071 // embedded_scm_active to have an output definition
1072 $$ = scm_list_1 ($1);
1074 | output_def_body assignment {
1075 if (scm_is_pair ($1))
1078 | output_def_body embedded_scm_active
1080 // We don't switch into note mode for Scheme functions
1081 // here. Does not seem warranted/required in output
1083 if (scm_is_pair ($1))
1085 Output_def *o = unsmob_output_def ($2);
1087 o->input_origin_.set_spot (@$);
1088 $1 = o->self_scm ();
1089 parser->lexer_->remove_scope ();
1090 parser->lexer_->add_scope (o->scope_);
1091 $2 = SCM_UNSPECIFIED;
1095 if (unsmob_context_def ($2))
1096 assign_context_def (unsmob_output_def ($1), $2);
1097 // Seems unlikely, but let's be complete:
1098 else if (unsmob_music ($2))
1100 SCM proc = parser->lexer_->lookup_identifier
1101 ("output-def-music-handler");
1102 scm_call_3 (proc, parser->self_scm (),
1104 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1105 parser->parser_error (@2, _("bad expression type"));
1108 | output_def_body SCM_TOKEN {
1109 if (scm_is_pair ($1))
1111 // Evaluate and ignore #xxx, as opposed to \xxx
1112 parser->lexer_->eval_scm_token ($2, @2);
1116 if (scm_is_pair ($1))
1118 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1119 parser->lexer_->push_note_state (nn);
1120 } music_or_context_def
1122 parser->lexer_->pop_state ();
1123 if (unsmob_context_def ($3))
1124 assign_context_def (unsmob_output_def ($1), $3);
1127 SCM proc = parser->lexer_->lookup_identifier
1128 ("output-def-music-handler");
1129 scm_call_3 (proc, parser->self_scm (),
1134 | output_def_body error {
1140 TEMPO steno_duration '=' tempo_range {
1141 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1143 | TEMPO scalar steno_duration '=' tempo_range {
1144 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1147 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1152 The representation of a list is reversed to have efficient append. */
1158 | music_list music_embedded {
1159 if (unsmob_music ($2))
1160 $$ = scm_cons ($2, $1);
1162 | music_list error {
1163 Music *m = MY_MAKE_MUSIC("Music", @$);
1165 m->set_property ("error-found", SCM_BOOL_T);
1166 $$ = scm_cons (m->self_scm (), $1);
1167 m->unprotect (); /* UGH */
1174 $$ = scm_reverse_x ($2, SCM_EOL);
1179 | lyric_element_music
1182 $$ = make_music_from_simple (parser, @1, $1);
1183 if (!unsmob_music ($$))
1185 parser->parser_error (@1, _ ("music expected"));
1186 $$ = MAKE_SYNTAX ("void-music", @$);
1194 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1195 parser->parser_error (@1, _ ("unexpected post-event"));
1196 $$ = SCM_UNSPECIFIED;
1199 | music_embedded_backup
1203 | music_embedded_backup BACKUP lyric_element_music
1207 | multiplied_duration post_events
1209 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1211 parser->default_duration_ = *unsmob_duration ($1);
1212 n->set_property ("duration", $1);
1214 if (scm_is_pair ($2))
1215 n->set_property ("articulations",
1216 scm_reverse_x ($2, SCM_EOL));
1217 $$ = n->unprotect ();
1221 music_embedded_backup:
1224 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1226 else if (Music *m = unsmob_music ($1)) {
1227 if (m->is_mus_type ("post-event")) {
1228 parser->parser_error
1229 (@1, _ ("unexpected post-event"));
1230 $$ = SCM_UNSPECIFIED;
1233 } else if (parser->lexer_->is_lyric_state ()
1234 && Text_interface::is_markup ($1))
1235 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1237 @$.warning (_ ("Ignoring non-music expression"));
1243 // music_assign does not need to contain lyrics: there are no
1244 // assignments in lyricmode.
1247 | composite_music %prec COMPOSITE
1251 REPEAT simple_string unsigned_number music
1253 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1255 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1257 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1262 SEQUENTIAL braced_music_list {
1263 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1265 | braced_music_list {
1266 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1271 SIMULTANEOUS braced_music_list {
1272 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1274 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1275 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1281 | music_property_def
1285 context_modification:
1288 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1289 parser->lexer_->push_note_state (nn);
1290 } '{' context_mod_list '}'
1292 parser->lexer_->pop_state ();
1295 | WITH CONTEXT_MOD_IDENTIFIER
1299 | CONTEXT_MOD_IDENTIFIER
1303 | WITH context_modification_arg
1305 if (unsmob_music ($2)) {
1306 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1307 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1309 if (unsmob_context_mod ($2))
1312 parser->parser_error (@2, _ ("not a context mod"));
1313 $$ = Context_mod ().smobbed_copy ();
1318 context_modification_arg:
1323 optional_context_mod:
1327 | context_modification
1335 $$ = Context_mod ().smobbed_copy ();
1337 | context_mod_list context_mod {
1338 if (!SCM_UNBNDP ($2))
1339 unsmob_context_mod ($1)->add_context_mod ($2);
1341 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1342 Context_mod *md = unsmob_context_mod ($2);
1344 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1346 | context_mod_list context_mod_arg {
1347 if (scm_is_eq ($2, SCM_UNSPECIFIED))
1349 else if (unsmob_music ($2)) {
1350 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1351 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1353 if (unsmob_context_mod ($2))
1354 unsmob_context_mod ($$)->add_context_mods
1355 (unsmob_context_mod ($2)->get_mods ());
1357 parser->parser_error (@2, _ ("not a context mod"));
1370 | grouped_music_list
1374 simultaneous_music { $$ = $1; }
1375 | sequential_music { $$ = $1; }
1378 /* Function argument lists are arguably the most complex part in the
1379 * parser. They are pretty tricky to understand because of the way
1380 * they are processed, and because of optional arguments that can be
1381 * omitted. When there are several optional arguments in a row,
1382 * omitting one automatically omits all following arguments. Optional
1383 * arguments can only be omitted when either
1385 * a) the omission is explicitly started with \default
1386 * b) the omission is implicitly started by an argument not matching
1387 * its predicate, and there is a mandatory argument later that can
1388 * "catch" the argument that does not fit.
1390 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1391 * (corresponding to mandatory arguments and having a predicate
1392 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1393 * the semantic value of the EXPECT_OPTIONAL token is the default to
1394 * use when the optional argument is omitted, and EXPECT_SCM again has
1395 * the argument predicate as semantic value) in reverse order to the
1396 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1397 * processed inside-out while actual tokens are consumed.
1399 * This means that the argument list tokens determine the actions
1400 * taken as they arrive. The structure of the argument list is known
1401 * to the parser and stored in its parse stack when the first argument
1402 * is being parsed. What the parser does not know is which predicates
1403 * will match and whether or not \default will be appearing in the
1404 * argument list, and where.
1406 * Sequences of 0 or more optional arguments are scanned using either
1407 * function_arglist_backup or function_arglist_nonbackup. The first
1408 * is used when optional arguments are followed by at least one
1409 * mandatory argument: in that case optional arguments may be skipped
1410 * by either a false predicate (in which case the expression will be
1411 * pushed back as one or more tokens, preceded by a BACKUP token) or
1412 * by using \default.
1414 * If optional arguments are at the end of the argument list, they are
1415 * instead scanned using function_arglist_nonbackup: here the only
1416 * manner to enter into skipping of optional arguments is the use of
1419 * The argument list of a normal function call is parsed using
1420 * function_arglist. The part of an argument list before a mandatory
1421 * argument is parsed using function_arglist_optional.
1423 * The difference is that leading optional arguments are scanned using
1424 * function_arglist_nonbackup and function_arglist_backup,
1427 * Most other details are obvious in the rules themselves.
1433 | SYMBOL_LIST '.' symbol_list_rev
1435 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1441 | symbol_list_rev '.' symbol_list_part
1443 $$ = scm_append_x (scm_list_2 ($3, $1));
1447 // symbol_list_part delivers elements in reverse copy.
1452 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1453 $$ = try_string_variants (sym_l_p, $1);
1454 if (SCM_UNBNDP ($$)) {
1455 parser->parser_error (@1, _("not a symbol"));
1458 $$ = scm_reverse ($$);
1463 symbol_list_element:
1469 function_arglist_nonbackup:
1470 function_arglist_common
1471 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1473 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1475 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1477 SCM n = scm_difference ($5, SCM_UNDEFINED);
1478 if (scm_is_true (scm_call_1 ($2, n)))
1479 $$ = scm_cons (n, $3);
1481 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1482 t->set_property ("digit", $5);
1483 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1487 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1489 $$ = check_scheme_arg (parser, @4,
1490 scm_difference ($5, SCM_UNDEFINED),
1493 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1495 $$ = check_scheme_arg (parser, @4,
1496 scm_difference ($5, SCM_UNDEFINED),
1499 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1501 if (scm_is_true (scm_call_1 ($2, $4)))
1502 $$ = scm_cons ($4, $3);
1504 $$ = check_scheme_arg (parser, @4,
1505 make_music_from_simple
1509 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1511 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1513 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1515 if (scm_is_true (scm_call_1 ($2, $3)))
1516 $$ = scm_cons ($3, $1);
1518 $$ = check_scheme_arg (parser, @3,
1519 make_music_from_simple
1523 | function_arglist_nonbackup_reparse REPARSE duration_length
1525 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1527 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1529 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1531 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1533 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1535 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1537 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1539 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1541 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1545 function_arglist_nonbackup_reparse:
1546 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1549 SCM res = try_string_variants ($2, $4);
1550 if (!SCM_UNBNDP (res))
1551 if (scm_is_pair (res))
1552 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1554 MYREPARSE (@4, $2, SCM_ARG, res);
1555 else if (scm_is_true
1557 ($2, make_music_from_simple
1559 MYREPARSE (@4, $2, STRING, $4);
1561 MYREPARSE (@4, $2, SCM_ARG, $4);
1563 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1568 ($2, make_music_from_simple
1570 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1572 MYREPARSE (@4, $2, SCM_ARG, $4);
1574 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1579 ($2, make_music_from_simple
1581 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1583 MYREPARSE (@4, $2, SCM_ARG, $4);
1585 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1588 SCM res = try_string_variants ($2, $4);
1589 if (!SCM_UNBNDP (res))
1590 if (scm_is_pair (res))
1591 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1593 MYREPARSE (@4, $2, SCM_ARG, res);
1594 else if (scm_is_true
1596 ($2, make_music_from_simple
1598 MYREPARSE (@4, $2, STRING, $4);
1600 MYREPARSE (@4, $2, SCM_ARG, $4);
1602 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1605 if (scm_is_true (scm_call_1 ($2, $4)))
1606 MYREPARSE (@4, $2, SCM_ARG, $4);
1607 else if (scm_is_true
1609 ($2, make_music_from_simple
1611 MYREPARSE (@4, $2, STRING, $4);
1613 MYREPARSE (@4, $2, SCM_ARG, $4);
1615 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1618 if (scm_is_true (scm_call_1 ($2, $4)))
1619 MYREPARSE (@4, $2, REAL, $4);
1621 SCM d = make_duration ($4);
1622 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1623 MYREPARSE (@4, $2, REAL, $4); // trigger error
1625 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1628 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1630 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1635 // function_arglist_backup can't occur at the end of an argument
1637 function_arglist_backup:
1638 function_arglist_common
1639 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1641 if (scm_is_true (scm_call_1 ($2, $4)))
1642 $$ = scm_cons ($4, $3);
1644 $$ = make_music_from_simple (parser, @4, $4);
1645 if (scm_is_true (scm_call_1 ($2, $$)))
1646 $$ = scm_cons ($$, $3);
1649 $$ = scm_cons (loc_on_music (@3, $1), $3);
1650 MYBACKUP (SCM_ARG, $4, @4);
1654 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1656 if (scm_is_true (scm_call_1 ($2, $4)))
1658 $$ = scm_cons ($4, $3);
1660 $$ = scm_cons (loc_on_music (@3, $1), $3);
1661 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1664 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1668 ($2, make_music_from_simple
1672 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1673 } else if (scm_is_true (scm_call_1 ($2, $4)))
1674 $$ = scm_cons ($4, $3);
1676 $$ = scm_cons (loc_on_music (@3, $1), $3);
1677 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1680 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1684 ($2, make_music_from_simple
1688 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1689 } else if (scm_is_true (scm_call_1 ($2, $4)))
1690 $$ = scm_cons ($4, $3);
1692 $$ = scm_cons (loc_on_music (@3, $1), $3);
1693 MYBACKUP (TONICNAME_PITCH, $4, @4);
1696 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1698 if (scm_is_true (scm_call_1 ($2, $4)))
1699 $$ = scm_cons ($4, $3);
1701 $$ = scm_cons (loc_on_music (@3, $1), $3);
1702 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1705 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1707 if (scm_is_true (scm_call_1 ($2, $4)))
1709 MYREPARSE (@4, $2, REAL, $4);
1712 SCM d = make_duration ($4);
1713 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1715 $$ = scm_cons (loc_on_music (@3, $1), $3);
1716 MYBACKUP (UNSIGNED, $4, @4);
1718 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1723 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1725 if (scm_is_true (scm_call_1 ($2, $4)))
1728 MYREPARSE (@4, $2, REAL, $4);
1730 $$ = scm_cons (loc_on_music (@3, $1), $3);
1731 MYBACKUP (REAL, $4, @4);
1734 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1736 if (scm_is_true (scm_call_1 ($2, $4)))
1738 $$ = scm_cons ($4, $3);
1740 $$ = scm_cons (loc_on_music (@3, $1), $3);
1741 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1744 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1746 SCM n = scm_difference ($5, SCM_UNDEFINED);
1747 if (scm_is_true (scm_call_1 ($2, n))) {
1749 MYREPARSE (@5, $2, REAL, n);
1751 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1752 t->set_property ("digit", $5);
1753 $$ = t->unprotect ();
1754 if (scm_is_true (scm_call_1 ($2, $$)))
1755 $$ = scm_cons ($$, $3);
1757 $$ = scm_cons (loc_on_music (@3, $1), $3);
1758 MYBACKUP (UNSIGNED, $5, @5);
1759 parser->lexer_->push_extra_token (@4, '-');
1763 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1765 SCM n = scm_difference ($5, SCM_UNDEFINED);
1766 if (scm_is_true (scm_call_1 ($2, n))) {
1767 MYREPARSE (@5, $2, REAL, n);
1770 $$ = scm_cons (loc_on_music (@3, $1), $3);
1771 MYBACKUP (REAL, n, @5);
1774 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1776 SCM n = scm_difference ($5, SCM_UNDEFINED);
1777 if (scm_is_true (scm_call_1 ($2, n))) {
1778 $$ = scm_cons (n, $3);
1780 $$ = scm_cons (loc_on_music (@3, $1), $3);
1781 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1784 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1786 if (scm_is_true (scm_call_1 ($2, $4)))
1788 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1791 $$ = scm_cons (loc_on_music (@3, $1), $3);
1792 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1795 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1797 SCM res = try_string_variants ($2, $4);
1798 if (!SCM_UNBNDP (res))
1799 if (scm_is_pair (res)) {
1801 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1804 $$ = scm_cons (res, $3);
1806 $$ = scm_cons (loc_on_music (@3, $1), $3);
1807 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1810 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1812 SCM res = try_string_variants ($2, $4);
1813 if (!SCM_UNBNDP (res))
1814 if (scm_is_pair (res)) {
1816 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1819 $$ = scm_cons (res, $3);
1821 $$ = scm_cons (loc_on_music (@3, $1), $3);
1822 MYBACKUP (STRING, $4, @4);
1825 | function_arglist_backup REPARSE pitch_or_music
1827 if (scm_is_true (scm_call_1 ($2, $3)))
1828 $$ = scm_cons ($3, $1);
1830 $$ = check_scheme_arg (parser, @3,
1831 make_music_from_simple
1835 | function_arglist_backup REPARSE bare_number_common
1837 $$ = check_scheme_arg (parser, @3,
1840 | function_arglist_backup REPARSE duration_length
1842 $$ = check_scheme_arg (parser, @3,
1845 | function_arglist_backup REPARSE symbol_list_arg
1847 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1852 function_arglist_nonbackup
1853 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1855 $$ = scm_cons (loc_on_music (@4, $1), $3);
1859 function_arglist_skip_nonbackup:
1860 function_arglist_nonbackup
1861 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1863 $$ = scm_cons (loc_on_music (@3, $1), $3);
1867 function_arglist_common:
1868 EXPECT_NO_MORE_ARGS {
1871 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1873 if (scm_is_true (scm_call_1 ($1, $3)))
1874 $$ = scm_cons ($3, $2);
1876 $$ = check_scheme_arg (parser, @3,
1877 make_music_from_simple
1881 | EXPECT_SCM function_arglist_optional bare_number_common
1883 $$ = check_scheme_arg (parser, @3,
1886 | EXPECT_SCM function_arglist_optional post_event_nofinger
1888 $$ = check_scheme_arg (parser, @3,
1891 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1893 SCM n = scm_difference ($4, SCM_UNDEFINED);
1894 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1896 | function_arglist_common_reparse REPARSE SCM_ARG
1898 $$ = check_scheme_arg (parser, @3,
1901 | function_arglist_common_reparse REPARSE lyric_element_music
1903 $$ = check_scheme_arg (parser, @3,
1906 | function_arglist_common_reparse REPARSE pitch_or_music
1908 if (scm_is_true (scm_call_1 ($2, $3)))
1909 $$ = scm_cons ($3, $1);
1911 $$ = check_scheme_arg (parser, @3,
1912 make_music_from_simple
1916 | function_arglist_common_reparse REPARSE bare_number_common
1918 $$ = check_scheme_arg (parser, @3,
1921 | function_arglist_common_reparse REPARSE duration_length
1923 $$ = check_scheme_arg (parser, @3,
1926 | function_arglist_common_reparse REPARSE symbol_list_arg
1928 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1932 function_arglist_common_reparse:
1933 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1936 SCM res = try_string_variants ($1, $3);
1937 if (!SCM_UNBNDP (res))
1938 if (scm_is_pair (res))
1939 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1941 MYREPARSE (@3, $1, SCM_ARG, res);
1942 else if (scm_is_true
1944 ($1, make_music_from_simple (parser, @3, $3))))
1945 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1947 // This is going to flag a syntax error, we
1948 // know the predicate to be false.
1949 MYREPARSE (@3, $1, SCM_ARG, $3);
1951 | EXPECT_SCM function_arglist_optional pitch
1956 ($1, make_music_from_simple
1958 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
1960 MYREPARSE (@3, $1, SCM_ARG, $3);
1962 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
1967 ($1, make_music_from_simple
1969 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
1971 MYREPARSE (@3, $1, SCM_ARG, $3);
1973 | EXPECT_SCM function_arglist_optional STRING
1976 SCM res = try_string_variants ($1, $3);
1977 if (!SCM_UNBNDP (res))
1978 if (scm_is_pair (res))
1979 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1981 MYREPARSE (@3, $1, SCM_ARG, res);
1982 else if (scm_is_true
1984 ($1, make_music_from_simple (parser, @3, $3))))
1985 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1987 // This is going to flag a syntax error, we
1988 // know the predicate to be false.
1989 MYREPARSE (@3, $1, SCM_ARG, $3);
1991 | EXPECT_SCM function_arglist_optional full_markup
1994 if (scm_is_true (scm_call_1 ($1, $3)))
1995 MYREPARSE (@3, $1, SCM_ARG, $3);
1996 else if (scm_is_true
1998 ($1, make_music_from_simple (parser, @3, $3))))
1999 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2001 // This is going to flag a syntax error, we
2002 // know the predicate to be false.
2003 MYREPARSE (@3, $1, SCM_ARG, $3);
2005 | EXPECT_SCM function_arglist_optional UNSIGNED
2008 if (scm_is_true (scm_call_1 ($1, $3)))
2009 MYREPARSE (@3, $1, REAL, $3);
2011 SCM d = make_duration ($3);
2012 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
2013 MYREPARSE (@3, $1, REAL, $3);
2015 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2018 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2021 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2023 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2026 SCM n = scm_difference ($4, SCM_UNDEFINED);
2027 if (scm_is_true (scm_call_1 ($1, n)))
2028 MYREPARSE (@4, $1, REAL, n);
2030 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2031 t->set_property ("digit", $4);
2032 SCM m = t->unprotect ();
2033 if (scm_is_true (scm_call_1 ($1, m)))
2034 MYREPARSE (@4, $1, SCM_ARG, m);
2036 MYREPARSE (@4, $1, SCM_ARG, $4);
2039 | EXPECT_SCM function_arglist_optional '-' REAL
2042 SCM n = scm_difference ($4, SCM_UNDEFINED);
2043 MYREPARSE (@4, $1, REAL, n);
2047 function_arglist_optional:
2048 function_arglist_backup
2049 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2051 $$ = scm_cons (loc_on_music (@4, $1), $3);
2053 | function_arglist_skip_backup BACKUP
2056 function_arglist_skip_backup:
2057 function_arglist_backup
2058 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2060 $$ = scm_cons (loc_on_music (@3, $1), $3);
2064 music_function_call:
2065 MUSIC_FUNCTION function_arglist {
2066 $$ = MAKE_SYNTAX ("music-function", @$,
2073 /**/ { $$ = SCM_EOL; }
2074 | '=' simple_string {
2079 // We must not have lookahead tokens parsed in lyric mode. In order
2080 // to save confusion, we take almost the same set as permitted with
2081 // \lyricmode and/or \lyrics. However, music identifiers are also
2082 // allowed, and they obviously do not require switching into lyrics
2083 // mode for parsing.
2087 parser->lexer_->push_lyric_state ();
2088 } grouped_music_list
2090 parser->lexer_->pop_state ();
2098 | repeated_music { $$ = $1; }
2099 | re_rhythmed_music { $$ = $1; }
2100 | complex_music_prefix music
2102 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2106 complex_music_prefix:
2107 CONTEXT symbol optional_id optional_context_mod {
2108 Context_mod *ctxmod = unsmob_context_mod ($4);
2111 mods = ctxmod->get_mods ();
2112 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2114 | NEWCONTEXT symbol optional_id optional_context_mod {
2115 Context_mod *ctxmod = unsmob_context_mod ($4);
2118 mods = ctxmod->get_mods ();
2119 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2124 mode_changing_head grouped_music_list {
2125 if ($1 == ly_symbol2scm ("chords"))
2127 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2133 parser->lexer_->pop_state ();
2135 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2136 Context_mod *ctxmod = unsmob_context_mod ($2);
2139 mods = ctxmod->get_mods ();
2140 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2141 if ($1 == ly_symbol2scm ("ChordNames"))
2143 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2145 parser->lexer_->pop_state ();
2151 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2152 parser->lexer_->push_note_state (nn);
2154 $$ = ly_symbol2scm ("notes");
2158 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2159 parser->lexer_->push_note_state (nn);
2161 $$ = ly_symbol2scm ("drums");
2164 parser->lexer_->push_figuredbass_state ();
2166 $$ = ly_symbol2scm ("figures");
2169 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2170 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2171 nn = parser->lexer_->lookup_identifier ("pitchnames");
2172 parser->lexer_->push_chord_state (nn);
2173 $$ = ly_symbol2scm ("chords");
2177 { parser->lexer_->push_lyric_state ();
2178 $$ = ly_symbol2scm ("lyrics");
2182 mode_changing_head_with_context:
2184 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2185 parser->lexer_->push_note_state (nn);
2187 $$ = ly_symbol2scm ("DrumStaff");
2190 parser->lexer_->push_figuredbass_state ();
2192 $$ = ly_symbol2scm ("FiguredBass");
2195 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2196 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2197 nn = parser->lexer_->lookup_identifier ("pitchnames");
2198 parser->lexer_->push_chord_state (nn);
2199 $$ = ly_symbol2scm ("ChordNames");
2202 { parser->lexer_->push_lyric_state ();
2203 $$ = ly_symbol2scm ("Lyrics");
2208 ADDLYRICS lyric_mode_music {
2209 $$ = scm_list_1 ($2);
2211 | new_lyrics ADDLYRICS lyric_mode_music {
2212 $$ = scm_cons ($3, $1);
2217 composite_music new_lyrics {
2218 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2220 | LYRICSTO simple_string lyric_mode_music {
2221 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $3);
2226 CHANGE symbol '=' simple_string {
2227 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2234 $$ = scm_reverse_x ($1, SCM_EOL);
2236 | symbol_list_rev property_path {
2237 $$ = scm_reverse_x ($1, $2);
2243 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2246 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2248 | OVERRIDE property_path '=' scalar {
2249 if (scm_ilength ($2) < 2) {
2250 parser->parser_error (@2, _("bad grob property path"));
2253 $$ = scm_cons (ly_symbol2scm ("push"),
2254 scm_cons2 (scm_car ($2),
2259 | REVERT revert_arg {
2260 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2264 // This is all quite awkward for the sake of substantial backward
2265 // compatibility while at the same time allowing a more "natural" form
2266 // of specification not separating grob specification from grob
2267 // property path. The purpose of this definition of revert_arg is to
2268 // allow the symbol list which specifies grob and property to revert
2269 // to be optionally be split into two parts after the grob (which in
2270 // this case is just the first element of the list). symbol_list_part
2271 // is only one path component, but it can be parsed without lookahead,
2272 // so we can follow it with a synthetic BACKUP token when needed. If
2273 // the first symbol_list_part already contains multiple elements (only
2274 // possible if a Scheme expression provides them), we just parse for
2275 // additional elements introduced by '.', which is what the
2276 // SYMBOL_LIST backup in connection with the immediately following
2277 // rule using symbol_list_arg does.
2279 // As long as we don't have our coffers filled with both grob and at
2280 // least one grob property specification, the rest of the required
2281 // symbol list chain may be provided either with or without a leading
2282 // dot. This is for both allowing the traditional
2283 // \revert Accidental #'color
2284 // as well as well as the "naive" form
2285 // \revert Accidental.color
2288 revert_arg_backup BACKUP symbol_list_arg
2297 if (scm_is_null ($1)
2298 || scm_is_null (scm_cdr ($1)))
2299 MYBACKUP (SCM_ARG, $1, @1);
2301 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2305 // revert_arg_part delivers results in reverse
2308 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2310 $$ = scm_append_x (scm_list_2 ($5, $3));
2312 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2314 $$ = scm_append_x (scm_list_2 ($4, $3));
2319 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2320 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2322 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2323 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2324 | DENIES { $$ = ly_symbol2scm ("denies"); }
2326 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2327 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2328 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2329 | NAME { $$ = ly_symbol2scm ("context-name"); }
2333 property_operation { $$ = $1; }
2334 | context_def_mod STRING {
2335 $$ = scm_list_2 ($1, $2);
2337 | context_def_mod embedded_scm
2339 if (!scm_is_string ($2)
2340 && ly_symbol2scm ("consists") != $1
2341 && ly_symbol2scm ("remove") != $1)
2344 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2348 $$ = scm_list_2 ($1, $2);
2353 // If defined, at least two members.
2357 SCM l = scm_reverse_x ($1, SCM_EOL);
2360 (scm_object_property (scm_car (l),
2361 ly_symbol2scm ("is-grob?"))))
2362 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2363 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2364 parser->parser_error (@1, _ ("bad grob property path"));
2371 // If defined, at least three members
2375 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2377 parser->parser_error (@1, _ ("bad grob property path"));
2381 | grob_prop_spec property_path
2383 if (!SCM_UNBNDP ($1)) {
2384 $$ = scm_append_x (scm_list_2 ($1, $2));
2385 if (scm_is_null (scm_cddr ($$))) {
2386 parser->parser_error (@$, _ ("bad grob property path"));
2394 // Exactly two elements or undefined
2398 SCM l = scm_reverse_x ($1, SCM_EOL);
2399 switch (scm_ilength (l)) {
2401 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2405 parser->parser_error (@1, _ ("bad context property path"));
2412 simple_music_property_def:
2413 OVERRIDE grob_prop_path '=' scalar {
2414 if (SCM_UNBNDP ($2))
2417 $$ = scm_list_5 (scm_car ($2),
2418 ly_symbol2scm ("OverrideProperty"),
2424 | REVERT simple_revert_context revert_arg {
2425 $$ = scm_list_4 ($2,
2426 ly_symbol2scm ("RevertProperty"),
2430 | SET context_prop_spec '=' scalar {
2431 if (SCM_UNBNDP ($2))
2434 $$ = scm_list_4 (scm_car ($2),
2435 ly_symbol2scm ("PropertySet"),
2439 | UNSET context_prop_spec {
2440 if (SCM_UNBNDP ($2))
2443 $$ = scm_list_3 (scm_car ($2),
2444 ly_symbol2scm ("PropertyUnset"),
2450 // This is all quite awkward for the sake of substantial backward
2451 // compatibility while at the same time allowing a more "natural" form
2452 // of specification not separating grob specification from grob
2453 // property path. The purpose of this definition of
2454 // simple_revert_context is to allow the symbol list which specifies
2455 // grob and property to revert to be optionally be split into two
2456 // parts after the grob (which may be preceded by a context
2457 // specification, a case which we distinguish by checking whether the
2458 // first symbol is a valid grob symbol instead).
2460 // See revert_arg above for the main work horse of this arrangement.
2461 // simple_revert_context just caters for the context and delegates the
2462 // rest of the job to revert_arg.
2464 simple_revert_context:
2467 $1 = scm_reverse_x ($1, SCM_EOL);
2468 if (scm_is_null ($1)
2470 (scm_object_property (scm_car ($1),
2471 ly_symbol2scm ("is-grob?")))) {
2472 $$ = ly_symbol2scm ("Bottom");
2473 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2476 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2483 simple_music_property_def {
2484 if (SCM_UNBNDP ($1))
2485 $$ = MAKE_SYNTAX ("void-music", @1);
2487 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2498 simple_string: STRING {
2503 if (scm_is_string ($1)) {
2506 parser->parser_error (@1, (_ ("simple string expected")));
2507 $$ = scm_string (SCM_EOL);
2514 $$ = scm_string_to_symbol ($1);
2518 // This is a bit of overkill but makes the same
2519 // routine responsible for all symbol interpretations.
2520 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2522 if (SCM_UNBNDP ($$))
2524 parser->parser_error (@1, (_ ("symbol expected")));
2525 // Generate a unique symbol in case it is used
2526 // for an assignment or similar
2527 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2537 // The following is a rather defensive variant of admitting
2538 // negative numbers: the grammar would permit number_factor or
2539 // even number_expression. However, function arguments allow
2540 // only this simple kind of negative number, so to have things
2541 // like \tweak and \override behave reasonably similar, it
2542 // makes sense to rule out things like -- which are rather an
2543 // accent in function argument contexts.
2546 $$ = scm_difference ($2, SCM_UNDEFINED);
2552 simple_element post_events {
2553 // Let the rhythmic music iterator sort this mess out.
2554 if (scm_is_pair ($2)) {
2555 unsmob_music ($$)->set_property ("articulations",
2556 scm_reverse_x ($2, SCM_EOL));
2559 | CHORD_REPETITION optional_notemode_duration post_events {
2561 i.set_location (@1, @3);
2562 $$ = MAKE_SYNTAX ("repetition-chord", i,
2563 $2, scm_reverse_x ($3, SCM_EOL));
2565 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2567 i.set_location (@1, @3);
2568 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2569 scm_reverse_x ($3, SCM_EOL));
2572 | note_chord_element
2577 chord_body optional_notemode_duration post_events
2579 Music *m = unsmob_music ($1);
2580 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2581 SCM es = m->get_property ("elements");
2582 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2584 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2585 unsmob_music (scm_car (s))->set_property ("duration", dur);
2586 es = ly_append2 (es, postevs);
2588 m-> set_property ("elements", es);
2590 $$ = m->self_scm ();
2595 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2597 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2601 chord_body_elements:
2602 /* empty */ { $$ = SCM_EOL; }
2603 | chord_body_elements chord_body_element {
2604 if (!SCM_UNBNDP ($2))
2605 $$ = scm_cons ($2, $1);
2610 pitch exclamations questions octave_check post_events
2612 bool q = to_boolean ($3);
2613 bool ex = to_boolean ($2);
2617 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2618 n->set_property ("pitch", $1);
2620 n->set_property ("cautionary", SCM_BOOL_T);
2622 n->set_property ("force-accidental", SCM_BOOL_T);
2624 if (scm_is_pair (post)) {
2625 SCM arts = scm_reverse_x (post, SCM_EOL);
2626 n->set_property ("articulations", arts);
2628 if (scm_is_number (check))
2630 int q = scm_to_int (check);
2631 n->set_property ("absolute-octave", scm_from_int (q-1));
2634 $$ = n->unprotect ();
2636 | DRUM_PITCH post_events {
2637 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2638 n->set_property ("drum-type", $1);
2640 if (scm_is_pair ($2)) {
2641 SCM arts = scm_reverse_x ($2, SCM_EOL);
2642 n->set_property ("articulations", arts);
2644 $$ = n->unprotect ();
2646 | music_function_chord_body
2648 Music *m = unsmob_music ($1);
2650 while (m && m->is_mus_type ("music-wrapper-music")) {
2651 $$ = m->get_property ("element");
2652 m = unsmob_music ($$);
2655 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2656 parser->parser_error (@$, _ ("not a rhythmic event"));
2662 music_function_chord_body:
2668 event_function_event:
2669 EVENT_FUNCTION function_arglist {
2670 $$ = MAKE_SYNTAX ("music-function", @$,
2679 | post_events post_event {
2681 if (Music *m = unsmob_music ($2))
2683 if (m->is_mus_type ("post-event-wrapper"))
2685 for (SCM p = m->get_property ("elements");
2689 $$ = scm_cons (scm_car (p), $$);
2693 $$ = scm_cons ($2, $$);
2699 post_event_nofinger:
2700 direction_less_event {
2703 | script_dir music_function_call {
2705 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2706 parser->parser_error (@2, _ ("post-event expected"));
2707 $$ = SCM_UNSPECIFIED;
2708 } else if (!SCM_UNBNDP ($1))
2710 unsmob_music ($$)->set_property ("direction", $1);
2714 if (!parser->lexer_->is_lyric_state ())
2715 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2716 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2719 if (!parser->lexer_->is_lyric_state ())
2720 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2721 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2723 | script_dir direction_reqd_event {
2724 if (!SCM_UNBNDP ($1))
2726 Music *m = unsmob_music ($2);
2727 m->set_property ("direction", $1);
2731 | script_dir direction_less_event {
2732 if (!SCM_UNBNDP ($1))
2734 Music *m = unsmob_music ($2);
2735 m->set_property ("direction", $1);
2742 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2747 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2758 string_number_event:
2760 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2761 s->set_property ("string-number", $1);
2762 $$ = s->unprotect ();
2766 direction_less_event:
2768 | EVENT_IDENTIFIER {
2772 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2773 a->set_property ("tremolo-type", $1);
2774 $$ = a->unprotect ();
2776 | event_function_event
2779 direction_reqd_event:
2783 | script_abbreviation {
2784 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2785 if (scm_is_string (s)) {
2786 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2787 a->set_property ("articulation-type", s);
2788 $$ = a->unprotect ();
2790 Music *original = unsmob_music (s);
2791 if (original && original->is_mus_type ("post-event")) {
2792 Music *a = original->clone ();
2793 a->set_spot (parser->lexer_->override_input (@$));
2794 $$ = a->unprotect ();
2796 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2797 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2804 /**/ { $$ = SCM_EOL; }
2805 | '=' quotes { $$ = $2; }
2819 $$ = scm_from_int (1);
2822 $$ = scm_oneplus ($1);
2828 $$ = scm_from_int (-1);
2831 $$ = scm_oneminus ($1);
2836 NOTENAME_PITCH quotes {
2837 if (!scm_is_eq (SCM_INUM0, $2))
2839 Pitch p = *unsmob_pitch ($1);
2840 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2841 $$ = p.smobbed_copy ();
2851 TONICNAME_PITCH quotes {
2852 if (!scm_is_eq (SCM_INUM0, $2))
2854 Pitch p = *unsmob_pitch ($1);
2855 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2856 $$ = p.smobbed_copy ();
2863 | PITCH_IDENTIFIER quotes {
2864 if (!scm_is_eq (SCM_INUM0, $2))
2866 Pitch p = *unsmob_pitch ($1);
2867 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2868 $$ = p.smobbed_copy ();
2875 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2876 t->set_property ("text", $1);
2877 $$ = t->unprotect ();
2880 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2881 t->set_property ("text",
2882 make_simple_markup ($1));
2883 $$ = t->unprotect ();
2887 Music *m = unsmob_music ($1);
2888 if (m && m->is_mus_type ("post-event"))
2890 else if (Text_interface::is_markup ($1)) {
2891 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2892 t->set_property ("text", $1);
2893 $$ = t->unprotect ();
2895 parser->parser_error (@1, _ ("not an articulation"));
2901 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2902 t->set_property ("digit", $1);
2903 $$ = t->unprotect ();
2907 script_abbreviation:
2909 $$ = scm_from_locale_string ("Hat");
2912 $$ = scm_from_locale_string ("Plus");
2915 $$ = scm_from_locale_string ("Dash");
2918 $$ = scm_from_locale_string ("Bang");
2921 $$ = scm_from_locale_string ("Larger");
2924 $$ = scm_from_locale_string ("Dot");
2927 $$ = scm_from_locale_string ("Underscore");
2932 '_' { $$ = scm_from_int (DOWN); }
2933 | '^' { $$ = scm_from_int (UP); }
2934 | '-' { $$ = SCM_UNDEFINED; }
2938 multiplied_duration {
2943 maybe_notemode_duration:
2947 | multiplied_duration {
2949 parser->default_duration_ = *unsmob_duration ($$);
2954 optional_notemode_duration:
2955 maybe_notemode_duration
2957 if (SCM_UNBNDP ($$))
2958 $$ = parser->default_duration_.smobbed_copy ();
2964 $$ = make_duration ($1, scm_to_int ($2));
2965 if (SCM_UNBNDP ($$))
2967 parser->parser_error (@1, _ ("not a duration"));
2968 $$ = Duration ().smobbed_copy ();
2971 | DURATION_IDENTIFIER dots {
2972 Duration *d = unsmob_duration ($1);
2973 Duration k (d->duration_log (),
2974 d->dot_count () + scm_to_int ($2));
2975 k = k.compressed (d->factor ());
2976 scm_remember_upto_here_1 ($1);
2977 $$ = k.smobbed_copy ();
2981 multiplied_duration:
2985 | multiplied_duration '*' UNSIGNED {
2986 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2988 | multiplied_duration '*' FRACTION {
2989 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2991 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
3000 $$ = scm_oneplus ($1);
3006 $$ = scm_from_int (parser->default_tremolo_type_);
3009 if (SCM_UNBNDP (make_duration ($2))) {
3010 parser->parser_error (@2, _ ("not a duration"));
3011 $$ = scm_from_int (parser->default_tremolo_type_);
3014 parser->default_tremolo_type_ = scm_to_int ($2);
3020 UNSIGNED { $$ = $1; }
3021 | STRING { $$ = $1; }
3022 | full_markup { $$ = $1; }
3025 // as an integer, it needs to be non-negative, and otherwise
3026 // it needs to be suitable as a markup.
3027 if (scm_is_integer ($1)
3028 ? scm_is_true (scm_negative_p ($1))
3029 : !Text_interface::is_markup ($1))
3031 parser->parser_error (@1, _ ("bass number expected"));
3037 figured_bass_alteration:
3038 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3039 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3040 | '!' { $$ = scm_from_int (0); }
3045 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3046 $$ = bfr->unprotect ();
3049 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3050 $$ = bfr->self_scm ();
3052 if (scm_is_number ($1))
3053 bfr->set_property ("figure", $1);
3054 else if (Text_interface::is_markup ($1))
3055 bfr->set_property ("text", $1);
3061 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3063 | bass_figure figured_bass_alteration {
3064 Music *m = unsmob_music ($1);
3065 if (scm_to_double ($2)) {
3066 SCM salter = m->get_property ("alteration");
3067 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3068 m->set_property ("alteration",
3069 scm_sum (alter, $2));
3071 m->set_property ("alteration", scm_from_int (0));
3074 | bass_figure figured_bass_modification {
3075 Music *m = unsmob_music ($1);
3076 m->set_property ($2, SCM_BOOL_T);
3081 figured_bass_modification:
3083 $$ = ly_symbol2scm ("augmented");
3086 $$ = ly_symbol2scm ("no-continuation");
3089 $$ = ly_symbol2scm ("diminished");
3092 $$ = ly_symbol2scm ("augmented-slash");
3102 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3110 | figure_list br_bass_figure {
3111 $$ = scm_cons ($2, $1);
3116 FIGURE_OPEN figure_list FIGURE_CLOSE {
3117 $$ = scm_reverse_x ($2, SCM_EOL);
3123 /**/ { $$ = SCM_BOOL_F; }
3124 | REST { $$ = SCM_BOOL_T; }
3128 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3129 if (!parser->lexer_->is_note_state ())
3130 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3131 if (!SCM_UNBNDP ($2)
3133 || scm_is_number ($4)
3136 || scm_is_pair ($7))
3139 if (scm_is_true ($6))
3140 n = MY_MAKE_MUSIC ("RestEvent", @$);
3142 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3144 n->set_property ("pitch", $1);
3145 if (SCM_UNBNDP ($5))
3146 n->set_property ("duration",
3147 parser->default_duration_.smobbed_copy ());
3149 n->set_property ("duration", $5);
3151 if (scm_is_number ($4))
3153 int q = scm_to_int ($4);
3154 n->set_property ("absolute-octave", scm_from_int (q-1));
3157 if (to_boolean ($3))
3158 n->set_property ("cautionary", SCM_BOOL_T);
3159 if (to_boolean ($2) || to_boolean ($3))
3160 n->set_property ("force-accidental", SCM_BOOL_T);
3161 if (scm_is_pair ($7))
3162 n->set_property ("articulations",
3163 scm_reverse_x ($7, SCM_EOL));
3164 $$ = n->unprotect ();
3167 | simple_chord_elements post_events {
3168 if (scm_is_pair ($2)) {
3169 if (unsmob_pitch ($1))
3170 $1 = make_chord_elements (@1,
3172 parser->default_duration_.smobbed_copy (),
3175 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3177 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
3178 } else if (!unsmob_pitch ($1))
3179 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
3180 // A mere pitch drops through.
3185 DRUM_PITCH optional_notemode_duration {
3186 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3187 n->set_property ("duration", $2);
3188 n->set_property ("drum-type", $1);
3190 $$ = n->unprotect ();
3192 | RESTNAME optional_notemode_duration {
3194 if (ly_scm2string ($1) == "s") {
3196 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3199 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3202 ev->set_property ("duration", $2);
3203 $$ = ev->unprotect ();
3207 // Can return a single pitch rather than a list.
3208 simple_chord_elements:
3210 if (!parser->lexer_->is_chord_state ())
3211 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3214 | figure_spec optional_notemode_duration {
3215 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3217 unsmob_music (scm_car (s))->set_property ("duration", $2);
3225 if (!parser->lexer_->is_lyric_state ())
3226 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3230 if (!parser->lexer_->is_lyric_state ())
3231 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3237 lyric_element_music:
3238 lyric_element optional_notemode_duration post_events {
3239 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3240 if (scm_is_pair ($3))
3241 unsmob_music ($$)->set_property
3242 ("articulations", scm_reverse_x ($3, SCM_EOL));
3246 // Can return a single pitch rather than a list.
3248 steno_tonic_pitch maybe_notemode_duration {
3249 if (SCM_UNBNDP ($2))
3252 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3254 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3255 SCM its = scm_reverse_x ($4, SCM_EOL);
3256 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3264 | chord_items chord_item {
3265 $$ = scm_cons ($2, $$);
3271 $$ = ly_symbol2scm ("chord-colon");
3274 $$ = ly_symbol2scm ("chord-caret");
3276 | CHORD_SLASH steno_tonic_pitch {
3277 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3279 | CHORD_BASS steno_tonic_pitch {
3280 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3289 $$ = scm_reverse_x ($1, SCM_EOL);
3297 step_number { $$ = scm_cons ($1, SCM_EOL); }
3298 | step_numbers '.' step_number {
3299 $$ = scm_cons ($3, $$);
3305 $$ = make_chord_step ($1, 0);
3308 $$ = make_chord_step ($1, SHARP_ALTERATION);
3310 | UNSIGNED CHORD_MINUS {
3311 $$ = make_chord_step ($1, FLAT_ALTERATION);
3319 | unsigned_number '-' unsigned_number {
3320 $$ = scm_cons ($1, $3);
3327 TODO: should deprecate in favor of Scheme?
3331 number_expression '+' number_term {
3332 $$ = scm_sum ($1, $3);
3334 | number_expression '-' number_term {
3335 $$ = scm_difference ($1, $3);
3344 | number_factor '*' number_factor {
3345 $$ = scm_product ($1, $3);
3347 | number_factor '/' number_factor {
3348 $$ = scm_divide ($1, $3);
3353 '-' number_factor { /* %prec UNARY_MINUS */
3354 $$ = scm_difference ($2, SCM_UNDEFINED);
3362 | REAL NUMBER_IDENTIFIER
3364 $$ = scm_product ($1, $2);
3371 | UNSIGNED NUMBER_IDENTIFIER {
3372 $$ = scm_product ($1, $2);
3380 if (!scm_is_integer ($1)
3381 || scm_is_true (scm_negative_p ($1)))
3383 parser->parser_error (@1, _("not an unsigned integer"));
3389 if (!scm_is_integer ($1)
3390 || scm_is_true (scm_negative_p ($1)))
3392 parser->parser_error (@1, _("not an unsigned integer"));
3399 { $$ = SCM_UNDEFINED; }
3402 if (SCM_UNBNDP ($1))
3410 // This precedence rule is rather weird. It triggers when '!' is
3411 // encountered after a pitch, and is used for deciding whether to save
3412 // this instead for a figure modification. This should not actually
3413 // occur in practice as pitches and figures are generated in different
3414 // modes. Using a greedy (%right) precedence makes sure that we don't
3415 // get stuck in a wrong interpretation.
3416 { $$ = SCM_UNDEFINED; } %prec ':'
3419 if (SCM_UNBNDP ($1))
3428 { parser->lexer_->push_markup_state (); }
3431 parser->lexer_->pop_state ();
3437 { parser->lexer_->push_markup_state (); }
3440 parser->lexer_->pop_state ();
3446 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3448 | markup_head_1_list simple_markup
3450 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3451 @2, $1, scm_list_1 ($2)));
3461 if (Text_interface::is_markup ($1))
3462 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3463 else if (Text_interface::is_markup_list ($1))
3464 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3466 parser->parser_error (@1, _ ("not a markup"));
3467 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3474 markup_composed_list {
3477 | markup_uncomposed_list
3480 markup_uncomposed_list:
3481 markup_braced_list {
3484 | markup_command_list {
3485 $$ = scm_list_1 ($1);
3487 | markup_scm MARKUPLIST_IDENTIFIER
3492 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3493 parser->lexer_->push_note_state (nn);
3494 } '{' score_body '}' {
3495 Score *sc = unsmob_score ($4);
3496 sc->origin ()->set_spot (@$);
3497 if (sc->defs_.empty ()) {
3498 Output_def *od = get_layout (parser);
3499 sc->add_output_def (od);
3502 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3503 parser->lexer_->pop_state ();
3507 markup_composed_list:
3508 markup_head_1_list markup_uncomposed_list {
3509 $$ = MAKE_SYNTAX ("composed-markup-list",
3515 '{' markup_braced_list_body '}' {
3516 $$ = scm_reverse_x ($2, SCM_EOL);
3520 markup_braced_list_body:
3521 /* empty */ { $$ = SCM_EOL; }
3522 | markup_braced_list_body markup {
3523 $$ = scm_cons ($2, $1);
3525 | markup_braced_list_body markup_list {
3526 $$ = scm_reverse_x ($2, $1);
3530 markup_command_list:
3531 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3532 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3536 markup_command_basic_arguments:
3537 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3538 $$ = scm_cons ($3, $2);
3540 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3541 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3543 | EXPECT_NO_MORE_ARGS {
3548 markup_command_list_arguments:
3549 markup_command_basic_arguments { $$ = $1; }
3550 | EXPECT_MARKUP markup_command_list_arguments markup {
3551 $$ = scm_cons ($3, $2);
3556 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3557 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3562 markup_head_1_item {
3563 $$ = scm_list_1 ($1);
3565 | markup_head_1_list markup_head_1_item {
3566 $$ = scm_cons ($2, $1);
3572 $$ = make_simple_markup ($1);
3575 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3576 parser->lexer_->push_note_state (nn);
3577 } '{' score_body '}' {
3578 Score *sc = unsmob_score ($4);
3579 sc->origin ()->set_spot (@$);
3580 if (sc->defs_.empty ()) {
3581 Output_def *od = get_layout (parser);
3582 sc->add_output_def (od);
3585 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3586 parser->lexer_->pop_state ();
3588 | MARKUP_FUNCTION markup_command_basic_arguments {
3589 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3591 | markup_scm MARKUP_IDENTIFIER
3598 markup_head_1_list simple_markup
3600 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3601 @2, $1, scm_list_1 ($2)));
3611 Lily_parser::set_yydebug (bool x)
3617 Lily_parser::do_yyparse ()
3619 SCM retval = SCM_UNDEFINED;
3620 yyparse (this, &retval);
3630 It is a little strange to have this function in this file, but
3631 otherwise, we have to import music classes into the lexer.
3635 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3637 if (unsmob_book (sid)) {
3638 Book *book = unsmob_book (sid)->clone ();
3639 *destination = book->self_scm ();
3642 return BOOK_IDENTIFIER;
3643 } else if (scm_is_number (sid)) {
3645 return NUMBER_IDENTIFIER;
3646 } else if (unsmob_context_def (sid))
3648 *destination = unsmob_context_def (sid)->clone ()->unprotect ();
3649 return SCM_IDENTIFIER;
3650 } else if (unsmob_context_mod (sid)) {
3651 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3652 return CONTEXT_MOD_IDENTIFIER;
3653 } else if (Music *mus = unsmob_music (sid)) {
3654 mus = mus->clone ();
3655 *destination = mus->self_scm ();
3656 bool is_event = mus->is_mus_type ("post-event");
3658 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3659 } else if (unsmob_pitch (sid)) {
3660 *destination = unsmob_pitch (sid)->smobbed_copy ();
3661 return PITCH_IDENTIFIER;
3662 } else if (unsmob_duration (sid)) {
3663 *destination = unsmob_duration (sid)->smobbed_copy ();
3664 return DURATION_IDENTIFIER;
3665 } else if (unsmob_output_def (sid)) {
3666 *destination = unsmob_output_def (sid)->clone ()->unprotect ();
3667 return SCM_IDENTIFIER;
3668 } else if (unsmob_score (sid)) {
3669 *destination = unsmob_score (sid)->clone ()->unprotect ();
3670 return SCM_IDENTIFIER;
3677 get_next_unique_context_id ()
3679 return scm_from_locale_string ("$uniqueContextId");
3684 get_next_unique_lyrics_context_id ()
3686 static int new_context_count;
3688 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3689 return scm_from_locale_string (s);
3692 // check_scheme_arg checks one argument with a given predicate for use
3693 // in an argument list and throws a syntax error if it is unusable.
3694 // The argument is prepended to the argument list in any case. After
3695 // throwing a syntax error, the argument list is terminated with #f as
3696 // its last cdr in order to mark it as uncallable while not losing
3697 // track of its total length.
3699 // There are a few special considerations: if optional argument disp
3700 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3701 // instead of arg in a prospective error message. This is useful if
3702 // arg is not the actual argument but rather a transformation of it.
3704 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3705 // and an error message using disp is produced unconditionally.
3707 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3708 SCM arg, SCM args, SCM pred, SCM disp)
3710 if (SCM_UNBNDP (arg))
3711 args = scm_cons (disp, args);
3713 args = scm_cons (arg, args);
3714 if (scm_is_true (scm_call_1 (pred, arg)))
3717 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3718 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3719 SCM_UNBNDP (disp) ? arg : disp);
3720 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3724 SCM loc_on_music (Input loc, SCM arg)
3726 if (Music *m = unsmob_music (arg))
3730 return m->unprotect ();
3736 try_string_variants (SCM pred, SCM str)
3738 // a matching predicate is always ok
3739 if (scm_is_true (scm_call_1 (pred, str)))
3741 // a symbol may be interpreted as a list of symbols if it helps
3742 if (scm_is_symbol (str)) {
3743 str = scm_list_1 (str);
3744 if (scm_is_true (scm_call_1 (pred, str)))
3746 return SCM_UNDEFINED;
3749 // If this cannot be a string representation of a symbol list,
3752 if (!is_regular_identifier (str, true))
3753 return SCM_UNDEFINED;
3755 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3756 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3757 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3759 // Let's attempt the symbol list interpretation first.
3761 if (scm_is_true (scm_call_1 (pred, str)))
3764 // If there is just one symbol in the list, we might interpret
3765 // it as a single symbol
3767 if (scm_is_null (scm_cdr (str)))
3769 str = scm_car (str);
3770 if (scm_is_true (scm_call_1 (pred, str)))
3774 return SCM_UNDEFINED;
3778 is_regular_identifier (SCM id, bool multiple)
3780 if (!scm_is_string (id))
3783 string str = ly_scm2string (id);
3785 bool middle = false;
3787 for (string::iterator it=str.begin(); it != str.end (); it++)
3790 if ((c >= 'a' && c <= 'z')
3791 || (c >= 'A' && c <= 'Z')
3794 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3803 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3805 if (unsmob_music (simple))
3807 if (parser->lexer_->is_note_state ()) {
3808 if (scm_is_symbol (simple)) {
3809 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3810 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3811 n->set_property ("drum-type", simple);
3812 return n->unprotect ();
3814 if (unsmob_pitch (simple)) {
3815 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3816 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3817 n->set_property ("pitch", simple);
3818 return n->unprotect ();
3821 } else if (parser->lexer_->is_lyric_state ()) {
3822 if (Text_interface::is_markup (simple))
3823 return MAKE_SYNTAX ("lyric-event", loc, simple,
3824 parser->default_duration_.smobbed_copy ());
3825 } else if (parser->lexer_->is_chord_state ()) {
3826 if (unsmob_pitch (simple))
3830 make_chord_elements (loc, simple,
3831 parser->default_duration_.smobbed_copy (),
3838 make_music_with_input (SCM name, Input where)
3840 Music *m = make_music_by_name (name);
3841 m->set_spot (where);
3846 make_simple_markup (SCM a)
3852 make_duration (SCM d, int dots)
3854 int t = scm_to_int (d);
3855 if (t > 0 && (t & (t-1)) == 0)
3856 return Duration (intlog2 (t), dots).smobbed_copy ();
3858 return SCM_UNDEFINED;
3862 make_chord_step (SCM step_scm, Rational alter)
3864 int step = scm_to_int (step_scm);
3867 alter += FLAT_ALTERATION;
3871 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3872 return m.smobbed_copy ();
3877 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3879 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3880 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3881 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3883 unsmob_music (scm_car (s))->set_spot (loc);
3889 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3891 Lily_lexer *lex = parser->lexer_;
3895 int tok = lex->pop_extra_token ();
3898 lex->prepare_for_next_token ();
3899 return lex->yylex ();