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 (),
1488 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1490 $$ = check_scheme_arg (parser, @4,
1491 scm_difference ($5, SCM_UNDEFINED),
1494 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1496 $$ = check_scheme_arg (parser, @4,
1497 scm_difference ($5, SCM_UNDEFINED),
1500 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1502 if (scm_is_true (scm_call_1 ($2, $4)))
1503 $$ = scm_cons ($4, $3);
1505 $$ = check_scheme_arg (parser, @4,
1506 make_music_from_simple
1510 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1512 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1514 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1516 if (scm_is_true (scm_call_1 ($2, $3)))
1517 $$ = scm_cons ($3, $1);
1519 $$ = check_scheme_arg (parser, @3,
1520 make_music_from_simple
1524 | function_arglist_nonbackup_reparse REPARSE duration_length
1526 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1528 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1530 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1532 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1534 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1536 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1538 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1540 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1542 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1546 function_arglist_nonbackup_reparse:
1547 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1550 SCM res = try_string_variants ($2, $4);
1551 if (!SCM_UNBNDP (res))
1552 if (scm_is_pair (res))
1553 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1555 MYREPARSE (@4, $2, SCM_ARG, res);
1556 else if (scm_is_true
1558 ($2, make_music_from_simple
1560 MYREPARSE (@4, $2, STRING, $4);
1562 MYREPARSE (@4, $2, SCM_ARG, $4);
1564 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1569 ($2, make_music_from_simple
1571 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1573 MYREPARSE (@4, $2, SCM_ARG, $4);
1575 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1580 ($2, make_music_from_simple
1582 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1584 MYREPARSE (@4, $2, SCM_ARG, $4);
1586 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1589 SCM res = try_string_variants ($2, $4);
1590 if (!SCM_UNBNDP (res))
1591 if (scm_is_pair (res))
1592 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1594 MYREPARSE (@4, $2, SCM_ARG, res);
1595 else if (scm_is_true
1597 ($2, make_music_from_simple
1599 MYREPARSE (@4, $2, STRING, $4);
1601 MYREPARSE (@4, $2, SCM_ARG, $4);
1603 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1606 if (scm_is_true (scm_call_1 ($2, $4)))
1607 MYREPARSE (@4, $2, SCM_ARG, $4);
1608 else if (scm_is_true
1610 ($2, make_music_from_simple
1612 MYREPARSE (@4, $2, STRING, $4);
1614 MYREPARSE (@4, $2, SCM_ARG, $4);
1616 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1619 if (scm_is_true (scm_call_1 ($2, $4)))
1620 MYREPARSE (@4, $2, REAL, $4);
1622 SCM d = make_duration ($4);
1623 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1624 MYREPARSE (@4, $2, REAL, $4); // trigger error
1626 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1629 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1631 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1636 // function_arglist_backup can't occur at the end of an argument
1638 function_arglist_backup:
1639 function_arglist_common
1640 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1642 if (scm_is_true (scm_call_1 ($2, $4)))
1643 $$ = scm_cons ($4, $3);
1645 $$ = make_music_from_simple (parser, @4, $4);
1646 if (scm_is_true (scm_call_1 ($2, $$)))
1647 $$ = scm_cons ($$, $3);
1650 $$ = scm_cons (loc_on_music (@3, $1), $3);
1651 MYBACKUP (SCM_ARG, $4, @4);
1655 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1657 if (scm_is_true (scm_call_1 ($2, $4)))
1659 $$ = scm_cons ($4, $3);
1661 $$ = scm_cons (loc_on_music (@3, $1), $3);
1662 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1665 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1669 ($2, make_music_from_simple
1673 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1674 } else if (scm_is_true (scm_call_1 ($2, $4)))
1675 $$ = scm_cons ($4, $3);
1677 $$ = scm_cons (loc_on_music (@3, $1), $3);
1678 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1681 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1685 ($2, make_music_from_simple
1689 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1690 } else if (scm_is_true (scm_call_1 ($2, $4)))
1691 $$ = scm_cons ($4, $3);
1693 $$ = scm_cons (loc_on_music (@3, $1), $3);
1694 MYBACKUP (TONICNAME_PITCH, $4, @4);
1697 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1699 if (scm_is_true (scm_call_1 ($2, $4)))
1700 $$ = scm_cons ($4, $3);
1702 $$ = scm_cons (loc_on_music (@3, $1), $3);
1703 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1706 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1708 if (scm_is_true (scm_call_1 ($2, $4)))
1710 MYREPARSE (@4, $2, REAL, $4);
1713 SCM d = make_duration ($4);
1714 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1716 $$ = scm_cons (loc_on_music (@3, $1), $3);
1717 MYBACKUP (UNSIGNED, $4, @4);
1719 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1724 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1726 if (scm_is_true (scm_call_1 ($2, $4)))
1729 MYREPARSE (@4, $2, REAL, $4);
1731 $$ = scm_cons (loc_on_music (@3, $1), $3);
1732 MYBACKUP (REAL, $4, @4);
1735 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1737 if (scm_is_true (scm_call_1 ($2, $4)))
1739 $$ = scm_cons ($4, $3);
1741 $$ = scm_cons (loc_on_music (@3, $1), $3);
1742 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1745 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1747 SCM n = scm_difference ($5, SCM_UNDEFINED);
1748 if (scm_is_true (scm_call_1 ($2, n))) {
1750 MYREPARSE (@5, $2, REAL, n);
1752 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1753 t->set_property ("digit", $5);
1754 $$ = t->unprotect ();
1755 if (scm_is_true (scm_call_1 ($2, $$)))
1756 $$ = scm_cons ($$, $3);
1758 $$ = scm_cons (loc_on_music (@3, $1), $3);
1759 MYBACKUP (UNSIGNED, $5, @5);
1760 parser->lexer_->push_extra_token (@4, '-');
1765 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1767 SCM n = scm_difference ($5, SCM_UNDEFINED);
1768 if (scm_is_true (scm_call_1 ($2, n))) {
1769 MYREPARSE (@5, $2, REAL, n);
1772 $$ = scm_cons (loc_on_music (@3, $1), $3);
1773 MYBACKUP (REAL, n, @5);
1776 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1778 SCM n = scm_difference ($5, SCM_UNDEFINED);
1779 if (scm_is_true (scm_call_1 ($2, n))) {
1780 $$ = scm_cons (n, $3);
1782 $$ = scm_cons (loc_on_music (@3, $1), $3);
1783 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1786 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1788 if (scm_is_true (scm_call_1 ($2, $4)))
1790 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1793 $$ = scm_cons (loc_on_music (@3, $1), $3);
1794 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1797 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1799 SCM res = try_string_variants ($2, $4);
1800 if (!SCM_UNBNDP (res))
1801 if (scm_is_pair (res)) {
1803 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1806 $$ = scm_cons (res, $3);
1808 $$ = scm_cons (loc_on_music (@3, $1), $3);
1809 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1812 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1814 SCM res = try_string_variants ($2, $4);
1815 if (!SCM_UNBNDP (res))
1816 if (scm_is_pair (res)) {
1818 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1821 $$ = scm_cons (res, $3);
1823 $$ = scm_cons (loc_on_music (@3, $1), $3);
1824 MYBACKUP (STRING, $4, @4);
1827 | function_arglist_backup REPARSE pitch_or_music
1829 if (scm_is_true (scm_call_1 ($2, $3)))
1830 $$ = scm_cons ($3, $1);
1832 $$ = check_scheme_arg (parser, @3,
1833 make_music_from_simple
1837 | function_arglist_backup REPARSE bare_number_common
1839 $$ = check_scheme_arg (parser, @3,
1842 | function_arglist_backup REPARSE duration_length
1844 $$ = check_scheme_arg (parser, @3,
1847 | function_arglist_backup REPARSE symbol_list_arg
1849 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1854 function_arglist_nonbackup
1855 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1857 $$ = scm_cons (loc_on_music (@4, $1), $3);
1861 function_arglist_skip_nonbackup:
1862 function_arglist_nonbackup
1863 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1865 $$ = scm_cons (loc_on_music (@3, $1), $3);
1869 function_arglist_common:
1870 EXPECT_NO_MORE_ARGS {
1873 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1875 if (scm_is_true (scm_call_1 ($1, $3)))
1876 $$ = scm_cons ($3, $2);
1878 $$ = check_scheme_arg (parser, @3,
1879 make_music_from_simple
1883 | EXPECT_SCM function_arglist_optional bare_number_common
1885 $$ = check_scheme_arg (parser, @3,
1888 | EXPECT_SCM function_arglist_optional post_event_nofinger
1890 $$ = check_scheme_arg (parser, @3,
1893 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1895 SCM n = scm_difference ($4, SCM_UNDEFINED);
1896 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1898 | function_arglist_common_reparse REPARSE SCM_ARG
1900 $$ = check_scheme_arg (parser, @3,
1903 | function_arglist_common_reparse REPARSE lyric_element_music
1905 $$ = check_scheme_arg (parser, @3,
1908 | function_arglist_common_reparse REPARSE pitch_or_music
1910 if (scm_is_true (scm_call_1 ($2, $3)))
1911 $$ = scm_cons ($3, $1);
1913 $$ = check_scheme_arg (parser, @3,
1914 make_music_from_simple
1918 | function_arglist_common_reparse REPARSE bare_number_common
1920 $$ = check_scheme_arg (parser, @3,
1923 | function_arglist_common_reparse REPARSE duration_length
1925 $$ = check_scheme_arg (parser, @3,
1928 | function_arglist_common_reparse REPARSE symbol_list_arg
1930 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1934 function_arglist_common_reparse:
1935 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1938 SCM res = try_string_variants ($1, $3);
1939 if (!SCM_UNBNDP (res))
1940 if (scm_is_pair (res))
1941 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1943 MYREPARSE (@3, $1, SCM_ARG, res);
1944 else if (scm_is_true
1946 ($1, make_music_from_simple (parser, @3, $3))))
1947 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1949 // This is going to flag a syntax error, we
1950 // know the predicate to be false.
1951 MYREPARSE (@3, $1, SCM_ARG, $3);
1953 | EXPECT_SCM function_arglist_optional pitch
1958 ($1, make_music_from_simple
1960 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
1962 MYREPARSE (@3, $1, SCM_ARG, $3);
1964 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
1969 ($1, make_music_from_simple
1971 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
1973 MYREPARSE (@3, $1, SCM_ARG, $3);
1975 | EXPECT_SCM function_arglist_optional STRING
1978 SCM res = try_string_variants ($1, $3);
1979 if (!SCM_UNBNDP (res))
1980 if (scm_is_pair (res))
1981 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1983 MYREPARSE (@3, $1, SCM_ARG, res);
1984 else if (scm_is_true
1986 ($1, make_music_from_simple (parser, @3, $3))))
1987 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1989 // This is going to flag a syntax error, we
1990 // know the predicate to be false.
1991 MYREPARSE (@3, $1, SCM_ARG, $3);
1993 | EXPECT_SCM function_arglist_optional full_markup
1996 if (scm_is_true (scm_call_1 ($1, $3)))
1997 MYREPARSE (@3, $1, SCM_ARG, $3);
1998 else if (scm_is_true
2000 ($1, make_music_from_simple (parser, @3, $3))))
2001 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2003 // This is going to flag a syntax error, we
2004 // know the predicate to be false.
2005 MYREPARSE (@3, $1, SCM_ARG, $3);
2007 | EXPECT_SCM function_arglist_optional UNSIGNED
2010 if (scm_is_true (scm_call_1 ($1, $3)))
2011 MYREPARSE (@3, $1, REAL, $3);
2013 SCM d = make_duration ($3);
2014 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
2015 MYREPARSE (@3, $1, REAL, $3);
2017 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2020 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2023 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2025 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2028 SCM n = scm_difference ($4, SCM_UNDEFINED);
2029 if (scm_is_true (scm_call_1 ($1, n)))
2030 MYREPARSE (@4, $1, REAL, n);
2032 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2033 t->set_property ("digit", $4);
2034 SCM m = t->unprotect ();
2035 if (scm_is_true (scm_call_1 ($1, m)))
2036 MYREPARSE (@4, $1, SCM_ARG, m);
2038 MYREPARSE (@4, $1, SCM_ARG, $4);
2042 | EXPECT_SCM function_arglist_optional '-' REAL
2045 SCM n = scm_difference ($4, SCM_UNDEFINED);
2046 MYREPARSE (@4, $1, REAL, n);
2050 function_arglist_optional:
2051 function_arglist_backup
2052 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2054 $$ = scm_cons (loc_on_music (@4, $1), $3);
2056 | function_arglist_skip_backup BACKUP
2059 function_arglist_skip_backup:
2060 function_arglist_backup
2061 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2063 $$ = scm_cons (loc_on_music (@3, $1), $3);
2067 music_function_call:
2068 MUSIC_FUNCTION function_arglist {
2069 $$ = MAKE_SYNTAX ("music-function", @$,
2076 /**/ { $$ = SCM_EOL; }
2077 | '=' simple_string {
2082 // We must not have lookahead tokens parsed in lyric mode. In order
2083 // to save confusion, we take almost the same set as permitted with
2084 // \lyricmode and/or \lyrics. However, music identifiers are also
2085 // allowed, and they obviously do not require switching into lyrics
2086 // mode for parsing.
2090 parser->lexer_->push_lyric_state ();
2091 } grouped_music_list
2093 parser->lexer_->pop_state ();
2101 | repeated_music { $$ = $1; }
2102 | re_rhythmed_music { $$ = $1; }
2103 | complex_music_prefix music
2105 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2109 complex_music_prefix:
2110 CONTEXT symbol optional_id optional_context_mod {
2111 Context_mod *ctxmod = unsmob_context_mod ($4);
2114 mods = ctxmod->get_mods ();
2115 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2117 | NEWCONTEXT symbol optional_id optional_context_mod {
2118 Context_mod *ctxmod = unsmob_context_mod ($4);
2121 mods = ctxmod->get_mods ();
2122 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2127 mode_changing_head grouped_music_list {
2128 if ($1 == ly_symbol2scm ("chords"))
2130 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2136 parser->lexer_->pop_state ();
2138 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2139 Context_mod *ctxmod = unsmob_context_mod ($2);
2142 mods = ctxmod->get_mods ();
2143 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2144 if ($1 == ly_symbol2scm ("ChordNames"))
2146 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2148 parser->lexer_->pop_state ();
2154 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2155 parser->lexer_->push_note_state (nn);
2157 $$ = ly_symbol2scm ("notes");
2161 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2162 parser->lexer_->push_note_state (nn);
2164 $$ = ly_symbol2scm ("drums");
2167 parser->lexer_->push_figuredbass_state ();
2169 $$ = ly_symbol2scm ("figures");
2172 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2173 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2174 nn = parser->lexer_->lookup_identifier ("pitchnames");
2175 parser->lexer_->push_chord_state (nn);
2176 $$ = ly_symbol2scm ("chords");
2180 { parser->lexer_->push_lyric_state ();
2181 $$ = ly_symbol2scm ("lyrics");
2185 mode_changing_head_with_context:
2187 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2188 parser->lexer_->push_note_state (nn);
2190 $$ = ly_symbol2scm ("DrumStaff");
2193 parser->lexer_->push_figuredbass_state ();
2195 $$ = ly_symbol2scm ("FiguredBass");
2198 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2199 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2200 nn = parser->lexer_->lookup_identifier ("pitchnames");
2201 parser->lexer_->push_chord_state (nn);
2202 $$ = ly_symbol2scm ("ChordNames");
2205 { parser->lexer_->push_lyric_state ();
2206 $$ = ly_symbol2scm ("Lyrics");
2211 ADDLYRICS lyric_mode_music {
2212 $$ = scm_list_1 ($2);
2214 | new_lyrics ADDLYRICS lyric_mode_music {
2215 $$ = scm_cons ($3, $1);
2220 composite_music new_lyrics {
2221 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2223 | LYRICSTO simple_string lyric_mode_music {
2224 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $3);
2229 CHANGE symbol '=' simple_string {
2230 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2237 $$ = scm_reverse_x ($1, SCM_EOL);
2239 | symbol_list_rev property_path {
2240 $$ = scm_reverse_x ($1, $2);
2246 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2249 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2251 | OVERRIDE property_path '=' scalar {
2252 if (scm_ilength ($2) < 2) {
2253 parser->parser_error (@2, _("bad grob property path"));
2256 $$ = scm_cons (ly_symbol2scm ("push"),
2257 scm_cons2 (scm_car ($2),
2262 | REVERT revert_arg {
2263 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2267 // This is all quite awkward for the sake of substantial backward
2268 // compatibility while at the same time allowing a more "natural" form
2269 // of specification not separating grob specification from grob
2270 // property path. The purpose of this definition of revert_arg is to
2271 // allow the symbol list which specifies grob and property to revert
2272 // to be optionally be split into two parts after the grob (which in
2273 // this case is just the first element of the list). symbol_list_part
2274 // is only one path component, but it can be parsed without lookahead,
2275 // so we can follow it with a synthetic BACKUP token when needed. If
2276 // the first symbol_list_part already contains multiple elements (only
2277 // possible if a Scheme expression provides them), we just parse for
2278 // additional elements introduced by '.', which is what the
2279 // SYMBOL_LIST backup in connection with the immediately following
2280 // rule using symbol_list_arg does.
2282 // As long as we don't have our coffers filled with both grob and at
2283 // least one grob property specification, the rest of the required
2284 // symbol list chain may be provided either with or without a leading
2285 // dot. This is for both allowing the traditional
2286 // \revert Accidental #'color
2287 // as well as well as the "naive" form
2288 // \revert Accidental.color
2291 revert_arg_backup BACKUP symbol_list_arg
2300 if (scm_is_null ($1)
2301 || scm_is_null (scm_cdr ($1)))
2302 MYBACKUP (SCM_ARG, $1, @1);
2304 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2308 // revert_arg_part delivers results in reverse
2311 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2313 $$ = scm_append_x (scm_list_2 ($5, $3));
2315 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2317 $$ = scm_append_x (scm_list_2 ($4, $3));
2322 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2323 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2325 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2326 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2327 | DENIES { $$ = ly_symbol2scm ("denies"); }
2329 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2330 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2331 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2332 | NAME { $$ = ly_symbol2scm ("context-name"); }
2336 property_operation { $$ = $1; }
2337 | context_def_mod STRING {
2338 $$ = scm_list_2 ($1, $2);
2340 | context_def_mod embedded_scm
2342 if (!scm_is_string ($2)
2343 && ly_symbol2scm ("consists") != $1
2344 && ly_symbol2scm ("remove") != $1)
2347 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2351 $$ = scm_list_2 ($1, $2);
2356 // If defined, at least two members.
2360 SCM l = scm_reverse_x ($1, SCM_EOL);
2363 (scm_object_property (scm_car (l),
2364 ly_symbol2scm ("is-grob?"))))
2365 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2366 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2367 parser->parser_error (@1, _ ("bad grob property path"));
2374 // If defined, at least three members
2378 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2380 parser->parser_error (@1, _ ("bad grob property path"));
2384 | grob_prop_spec property_path
2386 if (!SCM_UNBNDP ($1)) {
2387 $$ = scm_append_x (scm_list_2 ($1, $2));
2388 if (scm_is_null (scm_cddr ($$))) {
2389 parser->parser_error (@$, _ ("bad grob property path"));
2397 // Exactly two elements or undefined
2401 SCM l = scm_reverse_x ($1, SCM_EOL);
2402 switch (scm_ilength (l)) {
2404 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2408 parser->parser_error (@1, _ ("bad context property path"));
2415 simple_music_property_def:
2416 OVERRIDE grob_prop_path '=' scalar {
2417 if (SCM_UNBNDP ($2))
2420 $$ = scm_list_5 (scm_car ($2),
2421 ly_symbol2scm ("OverrideProperty"),
2427 | REVERT simple_revert_context revert_arg {
2428 $$ = scm_list_4 ($2,
2429 ly_symbol2scm ("RevertProperty"),
2433 | SET context_prop_spec '=' scalar {
2434 if (SCM_UNBNDP ($2))
2437 $$ = scm_list_4 (scm_car ($2),
2438 ly_symbol2scm ("PropertySet"),
2442 | UNSET context_prop_spec {
2443 if (SCM_UNBNDP ($2))
2446 $$ = scm_list_3 (scm_car ($2),
2447 ly_symbol2scm ("PropertyUnset"),
2453 // This is all quite awkward for the sake of substantial backward
2454 // compatibility while at the same time allowing a more "natural" form
2455 // of specification not separating grob specification from grob
2456 // property path. The purpose of this definition of
2457 // simple_revert_context is to allow the symbol list which specifies
2458 // grob and property to revert to be optionally be split into two
2459 // parts after the grob (which may be preceded by a context
2460 // specification, a case which we distinguish by checking whether the
2461 // first symbol is a valid grob symbol instead).
2463 // See revert_arg above for the main work horse of this arrangement.
2464 // simple_revert_context just caters for the context and delegates the
2465 // rest of the job to revert_arg.
2467 simple_revert_context:
2470 $1 = scm_reverse_x ($1, SCM_EOL);
2471 if (scm_is_null ($1)
2473 (scm_object_property (scm_car ($1),
2474 ly_symbol2scm ("is-grob?")))) {
2475 $$ = ly_symbol2scm ("Bottom");
2476 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2479 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2486 simple_music_property_def {
2487 if (SCM_UNBNDP ($1))
2488 $$ = MAKE_SYNTAX ("void-music", @1);
2490 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2501 simple_string: STRING {
2506 if (scm_is_string ($1)) {
2509 parser->parser_error (@1, (_ ("simple string expected")));
2510 $$ = scm_string (SCM_EOL);
2517 $$ = scm_string_to_symbol ($1);
2521 // This is a bit of overkill but makes the same
2522 // routine responsible for all symbol interpretations.
2523 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2525 if (SCM_UNBNDP ($$))
2527 parser->parser_error (@1, (_ ("symbol expected")));
2528 // Generate a unique symbol in case it is used
2529 // for an assignment or similar
2530 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2540 // The following is a rather defensive variant of admitting
2541 // negative numbers: the grammar would permit number_factor or
2542 // even number_expression. However, function arguments allow
2543 // only this simple kind of negative number, so to have things
2544 // like \tweak and \override behave reasonably similar, it
2545 // makes sense to rule out things like -- which are rather an
2546 // accent in function argument contexts.
2549 $$ = scm_difference ($2, SCM_UNDEFINED);
2555 simple_element post_events {
2556 // Let the rhythmic music iterator sort this mess out.
2557 if (scm_is_pair ($2)) {
2558 unsmob_music ($$)->set_property ("articulations",
2559 scm_reverse_x ($2, SCM_EOL));
2562 | CHORD_REPETITION optional_notemode_duration post_events {
2564 i.set_location (@1, @3);
2565 $$ = MAKE_SYNTAX ("repetition-chord", i,
2566 $2, scm_reverse_x ($3, SCM_EOL));
2568 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2570 i.set_location (@1, @3);
2571 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2572 scm_reverse_x ($3, SCM_EOL));
2575 | note_chord_element
2580 chord_body optional_notemode_duration post_events
2582 Music *m = unsmob_music ($1);
2583 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2584 SCM es = m->get_property ("elements");
2585 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2587 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2588 unsmob_music (scm_car (s))->set_property ("duration", dur);
2589 es = ly_append2 (es, postevs);
2591 m-> set_property ("elements", es);
2593 $$ = m->self_scm ();
2598 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2600 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2604 chord_body_elements:
2605 /* empty */ { $$ = SCM_EOL; }
2606 | chord_body_elements chord_body_element {
2607 if (!SCM_UNBNDP ($2))
2608 $$ = scm_cons ($2, $1);
2613 pitch exclamations questions octave_check post_events
2615 bool q = to_boolean ($3);
2616 bool ex = to_boolean ($2);
2620 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2621 n->set_property ("pitch", $1);
2623 n->set_property ("cautionary", SCM_BOOL_T);
2625 n->set_property ("force-accidental", SCM_BOOL_T);
2627 if (scm_is_pair (post)) {
2628 SCM arts = scm_reverse_x (post, SCM_EOL);
2629 n->set_property ("articulations", arts);
2631 if (scm_is_number (check))
2633 int q = scm_to_int (check);
2634 n->set_property ("absolute-octave", scm_from_int (q-1));
2637 $$ = n->unprotect ();
2639 | DRUM_PITCH post_events {
2640 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2641 n->set_property ("drum-type", $1);
2643 if (scm_is_pair ($2)) {
2644 SCM arts = scm_reverse_x ($2, SCM_EOL);
2645 n->set_property ("articulations", arts);
2647 $$ = n->unprotect ();
2649 | music_function_chord_body
2651 Music *m = unsmob_music ($1);
2653 while (m && m->is_mus_type ("music-wrapper-music")) {
2654 $$ = m->get_property ("element");
2655 m = unsmob_music ($$);
2658 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2659 parser->parser_error (@$, _ ("not a rhythmic event"));
2665 music_function_chord_body:
2671 event_function_event:
2672 EVENT_FUNCTION function_arglist {
2673 $$ = MAKE_SYNTAX ("music-function", @$,
2682 | post_events post_event {
2684 if (Music *m = unsmob_music ($2))
2686 if (m->is_mus_type ("post-event-wrapper"))
2688 for (SCM p = m->get_property ("elements");
2692 $$ = scm_cons (scm_car (p), $$);
2696 $$ = scm_cons ($2, $$);
2702 post_event_nofinger:
2703 direction_less_event {
2706 | script_dir music_function_call {
2708 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2709 parser->parser_error (@2, _ ("post-event expected"));
2710 $$ = SCM_UNSPECIFIED;
2711 } else if (!SCM_UNBNDP ($1))
2713 unsmob_music ($$)->set_property ("direction", $1);
2717 if (!parser->lexer_->is_lyric_state ())
2718 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2719 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2722 if (!parser->lexer_->is_lyric_state ())
2723 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2724 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2726 | script_dir direction_reqd_event {
2727 if (!SCM_UNBNDP ($1))
2729 Music *m = unsmob_music ($2);
2730 m->set_property ("direction", $1);
2734 | script_dir direction_less_event {
2735 if (!SCM_UNBNDP ($1))
2737 Music *m = unsmob_music ($2);
2738 m->set_property ("direction", $1);
2745 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2750 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2761 string_number_event:
2763 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2764 s->set_property ("string-number", $1);
2765 $$ = s->unprotect ();
2769 direction_less_event:
2771 | EVENT_IDENTIFIER {
2775 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2776 a->set_property ("tremolo-type", $1);
2777 $$ = a->unprotect ();
2779 | event_function_event
2782 direction_reqd_event:
2786 | script_abbreviation {
2787 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2788 if (scm_is_string (s)) {
2789 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2790 a->set_property ("articulation-type", s);
2791 $$ = a->unprotect ();
2793 Music *original = unsmob_music (s);
2794 if (original && original->is_mus_type ("post-event")) {
2795 Music *a = original->clone ();
2796 a->set_spot (parser->lexer_->override_input (@$));
2797 $$ = a->unprotect ();
2799 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2800 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2807 /**/ { $$ = SCM_EOL; }
2808 | '=' quotes { $$ = $2; }
2822 $$ = scm_from_int (1);
2825 $$ = scm_oneplus ($1);
2831 $$ = scm_from_int (-1);
2834 $$ = scm_oneminus ($1);
2839 NOTENAME_PITCH quotes {
2840 if (!scm_is_eq (SCM_INUM0, $2))
2842 Pitch p = *unsmob_pitch ($1);
2843 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2844 $$ = p.smobbed_copy ();
2854 TONICNAME_PITCH quotes {
2855 if (!scm_is_eq (SCM_INUM0, $2))
2857 Pitch p = *unsmob_pitch ($1);
2858 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2859 $$ = p.smobbed_copy ();
2866 | PITCH_IDENTIFIER quotes {
2867 if (!scm_is_eq (SCM_INUM0, $2))
2869 Pitch p = *unsmob_pitch ($1);
2870 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2871 $$ = p.smobbed_copy ();
2878 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2879 t->set_property ("text", $1);
2880 $$ = t->unprotect ();
2883 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2884 t->set_property ("text",
2885 make_simple_markup ($1));
2886 $$ = t->unprotect ();
2890 Music *m = unsmob_music ($1);
2891 if (m && m->is_mus_type ("post-event"))
2893 else if (Text_interface::is_markup ($1)) {
2894 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2895 t->set_property ("text", $1);
2896 $$ = t->unprotect ();
2898 parser->parser_error (@1, _ ("not an articulation"));
2904 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2905 t->set_property ("digit", $1);
2906 $$ = t->unprotect ();
2910 script_abbreviation:
2912 $$ = scm_from_locale_string ("Hat");
2915 $$ = scm_from_locale_string ("Plus");
2918 $$ = scm_from_locale_string ("Dash");
2921 $$ = scm_from_locale_string ("Bang");
2924 $$ = scm_from_locale_string ("Larger");
2927 $$ = scm_from_locale_string ("Dot");
2930 $$ = scm_from_locale_string ("Underscore");
2935 '_' { $$ = scm_from_int (DOWN); }
2936 | '^' { $$ = scm_from_int (UP); }
2937 | '-' { $$ = SCM_UNDEFINED; }
2941 multiplied_duration {
2946 maybe_notemode_duration:
2950 | multiplied_duration {
2952 parser->default_duration_ = *unsmob_duration ($$);
2957 optional_notemode_duration:
2958 maybe_notemode_duration
2960 if (SCM_UNBNDP ($$))
2961 $$ = parser->default_duration_.smobbed_copy ();
2967 $$ = make_duration ($1, scm_to_int ($2));
2968 if (SCM_UNBNDP ($$))
2970 parser->parser_error (@1, _ ("not a duration"));
2971 $$ = Duration ().smobbed_copy ();
2974 | DURATION_IDENTIFIER dots {
2975 Duration *d = unsmob_duration ($1);
2976 Duration k (d->duration_log (),
2977 d->dot_count () + scm_to_int ($2));
2978 k = k.compressed (d->factor ());
2979 scm_remember_upto_here_1 ($1);
2980 $$ = k.smobbed_copy ();
2984 multiplied_duration:
2988 | multiplied_duration '*' UNSIGNED {
2989 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2991 | multiplied_duration '*' FRACTION {
2992 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2994 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
3003 $$ = scm_oneplus ($1);
3009 $$ = scm_from_int (parser->default_tremolo_type_);
3012 if (SCM_UNBNDP (make_duration ($2))) {
3013 parser->parser_error (@2, _ ("not a duration"));
3014 $$ = scm_from_int (parser->default_tremolo_type_);
3017 parser->default_tremolo_type_ = scm_to_int ($2);
3023 UNSIGNED { $$ = $1; }
3024 | STRING { $$ = $1; }
3025 | full_markup { $$ = $1; }
3028 // as an integer, it needs to be non-negative, and otherwise
3029 // it needs to be suitable as a markup.
3030 if (scm_is_integer ($1)
3031 ? scm_is_true (scm_negative_p ($1))
3032 : !Text_interface::is_markup ($1))
3034 parser->parser_error (@1, _ ("bass number expected"));
3040 figured_bass_alteration:
3041 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3042 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3043 | '!' { $$ = scm_from_int (0); }
3048 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3049 $$ = bfr->unprotect ();
3052 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3053 $$ = bfr->self_scm ();
3055 if (scm_is_number ($1))
3056 bfr->set_property ("figure", $1);
3057 else if (Text_interface::is_markup ($1))
3058 bfr->set_property ("text", $1);
3064 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3066 | bass_figure figured_bass_alteration {
3067 Music *m = unsmob_music ($1);
3068 if (scm_to_double ($2)) {
3069 SCM salter = m->get_property ("alteration");
3070 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3071 m->set_property ("alteration",
3072 scm_sum (alter, $2));
3074 m->set_property ("alteration", scm_from_int (0));
3077 | bass_figure figured_bass_modification {
3078 Music *m = unsmob_music ($1);
3079 m->set_property ($2, SCM_BOOL_T);
3084 figured_bass_modification:
3086 $$ = ly_symbol2scm ("augmented");
3089 $$ = ly_symbol2scm ("no-continuation");
3092 $$ = ly_symbol2scm ("diminished");
3095 $$ = ly_symbol2scm ("augmented-slash");
3105 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3113 | figure_list br_bass_figure {
3114 $$ = scm_cons ($2, $1);
3119 FIGURE_OPEN figure_list FIGURE_CLOSE {
3120 $$ = scm_reverse_x ($2, SCM_EOL);
3126 /**/ { $$ = SCM_BOOL_F; }
3127 | REST { $$ = SCM_BOOL_T; }
3131 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3132 if (!parser->lexer_->is_note_state ())
3133 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3134 if (!SCM_UNBNDP ($2)
3136 || scm_is_number ($4)
3139 || scm_is_pair ($7))
3142 if (scm_is_true ($6))
3143 n = MY_MAKE_MUSIC ("RestEvent", @$);
3145 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3147 n->set_property ("pitch", $1);
3148 if (SCM_UNBNDP ($5))
3149 n->set_property ("duration",
3150 parser->default_duration_.smobbed_copy ());
3152 n->set_property ("duration", $5);
3154 if (scm_is_number ($4))
3156 int q = scm_to_int ($4);
3157 n->set_property ("absolute-octave", scm_from_int (q-1));
3160 if (to_boolean ($3))
3161 n->set_property ("cautionary", SCM_BOOL_T);
3162 if (to_boolean ($2) || to_boolean ($3))
3163 n->set_property ("force-accidental", SCM_BOOL_T);
3164 if (scm_is_pair ($7))
3165 n->set_property ("articulations",
3166 scm_reverse_x ($7, SCM_EOL));
3167 $$ = n->unprotect ();
3170 | simple_chord_elements post_events {
3171 if (scm_is_pair ($2)) {
3172 if (unsmob_pitch ($1))
3173 $1 = make_chord_elements (@1,
3175 parser->default_duration_.smobbed_copy (),
3178 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3180 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
3181 } else if (!unsmob_pitch ($1))
3182 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
3183 // A mere pitch drops through.
3188 DRUM_PITCH optional_notemode_duration {
3189 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3190 n->set_property ("duration", $2);
3191 n->set_property ("drum-type", $1);
3193 $$ = n->unprotect ();
3195 | RESTNAME optional_notemode_duration {
3197 if (ly_scm2string ($1) == "s") {
3199 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3202 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3205 ev->set_property ("duration", $2);
3206 $$ = ev->unprotect ();
3210 // Can return a single pitch rather than a list.
3211 simple_chord_elements:
3213 if (!parser->lexer_->is_chord_state ())
3214 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3217 | figure_spec optional_notemode_duration {
3218 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3220 unsmob_music (scm_car (s))->set_property ("duration", $2);
3228 if (!parser->lexer_->is_lyric_state ())
3229 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3233 if (!parser->lexer_->is_lyric_state ())
3234 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3240 lyric_element_music:
3241 lyric_element optional_notemode_duration post_events {
3242 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3243 if (scm_is_pair ($3))
3244 unsmob_music ($$)->set_property
3245 ("articulations", scm_reverse_x ($3, SCM_EOL));
3249 // Can return a single pitch rather than a list.
3251 steno_tonic_pitch maybe_notemode_duration {
3252 if (SCM_UNBNDP ($2))
3255 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3257 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3258 SCM its = scm_reverse_x ($4, SCM_EOL);
3259 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3267 | chord_items chord_item {
3268 $$ = scm_cons ($2, $$);
3274 $$ = ly_symbol2scm ("chord-colon");
3277 $$ = ly_symbol2scm ("chord-caret");
3279 | CHORD_SLASH steno_tonic_pitch {
3280 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3282 | CHORD_BASS steno_tonic_pitch {
3283 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3292 $$ = scm_reverse_x ($1, SCM_EOL);
3300 step_number { $$ = scm_cons ($1, SCM_EOL); }
3301 | step_numbers '.' step_number {
3302 $$ = scm_cons ($3, $$);
3308 $$ = make_chord_step ($1, 0);
3311 $$ = make_chord_step ($1, SHARP_ALTERATION);
3313 | UNSIGNED CHORD_MINUS {
3314 $$ = make_chord_step ($1, FLAT_ALTERATION);
3322 | unsigned_number '-' unsigned_number {
3323 $$ = scm_cons ($1, $3);
3330 TODO: should deprecate in favor of Scheme?
3334 number_expression '+' number_term {
3335 $$ = scm_sum ($1, $3);
3337 | number_expression '-' number_term {
3338 $$ = scm_difference ($1, $3);
3347 | number_factor '*' number_factor {
3348 $$ = scm_product ($1, $3);
3350 | number_factor '/' number_factor {
3351 $$ = scm_divide ($1, $3);
3356 '-' number_factor { /* %prec UNARY_MINUS */
3357 $$ = scm_difference ($2, SCM_UNDEFINED);
3365 | REAL NUMBER_IDENTIFIER
3367 $$ = scm_product ($1, $2);
3374 | UNSIGNED NUMBER_IDENTIFIER {
3375 $$ = scm_product ($1, $2);
3383 if (!scm_is_integer ($1)
3384 || scm_is_true (scm_negative_p ($1)))
3386 parser->parser_error (@1, _("not an unsigned integer"));
3392 if (!scm_is_integer ($1)
3393 || scm_is_true (scm_negative_p ($1)))
3395 parser->parser_error (@1, _("not an unsigned integer"));
3402 { $$ = SCM_UNDEFINED; }
3405 if (SCM_UNBNDP ($1))
3413 // This precedence rule is rather weird. It triggers when '!' is
3414 // encountered after a pitch, and is used for deciding whether to save
3415 // this instead for a figure modification. This should not actually
3416 // occur in practice as pitches and figures are generated in different
3417 // modes. Using a greedy (%right) precedence makes sure that we don't
3418 // get stuck in a wrong interpretation.
3419 { $$ = SCM_UNDEFINED; } %prec ':'
3422 if (SCM_UNBNDP ($1))
3431 { parser->lexer_->push_markup_state (); }
3434 parser->lexer_->pop_state ();
3440 { parser->lexer_->push_markup_state (); }
3443 parser->lexer_->pop_state ();
3449 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3451 | markup_head_1_list simple_markup
3453 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3454 @2, $1, scm_list_1 ($2)));
3464 if (Text_interface::is_markup ($1))
3465 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3466 else if (Text_interface::is_markup_list ($1))
3467 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3469 parser->parser_error (@1, _ ("not a markup"));
3470 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3477 markup_composed_list {
3480 | markup_uncomposed_list
3483 markup_uncomposed_list:
3484 markup_braced_list {
3487 | markup_command_list {
3488 $$ = scm_list_1 ($1);
3490 | markup_scm MARKUPLIST_IDENTIFIER
3495 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3496 parser->lexer_->push_note_state (nn);
3497 } '{' score_body '}' {
3498 unsmob_score ($4)->origin ()->set_spot (@$);
3499 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3500 parser->lexer_->pop_state ();
3504 markup_composed_list:
3505 markup_head_1_list markup_uncomposed_list {
3506 $$ = MAKE_SYNTAX ("composed-markup-list",
3512 '{' markup_braced_list_body '}' {
3513 $$ = scm_reverse_x ($2, SCM_EOL);
3517 markup_braced_list_body:
3518 /* empty */ { $$ = SCM_EOL; }
3519 | markup_braced_list_body markup {
3520 $$ = scm_cons ($2, $1);
3522 | markup_braced_list_body markup_list {
3523 $$ = scm_reverse_x ($2, $1);
3527 markup_command_list:
3528 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3529 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3533 markup_command_basic_arguments:
3534 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3535 $$ = scm_cons ($3, $2);
3537 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3538 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3540 | EXPECT_NO_MORE_ARGS {
3545 markup_command_list_arguments:
3546 markup_command_basic_arguments { $$ = $1; }
3547 | EXPECT_MARKUP markup_command_list_arguments markup {
3548 $$ = scm_cons ($3, $2);
3553 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3554 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3559 markup_head_1_item {
3560 $$ = scm_list_1 ($1);
3562 | markup_head_1_list markup_head_1_item {
3563 $$ = scm_cons ($2, $1);
3569 $$ = make_simple_markup ($1);
3572 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3573 parser->lexer_->push_note_state (nn);
3574 } '{' score_body '}' {
3575 unsmob_score ($4)->origin ()->set_spot (@$);
3576 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3577 parser->lexer_->pop_state ();
3579 | MARKUP_FUNCTION markup_command_basic_arguments {
3580 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3582 | markup_scm MARKUP_IDENTIFIER
3589 markup_head_1_list simple_markup
3591 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3592 @2, $1, scm_list_1 ($2)));
3602 Lily_parser::set_yydebug (bool x)
3608 Lily_parser::do_yyparse ()
3610 SCM retval = SCM_UNDEFINED;
3611 yyparse (this, &retval);
3621 It is a little strange to have this function in this file, but
3622 otherwise, we have to import music classes into the lexer.
3626 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3628 if (unsmob_book (sid)) {
3629 Book *book = unsmob_book (sid)->clone ();
3630 *destination = book->self_scm ();
3633 return BOOK_IDENTIFIER;
3634 } else if (scm_is_number (sid)) {
3636 return NUMBER_IDENTIFIER;
3637 } else if (unsmob_context_def (sid))
3639 *destination = unsmob_context_def (sid)->clone ()->unprotect ();
3640 return SCM_IDENTIFIER;
3641 } else if (unsmob_context_mod (sid)) {
3642 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3643 return CONTEXT_MOD_IDENTIFIER;
3644 } else if (Music *mus = unsmob_music (sid)) {
3645 mus = mus->clone ();
3646 *destination = mus->self_scm ();
3647 bool is_event = mus->is_mus_type ("post-event");
3649 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3650 } else if (unsmob_pitch (sid)) {
3651 *destination = unsmob_pitch (sid)->smobbed_copy ();
3652 return PITCH_IDENTIFIER;
3653 } else if (unsmob_duration (sid)) {
3654 *destination = unsmob_duration (sid)->smobbed_copy ();
3655 return DURATION_IDENTIFIER;
3656 } else if (unsmob_output_def (sid)) {
3657 *destination = unsmob_output_def (sid)->clone ()->unprotect ();
3658 return SCM_IDENTIFIER;
3659 } else if (unsmob_score (sid)) {
3660 *destination = unsmob_score (sid)->clone ()->unprotect ();
3661 return SCM_IDENTIFIER;
3668 get_next_unique_context_id ()
3670 return scm_from_locale_string ("$uniqueContextId");
3675 get_next_unique_lyrics_context_id ()
3677 static int new_context_count;
3679 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3680 return scm_from_locale_string (s);
3683 // check_scheme_arg checks one argument with a given predicate for use
3684 // in an argument list and throws a syntax error if it is unusable.
3685 // The argument is prepended to the argument list in any case. After
3686 // throwing a syntax error, the argument list is terminated with #f as
3687 // its last cdr in order to mark it as uncallable while not losing
3688 // track of its total length.
3690 // There are a few special considerations: if optional argument disp
3691 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3692 // instead of arg in a prospective error message. This is useful if
3693 // arg is not the actual argument but rather a transformation of it.
3695 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3696 // and an error message using disp is produced unconditionally.
3698 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3699 SCM arg, SCM args, SCM pred, SCM disp)
3701 if (SCM_UNBNDP (arg))
3702 args = scm_cons (disp, args);
3704 args = scm_cons (arg, args);
3705 if (scm_is_true (scm_call_1 (pred, arg)))
3708 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3709 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3710 SCM_UNBNDP (disp) ? arg : disp);
3711 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3715 SCM loc_on_music (Input loc, SCM arg)
3717 if (Music *m = unsmob_music (arg))
3721 return m->unprotect ();
3727 try_string_variants (SCM pred, SCM str)
3729 // a matching predicate is always ok
3730 if (scm_is_true (scm_call_1 (pred, str)))
3732 // a symbol may be interpreted as a list of symbols if it helps
3733 if (scm_is_symbol (str)) {
3734 str = scm_list_1 (str);
3735 if (scm_is_true (scm_call_1 (pred, str)))
3737 return SCM_UNDEFINED;
3740 // If this cannot be a string representation of a symbol list,
3743 if (!is_regular_identifier (str, true))
3744 return SCM_UNDEFINED;
3746 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3747 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3748 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3750 // Let's attempt the symbol list interpretation first.
3752 if (scm_is_true (scm_call_1 (pred, str)))
3755 // If there is just one symbol in the list, we might interpret
3756 // it as a single symbol
3758 if (scm_is_null (scm_cdr (str)))
3760 str = scm_car (str);
3761 if (scm_is_true (scm_call_1 (pred, str)))
3765 return SCM_UNDEFINED;
3769 is_regular_identifier (SCM id, bool multiple)
3771 if (!scm_is_string (id))
3774 string str = ly_scm2string (id);
3776 bool middle = false;
3778 for (string::iterator it=str.begin(); it != str.end (); it++)
3781 if ((c >= 'a' && c <= 'z')
3782 || (c >= 'A' && c <= 'Z')
3785 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3794 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3796 if (unsmob_music (simple))
3798 if (parser->lexer_->is_note_state ()) {
3799 if (scm_is_symbol (simple)) {
3800 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3801 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3802 n->set_property ("drum-type", simple);
3803 return n->unprotect ();
3805 if (unsmob_pitch (simple)) {
3806 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3807 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3808 n->set_property ("pitch", simple);
3809 return n->unprotect ();
3812 } else if (parser->lexer_->is_lyric_state ()) {
3813 if (Text_interface::is_markup (simple))
3814 return MAKE_SYNTAX ("lyric-event", loc, simple,
3815 parser->default_duration_.smobbed_copy ());
3816 } else if (parser->lexer_->is_chord_state ()) {
3817 if (unsmob_pitch (simple))
3821 make_chord_elements (loc, simple,
3822 parser->default_duration_.smobbed_copy (),
3829 make_music_with_input (SCM name, Input where)
3831 Music *m = make_music_by_name (name);
3832 m->set_spot (where);
3837 make_simple_markup (SCM a)
3843 make_duration (SCM d, int dots)
3845 int t = scm_to_int (d);
3846 if (t > 0 && (t & (t-1)) == 0)
3847 return Duration (intlog2 (t), dots).smobbed_copy ();
3849 return SCM_UNDEFINED;
3853 make_chord_step (SCM step_scm, Rational alter)
3855 int step = scm_to_int (step_scm);
3858 alter += FLAT_ALTERATION;
3862 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3863 return m.smobbed_copy ();
3868 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3870 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3871 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3872 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3874 unsmob_music (scm_car (s))->set_spot (loc);
3880 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3882 Lily_lexer *lex = parser->lexer_;
3886 int tok = lex->pop_extra_token ();
3889 lex->prepare_for_next_token ();
3890 return lex->yylex ();