1 /* -*- mode: c++; c-file-style: "linux"; indent-tabs-mode: t -*- */
3 This file is part of LilyPond, the GNU music typesetter.
5 Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 Jan Nieuwenhuizen <janneke@gnu.org>
8 LilyPond is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 /* Mode and indentation are at best a rough approximation based on TAB
23 * formatting (reasonable for compatibility with unspecific editor
24 * modes as Bison modes are hard to find) and need manual correction
25 * frequently. Without a reasonably dependable way of formatting a
26 * Bison file sensibly, there is little point in trying to fix the
27 * inconsistent state of indentation.
32 #define yyerror Lily_parser::parser_error
34 /* We use custom location type: Input objects */
37 #define YYLLOC_DEFAULT(Current,Rhs,N) \
38 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
40 #define YYPRINT(file, type, value) \
42 if (scm_is_eq (value, SCM_UNSPECIFIED)) \
44 char *p = scm_to_locale_string \
45 (scm_simple_format (SCM_BOOL_F, \
46 scm_from_locale_string ("~S"), \
47 scm_list_1 (value))); \
54 %parse-param {Lily_parser *parser}
55 %parse-param {SCM *retval}
56 %lex-param {Lily_parser *parser}
60 /* We use SCMs to do strings, because it saves us the trouble of
61 deleting them. Let's hope that a stack overflow doesn't trigger a move
62 of the parse stack onto the heap. */
65 %nonassoc REPEAT REPEAT_IDENTIFIER
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 #define MYBACKUP(Token, Value, Location) \
151 if (yychar == YYEMPTY) \
154 parser->lexer_->push_extra_token (Token, Value); \
155 parser->lexer_->push_extra_token (BACKUP); \
157 parser->parser_error \
158 (Location, _("Too much lookahead")); \
163 #define MYREPARSE(Location, Pred, Token, Value) \
165 if (yychar == YYEMPTY) \
167 parser->lexer_->push_extra_token (Token, Value); \
168 parser->lexer_->push_extra_token (REPARSE, \
171 parser->parser_error \
172 (Location, _("Too much lookahead")); \
181 #define MY_MAKE_MUSIC(x, spot) \
182 make_music_with_input (ly_symbol2scm (x), \
183 parser->lexer_->override_input (spot))
186 - Don't use lily module, create a new module instead.
187 - delay application of the function
189 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
190 scm_apply_0 (proc, args)
191 /* Syntactic Sugar. */
192 #define MAKE_SYNTAX(name, location, ...) \
193 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))
194 #define START_MAKE_SYNTAX(name, ...) \
195 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
196 #define FINISH_MAKE_SYNTAX(start, location, ...) \
197 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)))))
199 SCM get_next_unique_context_id ();
200 SCM get_next_unique_lyrics_context_id ();
207 #define _(x) gettext (x)
211 static Music *make_music_with_input (SCM name, Input where);
212 SCM check_scheme_arg (Lily_parser *parser, Input loc,
213 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
214 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
215 SCM loc_on_music (Input loc, SCM arg);
216 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
217 SCM make_chord_step (SCM step, Rational alter);
218 SCM make_simple_markup (SCM a);
219 SCM make_duration (SCM t, int dots = 0);
220 bool is_regular_identifier (SCM id, bool multiple=false);
221 SCM try_string_variants (SCM pred, SCM str);
222 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
226 /* The third option is an alias that will be used to display the
227 syntax error. Bison CVS now correctly handles backslash escapes.
229 FIXME: Bison needs to translate some of these, eg, STRING.
233 /* Keyword tokens with plain escaped name. */
234 %token END_OF_FILE 0 "end of input"
235 %token ACCEPTS "\\accepts"
236 %token ADDLYRICS "\\addlyrics"
237 %token ALIAS "\\alias"
238 %token ALTERNATIVE "\\alternative"
240 %token BOOKPART "\\bookpart"
241 %token CHANGE "\\change"
242 %token CHORDMODE "\\chordmode"
243 %token CHORDS "\\chords"
244 %token CONSISTS "\\consists"
245 %token CONTEXT "\\context"
246 %token DEFAULT "\\default"
247 %token DEFAULTCHILD "\\defaultchild"
248 %token DENIES "\\denies"
249 %token DESCRIPTION "\\description"
250 %token DRUMMODE "\\drummode"
251 %token DRUMS "\\drums"
252 %token FIGUREMODE "\\figuremode"
253 %token FIGURES "\\figures"
254 %token HEADER "\\header"
255 %token INVALID "\\version-error"
256 %token LAYOUT "\\layout"
257 %token LYRICMODE "\\lyricmode"
258 %token LYRICS "\\lyrics"
259 %token LYRICSTO "\\lyricsto"
260 %token MARKUP "\\markup"
261 %token MARKUPLIST "\\markuplist"
264 %token NOTEMODE "\\notemode"
265 %token OVERRIDE "\\override"
266 %token PAPER "\\paper"
267 %token REMOVE "\\remove"
268 %token REPEAT "\\repeat"
270 %token REVERT "\\revert"
271 %token SCORE "\\score"
272 %token SCORELINES "\\score-lines"
273 %token SEQUENTIAL "\\sequential"
275 %token SIMULTANEOUS "\\simultaneous"
276 %token TEMPO "\\tempo"
278 %token UNSET "\\unset"
281 /* Keyword token exceptions. */
282 %token NEWCONTEXT "\\new"
285 /* Other string tokens. */
287 %token CHORD_BASS "/+"
288 %token CHORD_CARET "^"
289 %token CHORD_COLON ":"
290 %token CHORD_MINUS "-"
291 %token CHORD_SLASH "/"
292 %token ANGLE_OPEN "<"
293 %token ANGLE_CLOSE ">"
294 %token DOUBLE_ANGLE_OPEN "<<"
295 %token DOUBLE_ANGLE_CLOSE ">>"
296 %token E_BACKSLASH "\\"
297 %token E_EXCLAMATION "\\!"
302 If we give names, Bison complains.
304 %token FIGURE_CLOSE /* "\\>" */
305 %token FIGURE_OPEN /* "\\<" */
306 %token FIGURE_SPACE "_"
309 %token MULTI_MEASURE_REST
315 /* Artificial tokens, for more generic function syntax */
316 %token EXPECT_MARKUP "markup?"
317 %token EXPECT_SCM "scheme?"
318 %token BACKUP "(backed-up?)"
319 %token REPARSE "(reparsed?)"
320 %token EXPECT_MARKUP_LIST "markup-list?"
321 %token EXPECT_OPTIONAL "optional?"
322 /* After the last argument. */
323 %token EXPECT_NO_MORE_ARGS;
325 /* An artificial token for parsing embedded Lilypond */
326 %token EMBEDDED_LILY "#{"
328 %token BOOK_IDENTIFIER
329 %token CHORD_BODY_IDENTIFIER
330 %token CHORD_MODIFIER
331 %token CHORD_REPETITION
332 %token CONTEXT_DEF_IDENTIFIER
333 %token CONTEXT_MOD_IDENTIFIER
335 %token PITCH_IDENTIFIER
336 %token DURATION_IDENTIFIER
337 %token EVENT_IDENTIFIER
338 %token EVENT_FUNCTION
341 %token MARKUP_FUNCTION
342 %token MARKUP_LIST_FUNCTION
343 %token MARKUP_IDENTIFIER
344 %token MARKUPLIST_IDENTIFIER
345 %token MUSIC_FUNCTION
346 %token MUSIC_IDENTIFIER
347 %token NOTENAME_PITCH
348 %token NUMBER_IDENTIFIER
349 %token OUTPUT_DEF_IDENTIFIER
351 %token REPEAT_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 ("toplevel-score-handler");
411 scm_call_2 (proc, parser->self_scm (), $1);
414 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
415 scm_call_2 (proc, parser->self_scm (), $1);
418 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
419 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
422 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
423 scm_call_2 (proc, parser->self_scm (), $1);
426 // Evaluate and ignore #xxx, as opposed to \xxx
427 parser->lexer_->eval_scm_token ($1);
429 | embedded_scm_active
431 SCM out = SCM_UNDEFINED;
432 if (Text_interface::is_markup ($1))
433 out = scm_list_1 ($1);
434 else if (Text_interface::is_markup_list ($1))
436 if (scm_is_pair (out))
438 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
439 scm_call_2 (proc, parser->self_scm (), out);
440 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
441 parser->parser_error (@1, _("bad expression type"));
445 Output_def * od = unsmob_output_def ($1);
447 if (od->c_variable ("is-paper") == SCM_BOOL_T)
448 id = ly_symbol2scm ("$defaultpaper");
449 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
450 id = ly_symbol2scm ("$defaultmidi");
451 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
452 id = ly_symbol2scm ("$defaultlayout");
454 parser->lexer_->set_identifier (id, $1);
461 $$ = parser->lexer_->eval_scm_token ($1);
471 embedded_scm_bare_arg:
475 $$ = parser->lexer_->eval_scm_token ($1);
478 | context_modification
480 | context_def_spec_block
486 /* The generic version may end in music, or not */
493 /* embedded_scm_arg is _not_ casting pitches to music by default, this
494 * has to be done by the function itself. Note that this may cause
495 * the results of scm_function_call or embedded_scm_bare_arg to be
496 * turned into music from pitches as well. Note that this creates a
497 * distinctly awkward situation for calculated drum pitches. Those
498 * are at the current point of time rejected as music constituents as
499 * they can't be distinguished from "proper" symbols.
503 embedded_scm_bare_arg
509 SCM_FUNCTION function_arglist {
510 $$ = MAKE_SYNTAX ("music-function", @$,
515 embedded_lilypond_number:
516 '-' embedded_lilypond_number
518 $$ = scm_difference ($2, SCM_UNDEFINED);
521 | UNSIGNED NUMBER_IDENTIFIER
523 $$ = scm_product ($1, $2);
530 // FIXME: @$ does not contain a useful source location
531 // for empty rules, and the only token in the whole
532 // production, EMBEDDED_LILY, is synthetic and also
533 // contains no source location.
534 $$ = MAKE_SYNTAX ("void-music", @$);
536 | identifier_init_nonumber
537 | embedded_lilypond_number
538 | post_event post_events
540 $$ = scm_reverse_x ($2, SCM_EOL);
541 if (Music *m = unsmob_music ($1))
543 if (m->is_mus_type ("post-event-wrapper"))
545 (scm_list_2 (m->get_property ("elements"),
548 $$ = scm_cons ($1, $$);
551 && scm_is_null (scm_cdr ($$)))
555 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
556 m->set_property ("elements", $$);
557 $$ = m->unprotect ();
560 | multiplied_duration
561 | music_embedded music_embedded music_list {
562 $3 = scm_reverse_x ($3, SCM_EOL);
563 if (unsmob_music ($2))
564 $3 = scm_cons ($2, $3);
565 if (unsmob_music ($1))
566 $3 = scm_cons ($1, $3);
567 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
570 parser->error_level_ = 1;
571 $$ = SCM_UNSPECIFIED;
573 | INVALID embedded_lilypond {
574 parser->error_level_ = 1;
580 lilypond_header_body:
581 /* empty */ { $$ = SCM_UNSPECIFIED; }
582 | lilypond_header_body assignment {
585 | lilypond_header_body embedded_scm {
591 HEADER '{' lilypond_header_body '}' {
592 $$ = parser->lexer_->remove_scope ();
604 assignment_id '=' identifier_init {
605 parser->lexer_->set_identifier ($1, $3);
606 $$ = SCM_UNSPECIFIED;
608 | assignment_id property_path '=' identifier_init {
609 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
610 parser->lexer_->set_identifier (path, $4);
611 $$ = SCM_UNSPECIFIED;
617 identifier_init_nonumber
619 | post_event_nofinger post_events
621 $$ = scm_reverse_x ($2, SCM_EOL);
622 if (Music *m = unsmob_music ($1))
624 if (m->is_mus_type ("post-event-wrapper"))
626 (scm_list_2 (m->get_property ("elements"),
629 $$ = scm_cons ($1, $$);
632 && scm_is_null (scm_cdr ($$)))
636 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
637 m->set_property ("elements", $$);
638 $$ = m->unprotect ();
643 identifier_init_nonumber:
648 | context_def_spec_block
654 | context_modification
657 context_def_spec_block:
658 CONTEXT '{' context_def_spec_body '}'
661 unsmob_context_def ($$)->origin ()->set_spot (@$);
669 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
670 parser->lexer_->push_note_state (nn);
674 parser->lexer_->pop_state ();
679 context_mod_embedded:
682 if (unsmob_music ($1)) {
683 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
684 $1 = scm_call_2 (proc, parser->self_scm (), $1);
686 if (unsmob_context_mod ($1))
689 parser->parser_error (@1, _ ("not a context mod"));
690 $$ = Context_mod ().smobbed_copy ();
696 context_def_spec_body:
698 $$ = Context_def::make_scm ();
700 | CONTEXT_DEF_IDENTIFIER {
703 | context_def_spec_body context_mod {
704 if (!SCM_UNBNDP ($2))
705 unsmob_context_def ($$)->add_context_mod ($2);
707 | context_def_spec_body context_modification {
708 Context_def *td = unsmob_context_def ($$);
709 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
710 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
711 td->add_context_mod (scm_car (m));
714 | context_def_spec_body context_mod_embedded {
715 Context_def *td = unsmob_context_def ($$);
716 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
717 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
718 td->add_context_mod (scm_car (m));
726 BOOK '{' book_body '}' {
728 unsmob_book ($$)->origin ()->set_spot (@$);
730 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
735 * Use 'handlers' like for toplevel-* stuff?
736 * grok \layout and \midi? */
739 Book *book = new Book;
740 init_papers (parser);
741 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
742 book->paper_->unprotect ();
743 push_paper (parser, book->paper_);
744 book->header_ = get_header (parser);
745 $$ = book->unprotect ();
746 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
749 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
751 | book_body paper_block {
752 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
753 set_paper (parser, unsmob_output_def ($2));
755 | book_body bookpart_block {
756 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
757 scm_call_2 (proc, $1, $2);
759 | book_body score_block {
760 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
761 scm_call_2 (proc, $1, $2);
763 | book_body composite_music {
764 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
765 scm_call_3 (proc, parser->self_scm (), $1, $2);
767 | book_body full_markup {
768 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
769 scm_call_2 (proc, $1, scm_list_1 ($2));
771 | book_body full_markup_list {
772 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
773 scm_call_2 (proc, $1, $2);
775 | book_body SCM_TOKEN {
776 // Evaluate and ignore #xxx, as opposed to \xxx
777 parser->lexer_->eval_scm_token ($2);
779 | book_body embedded_scm_active
781 SCM out = SCM_UNDEFINED;
782 if (Text_interface::is_markup ($2))
783 out = scm_list_1 ($2);
784 else if (Text_interface::is_markup_list ($2))
786 if (scm_is_pair (out))
788 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
789 scm_call_2 (proc, $1, out);
790 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
791 parser->parser_error (@2, _("bad expression type"));
795 parser->lexer_->add_scope (unsmob_book ($1)->header_);
798 Book *book = unsmob_book ($1);
800 book->scores_ = SCM_EOL;
801 book->bookparts_ = SCM_EOL;
806 BOOKPART '{' bookpart_body '}' {
808 unsmob_book ($$)->origin ()->set_spot (@$);
809 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
815 Book *book = new Book;
816 $$ = book->unprotect ();
817 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
820 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
822 | bookpart_body paper_block {
823 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
825 | bookpart_body score_block {
826 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
827 scm_call_2 (proc, $1, $2);
829 | bookpart_body composite_music {
830 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
831 scm_call_3 (proc, parser->self_scm (), $1, $2);
833 | bookpart_body full_markup {
834 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
835 scm_call_2 (proc, $1, scm_list_1 ($2));
837 | bookpart_body full_markup_list {
838 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
839 scm_call_2 (proc, $1, $2);
841 | bookpart_body SCM_TOKEN {
842 // Evaluate and ignore #xxx, as opposed to \xxx
843 parser->lexer_->eval_scm_token ($2);
845 | bookpart_body embedded_scm_active
847 SCM out = SCM_UNDEFINED;
848 if (Text_interface::is_markup ($2))
849 out = scm_list_1 ($2);
850 else if (Text_interface::is_markup_list ($2))
852 if (scm_is_pair (out))
854 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
855 scm_call_2 (proc, $1, out);
856 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
857 parser->parser_error (@2, _("bad expression type"));
861 Book *book = unsmob_book ($1);
862 if (!ly_is_module (book->header_))
863 book->header_ = ly_make_module (false);
864 parser->lexer_->add_scope (book->header_);
866 | bookpart_body error {
867 Book *book = unsmob_book ($1);
869 book->scores_ = SCM_EOL;
874 SCORE '{' score_body '}' {
881 SCM scorify = ly_lily_module_constant ("scorify-music");
882 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
884 unsmob_score ($$)->origin ()->set_spot (@$);
886 | embedded_scm_active {
888 if (unsmob_score ($1))
889 score = new Score (*unsmob_score ($1));
892 parser->parser_error (@1, _("score expected"));
894 unsmob_score ($$)->origin ()->set_spot (@$);
895 $$ = score->unprotect ();
899 Score *score = unsmob_score ($1);
900 if (!ly_is_module (score->get_header ()))
901 score->set_header (ly_make_module (false));
902 parser->lexer_->add_scope (score->get_header ());
904 | score_body output_def {
905 Output_def *od = unsmob_output_def ($2);
906 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
908 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
913 unsmob_score ($1)->add_output_def (od);
917 unsmob_score ($$)->error_found_ = true;
928 Output_def *od = unsmob_output_def ($1);
930 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
932 parser->parser_error (@1, _ ("need \\paper for paper block"));
933 $$ = get_paper (parser)->unprotect ();
940 output_def_body '}' {
943 parser->lexer_->remove_scope ();
944 parser->lexer_->pop_state ();
950 Output_def *p = get_paper (parser);
951 p->input_origin_ = @$;
952 parser->lexer_->add_scope (p->scope_);
953 $$ = p->unprotect ();
956 Output_def *p = get_midi (parser);
957 $$ = p->unprotect ();
958 parser->lexer_->add_scope (p->scope_);
961 Output_def *p = get_layout (parser);
963 parser->lexer_->add_scope (p->scope_);
964 $$ = p->unprotect ();
968 output_def_head_with_mode_switch:
970 parser->lexer_->push_initial_state ();
975 // We need this weird nonterminal because both music as well as a
976 // context definition can start with \context and the difference is
977 // only apparent after looking at the next token. If it is '{', there
978 // is still time to escape from notes mode.
980 music_or_context_def:
982 | context_def_spec_block
986 output_def_head_with_mode_switch '{' {
988 unsmob_output_def ($$)->input_origin_.set_spot (@$);
990 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
991 Output_def *o = unsmob_output_def ($3);
992 o->input_origin_.set_spot (@$);
994 parser->lexer_->remove_scope ();
995 parser->lexer_->add_scope (o->scope_);
997 | output_def_body assignment {
1000 | output_def_body embedded_scm {
1005 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1006 parser->lexer_->push_note_state (nn);
1007 } music_or_context_def
1009 parser->lexer_->pop_state ();
1010 if (unsmob_context_def ($3))
1011 assign_context_def (unsmob_output_def ($1), $3);
1014 SCM proc = parser->lexer_->lookup_identifier
1015 ("output-def-music-handler");
1016 scm_call_3 (proc, parser->self_scm (),
1020 | output_def_body error {
1026 TEMPO steno_duration '=' tempo_range {
1027 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1029 | TEMPO scalar steno_duration '=' tempo_range {
1030 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1033 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1038 The representation of a list is reversed to have efficient append. */
1044 | music_list music_embedded {
1045 if (unsmob_music ($2))
1046 $$ = scm_cons ($2, $1);
1048 | music_list error {
1049 Music *m = MY_MAKE_MUSIC("Music", @$);
1051 m->set_property ("error-found", SCM_BOOL_T);
1052 $$ = scm_cons (m->self_scm (), $1);
1053 m->unprotect (); /* UGH */
1060 $$ = scm_reverse_x ($2, SCM_EOL);
1065 | lyric_element_music
1071 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1072 parser->parser_error (@1, _ ("unexpected post-event"));
1073 $$ = SCM_UNSPECIFIED;
1076 | music_embedded_backup
1080 | music_embedded_backup BACKUP lyric_element_music
1084 | multiplied_duration post_events
1086 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1088 parser->default_duration_ = *unsmob_duration ($1);
1089 n->set_property ("duration", $1);
1091 if (scm_is_pair ($2))
1092 n->set_property ("articulations",
1093 scm_reverse_x ($2, SCM_EOL));
1094 $$ = n->unprotect ();
1098 music_embedded_backup:
1101 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1103 else if (Music *m = unsmob_music ($1)) {
1104 if (m->is_mus_type ("post-event")) {
1105 parser->parser_error
1106 (@1, _ ("unexpected post-event"));
1107 $$ = SCM_UNSPECIFIED;
1110 } else if (parser->lexer_->is_lyric_state ()
1111 && Text_interface::is_markup ($1))
1112 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1114 @$.warning (_ ("Ignoring non-music expression"));
1123 $$ = make_music_from_simple (parser, @1, $1);
1124 if (!unsmob_music ($$))
1126 parser->parser_error (@1, _ ("music expected"));
1127 $$ = MAKE_SYNTAX ("void-music", @$);
1130 | composite_music %prec COMPOSITE
1135 | composite_music %prec COMPOSITE
1139 REPEAT simple_string unsigned_number music
1141 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1143 | REPEAT_IDENTIFIER music
1145 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1148 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1150 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1152 | REPEAT_IDENTIFIER music ALTERNATIVE braced_music_list
1154 $$ = MAKE_SYNTAX ("repeat", @$, scm_car ($1), scm_cdr ($1),
1160 SEQUENTIAL braced_music_list {
1161 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1163 | braced_music_list {
1164 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1169 SIMULTANEOUS braced_music_list {
1170 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1172 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1173 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1179 | music_property_def
1183 context_modification:
1186 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1187 parser->lexer_->push_note_state (nn);
1188 } '{' context_mod_list '}'
1190 parser->lexer_->pop_state ();
1193 | WITH CONTEXT_MOD_IDENTIFIER
1197 | CONTEXT_MOD_IDENTIFIER
1201 | WITH context_modification_arg
1203 if (unsmob_music ($2)) {
1204 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1205 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1207 if (unsmob_context_mod ($2))
1210 parser->parser_error (@2, _ ("not a context mod"));
1211 $$ = Context_mod ().smobbed_copy ();
1216 context_modification_arg:
1221 optional_context_mod:
1225 | context_modification
1233 $$ = Context_mod ().smobbed_copy ();
1235 | context_mod_list context_mod {
1236 if (!SCM_UNBNDP ($2))
1237 unsmob_context_mod ($1)->add_context_mod ($2);
1239 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1240 Context_mod *md = unsmob_context_mod ($2);
1242 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1244 | context_mod_list context_mod_embedded {
1245 unsmob_context_mod ($1)->add_context_mods
1246 (unsmob_context_mod ($2)->get_mods ());
1255 /* Music that can be parsed without lookahead */
1258 | complex_music_prefix closed_music
1260 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1262 | music_function_call_closed
1268 | grouped_music_list
1272 simultaneous_music { $$ = $1; }
1273 | sequential_music { $$ = $1; }
1276 /* Function argument lists are arguably the most complex part in the
1277 * parser. They are pretty tricky to understand because of the way
1278 * they are processed, and because of optional arguments that can be
1279 * omitted. When there are several optional arguments in a row,
1280 * omitting one automatically omits all following arguments. Optional
1281 * arguments can only be omitted when either
1283 * a) the omission is explicitly started with \default
1284 * b) the omission is implicitly started by an argument not matching
1285 * its predicate, and there is a mandatory argument later that can
1286 * "catch" the argument that does not fit.
1288 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1289 * (corresponding to mandatory arguments and having a predicate
1290 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1291 * the semantic value of the EXPECT_OPTIONAL token is the default to
1292 * use when the optional argument is omitted, and EXPECT_SCM again has
1293 * the argument predicate as semantic value) in reverse order to the
1294 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1295 * processed inside-out while actual tokens are consumed.
1297 * This means that the argument list tokens determine the actions
1298 * taken as they arrive. The structure of the argument list is known
1299 * to the parser and stored in its parse stack when the first argument
1300 * is being parsed. What the parser does not know is which predicates
1301 * will match and whether or not \default will be appearing in the
1302 * argument list, and where.
1304 * Many of the basic nonterminals used for argument list scanning come
1305 * in a "normal" and a "closed" flavor. A closed expression is one
1306 * that can be parsed without a lookahead token. That makes it
1307 * feasible for an optional argument that may need to be skipped:
1308 * skipping can only be accomplished by pushing back the token into
1309 * the lexer, and that only works when there is no lookahead token.
1311 * Sequences of 0 or more optional arguments are scanned using either
1312 * function_arglist_backup or function_arglist_nonbackup. The first
1313 * is used when optional arguments are followed by at least one
1314 * mandatory argument: in that case optional arguments may be skipped
1315 * by either a false predicate (in which case the expression will be
1316 * pushed back as one or more tokens, preceded by a BACKUP token) or
1317 * by using \default.
1319 * If optional arguments are at the end of the argument list, they are
1320 * instead scanned using function_arglist_nonbackup: here the only
1321 * manner to enter into skipping of optional arguments is the use of
1324 * The argument list of a normal function call is parsed using
1325 * function_arglist. The part of an argument list before a mandatory
1326 * argument is parsed using function_arglist_optional.
1328 * The difference is that leading optional arguments are scanned using
1329 * function_arglist_nonbackup and function_arglist_backup,
1332 * Most other details are obvious in the rules themselves.
1336 function_arglist_nonbackup_common:
1337 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup FRACTION
1339 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1341 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1343 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1345 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1347 SCM n = scm_difference ($5, SCM_UNDEFINED);
1348 if (scm_is_true (scm_call_1 ($2, n)))
1349 $$ = scm_cons (n, $3);
1351 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1352 t->set_property ("digit", $5);
1353 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1358 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1360 $$ = check_scheme_arg (parser, @4,
1361 scm_difference ($5, SCM_UNDEFINED),
1364 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1366 $$ = check_scheme_arg (parser, @4,
1367 scm_difference ($5, SCM_UNDEFINED),
1372 function_arglist_closed_nonbackup:
1373 function_arglist_nonbackup_common
1374 | function_arglist_closed_common
1375 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg_closed
1377 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1379 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_closed
1381 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1383 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1385 $$ = check_scheme_arg (parser, @4,
1386 try_string_variants ($2, $4),
1389 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1391 $$ = check_scheme_arg (parser, @4,
1392 try_string_variants ($2, $4),
1395 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1397 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1403 | SYMBOL_LIST '.' symbol_list_rev
1405 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1411 | symbol_list_rev '.' symbol_list_part
1413 $$ = scm_append_x (scm_list_2 ($3, $1));
1417 // symbol_list_part delivers elements in reverse copy.
1422 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1423 $$ = try_string_variants (sym_l_p, $1);
1424 if (SCM_UNBNDP ($$)) {
1425 parser->parser_error (@1, _("not a symbol"));
1428 $$ = scm_reverse ($$);
1433 symbol_list_element:
1439 function_arglist_nonbackup:
1440 function_arglist_nonbackup_common
1441 | function_arglist_common
1442 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1444 if (scm_is_true (scm_call_1 ($2, $4)))
1445 $$ = scm_cons ($4, $3);
1447 $$ = check_scheme_arg (parser, @4,
1448 make_music_from_simple
1452 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1454 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1456 | function_arglist_nonbackup_reparse REPARSE duration_length
1458 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1460 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1462 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1464 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1466 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1468 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1470 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1472 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1474 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1478 function_arglist_nonbackup_reparse:
1479 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1482 SCM res = try_string_variants ($2, $4);
1483 if (!SCM_UNBNDP (res))
1484 if (scm_is_pair (res))
1485 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1487 MYREPARSE (@4, $2, SCM_ARG, res);
1488 else if (scm_is_true
1490 ($2, make_music_from_simple
1492 MYREPARSE (@4, $2, STRING, $4);
1494 MYREPARSE (@4, $2, SCM_ARG, $4);
1496 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1499 SCM res = try_string_variants ($2, $4);
1500 if (!SCM_UNBNDP (res))
1501 if (scm_is_pair (res))
1502 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1504 MYREPARSE (@4, $2, SCM_ARG, res);
1505 else if (scm_is_true
1507 ($2, make_music_from_simple
1509 MYREPARSE (@4, $2, STRING, $4);
1511 MYREPARSE (@4, $2, SCM_ARG, $4);
1513 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1516 if (scm_is_true (scm_call_1 ($2, $4)))
1517 MYREPARSE (@4, $2, SCM_ARG, $4);
1518 else if (scm_is_true
1520 ($2, make_music_from_simple
1522 MYREPARSE (@4, $2, STRING, $4);
1524 MYREPARSE (@4, $2, SCM_ARG, $4);
1526 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1529 if (scm_is_true (scm_call_1 ($2, $4)))
1530 MYREPARSE (@4, $2, REAL, $4);
1532 SCM d = make_duration ($4);
1533 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1534 MYREPARSE (@4, $2, REAL, $4); // trigger error
1536 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1539 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1541 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1546 function_arglist_backup:
1547 function_arglist_common
1548 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg_closed
1550 if (scm_is_true (scm_call_1 ($2, $4)))
1552 $$ = scm_cons ($4, $3);
1554 $$ = scm_cons (loc_on_music (@3, $1), $3);
1555 MYBACKUP (SCM_ARG, $4, @4);
1558 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REPEAT simple_string unsigned_number
1560 $4 = MAKE_SYNTAX ("repeat", @4, $5, $6,
1561 MY_MAKE_MUSIC ("Music", @4)->unprotect (),
1563 if (scm_is_true (scm_call_1 ($2, $4)))
1566 MYREPARSE (@4, $2, REPEAT_IDENTIFIER, scm_cons ($5, $6));
1568 $$ = scm_cons (loc_on_music (@3, $1), $3);
1569 MYBACKUP (REPEAT_IDENTIFIER, scm_cons ($5, $6), @4);
1572 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup chord_body
1574 if (scm_is_true (scm_call_1 ($2, $4)))
1577 MYREPARSE (@4, $2, CHORD_BODY_IDENTIFIER, $4);
1579 $$ = scm_cons (loc_on_music (@3, $1), $3);
1580 MYBACKUP (CHORD_BODY_IDENTIFIER, $4, @4);
1583 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1585 if (scm_is_true (scm_call_1 ($2, $4)))
1587 $$ = scm_cons ($4, $3);
1589 $$ = scm_cons (loc_on_music (@3, $1), $3);
1590 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1593 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1595 if (scm_is_true (scm_call_1 ($2, $4)))
1596 $$ = scm_cons ($4, $3);
1598 $$ = scm_cons (loc_on_music (@3, $1), $3);
1599 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1602 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1604 if (scm_is_true (scm_call_1 ($2, $4)))
1606 MYREPARSE (@4, $2, REAL, $4);
1609 SCM d = make_duration ($4);
1610 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1612 $$ = scm_cons (loc_on_music (@3, $1), $3);
1613 MYBACKUP (UNSIGNED, $4, @4);
1615 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1620 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1622 if (scm_is_true (scm_call_1 ($2, $4)))
1625 MYREPARSE (@4, $2, REAL, $4);
1627 $$ = scm_cons (loc_on_music (@3, $1), $3);
1628 MYBACKUP (REAL, $4, @4);
1631 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1633 if (scm_is_true (scm_call_1 ($2, $4)))
1635 $$ = scm_cons ($4, $3);
1637 $$ = scm_cons (loc_on_music (@3, $1), $3);
1638 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1641 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup FRACTION
1643 if (scm_is_true (scm_call_1 ($2, $4)))
1645 $$ = scm_cons ($4, $3);
1647 $$ = scm_cons (loc_on_music (@3, $1), $3);
1648 MYBACKUP (FRACTION, $4, @4);
1651 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1653 SCM n = scm_difference ($5, SCM_UNDEFINED);
1654 if (scm_is_true (scm_call_1 ($2, n))) {
1656 MYREPARSE (@5, $2, REAL, n);
1658 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1659 t->set_property ("digit", $5);
1660 $$ = t->unprotect ();
1661 if (scm_is_true (scm_call_1 ($2, $$)))
1662 $$ = scm_cons ($$, $3);
1664 $$ = scm_cons (loc_on_music (@3, $1), $3);
1665 MYBACKUP (UNSIGNED, $5, @5);
1666 parser->lexer_->push_extra_token ('-');
1671 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1673 SCM n = scm_difference ($5, SCM_UNDEFINED);
1674 if (scm_is_true (scm_call_1 ($2, n))) {
1675 MYREPARSE (@5, $2, REAL, n);
1678 $$ = scm_cons (loc_on_music (@3, $1), $3);
1679 MYBACKUP (REAL, n, @5);
1682 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1684 SCM n = scm_difference ($5, SCM_UNDEFINED);
1685 if (scm_is_true (scm_call_1 ($2, n))) {
1686 $$ = scm_cons (n, $3);
1688 $$ = scm_cons (loc_on_music (@3, $1), $3);
1689 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1692 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup PITCH_IDENTIFIER
1694 if (scm_is_true (scm_call_1 ($2, $4)))
1696 $$ = scm_cons ($4, $3);
1698 $$ = scm_cons (loc_on_music (@3, $1), $3);
1699 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1702 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NOTENAME_PITCH
1704 if (scm_is_true (scm_call_1 ($2, $4)))
1706 MYREPARSE (@4, $2, NOTENAME_PITCH, $4);
1709 $$ = scm_cons (loc_on_music (@3, $1), $3);
1710 MYBACKUP (NOTENAME_PITCH, $4, @4);
1713 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup TONICNAME_PITCH
1715 if (scm_is_true (scm_call_1 ($2, $4)))
1717 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1720 $$ = scm_cons (loc_on_music (@3, $1), $3);
1721 MYBACKUP (TONICNAME_PITCH, $4, @4);
1724 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1726 if (scm_is_true (scm_call_1 ($2, $4)))
1728 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1731 $$ = scm_cons (loc_on_music (@3, $1), $3);
1732 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1735 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1737 SCM res = try_string_variants ($2, $4);
1738 if (!SCM_UNBNDP (res))
1739 if (scm_is_pair (res)) {
1741 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1744 $$ = scm_cons (res, $3);
1746 $$ = scm_cons (loc_on_music (@3, $1), $3);
1747 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1750 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1752 SCM res = try_string_variants ($2, $4);
1753 if (!SCM_UNBNDP (res))
1754 if (scm_is_pair (res)) {
1756 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1759 $$ = scm_cons (res, $3);
1761 $$ = scm_cons (loc_on_music (@3, $1), $3);
1762 MYBACKUP (STRING, $4, @4);
1765 | function_arglist_backup REPARSE music_assign
1767 if (scm_is_true (scm_call_1 ($2, $3)))
1768 $$ = scm_cons ($3, $1);
1770 $$ = check_scheme_arg (parser, @3,
1771 make_music_from_simple
1775 | function_arglist_backup REPARSE bare_number_common
1777 $$ = check_scheme_arg (parser, @3,
1780 | function_arglist_backup REPARSE duration_length
1782 $$ = check_scheme_arg (parser, @3,
1785 | function_arglist_backup REPARSE symbol_list_arg
1787 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1792 function_arglist_nonbackup
1793 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1795 $$ = scm_cons (loc_on_music (@4, $1), $3);
1799 function_arglist_skip_nonbackup:
1800 function_arglist_nonbackup
1801 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1803 $$ = scm_cons (loc_on_music (@3, $1), $3);
1807 function_arglist_common:
1808 EXPECT_NO_MORE_ARGS {
1811 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1813 if (scm_is_true (scm_call_1 ($1, $3)))
1814 $$ = scm_cons ($3, $2);
1816 $$ = check_scheme_arg (parser, @3,
1817 make_music_from_simple
1821 | EXPECT_SCM function_arglist_optional bare_number_common
1823 $$ = check_scheme_arg (parser, @3,
1826 | EXPECT_SCM function_arglist_optional FRACTION
1828 $$ = check_scheme_arg (parser, @3,
1831 | EXPECT_SCM function_arglist_optional post_event_nofinger
1833 $$ = check_scheme_arg (parser, @3,
1836 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1838 SCM n = scm_difference ($4, SCM_UNDEFINED);
1839 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1841 | function_arglist_common_reparse REPARSE SCM_ARG
1843 $$ = check_scheme_arg (parser, @3,
1846 | function_arglist_common_reparse REPARSE lyric_element_music
1848 $$ = check_scheme_arg (parser, @3,
1851 | function_arglist_common_reparse REPARSE bare_number_common
1853 $$ = check_scheme_arg (parser, @3,
1856 | function_arglist_common_reparse REPARSE duration_length
1858 $$ = check_scheme_arg (parser, @3,
1861 | function_arglist_common_reparse REPARSE symbol_list_arg
1863 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1867 function_arglist_common_reparse:
1868 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1871 SCM res = try_string_variants ($1, $3);
1872 if (!SCM_UNBNDP (res))
1873 if (scm_is_pair (res))
1874 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1876 MYREPARSE (@3, $1, SCM_ARG, res);
1877 else if (scm_is_true
1879 ($1, make_music_from_simple (parser, @3, $3))))
1880 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1882 // This is going to flag a syntax error, we
1883 // know the predicate to be false.
1884 MYREPARSE (@3, $1, SCM_ARG, $3);
1886 | EXPECT_SCM function_arglist_optional STRING
1889 SCM res = try_string_variants ($1, $3);
1890 if (!SCM_UNBNDP (res))
1891 if (scm_is_pair (res))
1892 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1894 MYREPARSE (@3, $1, SCM_ARG, res);
1895 else if (scm_is_true
1897 ($1, make_music_from_simple (parser, @3, $3))))
1898 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1900 // This is going to flag a syntax error, we
1901 // know the predicate to be false.
1902 MYREPARSE (@3, $1, SCM_ARG, $3);
1904 | EXPECT_SCM function_arglist_optional full_markup
1907 if (scm_is_true (scm_call_1 ($1, $3)))
1908 MYREPARSE (@3, $1, SCM_ARG, $3);
1909 else if (scm_is_true
1911 ($1, make_music_from_simple (parser, @3, $3))))
1912 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1914 // This is going to flag a syntax error, we
1915 // know the predicate to be false.
1916 MYREPARSE (@3, $1, SCM_ARG, $3);
1918 | EXPECT_SCM function_arglist_optional UNSIGNED
1921 if (scm_is_true (scm_call_1 ($1, $3)))
1922 MYREPARSE (@3, $1, REAL, $3);
1924 SCM d = make_duration ($3);
1925 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
1926 MYREPARSE (@3, $1, REAL, $3);
1928 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
1931 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
1934 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
1936 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
1939 SCM n = scm_difference ($4, SCM_UNDEFINED);
1940 if (scm_is_true (scm_call_1 ($1, n)))
1941 MYREPARSE (@4, $1, REAL, n);
1943 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1944 t->set_property ("digit", $4);
1945 SCM m = t->unprotect ();
1946 if (scm_is_true (scm_call_1 ($1, m)))
1947 MYREPARSE (@4, $1, SCM_ARG, m);
1949 MYREPARSE (@4, $1, SCM_ARG, $4);
1953 | EXPECT_SCM function_arglist_optional '-' REAL
1956 SCM n = scm_difference ($4, SCM_UNDEFINED);
1957 MYREPARSE (@4, $1, REAL, n);
1961 function_arglist_closed:
1962 function_arglist_closed_nonbackup
1963 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1965 $$ = scm_cons (loc_on_music (@4, $1), $3);
1969 function_arglist_closed_common:
1970 EXPECT_NO_MORE_ARGS {
1973 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1975 $$ = check_scheme_arg (parser, @3,
1978 | EXPECT_SCM function_arglist_optional bare_number_common_closed
1980 $$ = check_scheme_arg (parser, @3,
1983 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1985 $$ = check_scheme_arg (parser, @3,
1986 scm_difference ($4, SCM_UNDEFINED),
1989 | EXPECT_SCM function_arglist_optional post_event_nofinger
1991 $$ = check_scheme_arg (parser, @3,
1994 | EXPECT_SCM function_arglist_optional FRACTION
1996 $$ = check_scheme_arg (parser, @3,
1999 | function_arglist_common_reparse REPARSE SCM_ARG
2001 $$ = check_scheme_arg (parser, @3,
2004 | function_arglist_common_reparse REPARSE bare_number_common_closed
2006 $$ = check_scheme_arg (parser, @3,
2009 | function_arglist_common_reparse REPARSE symbol_list_arg
2011 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2015 function_arglist_optional:
2016 function_arglist_backup
2017 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2019 $$ = scm_cons (loc_on_music (@4, $1), $3);
2021 | function_arglist_skip_backup BACKUP
2024 function_arglist_skip_backup:
2025 function_arglist_backup
2026 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2028 $$ = scm_cons (loc_on_music (@3, $1), $3);
2032 embedded_scm_closed:
2034 | scm_function_call_closed
2037 embedded_scm_arg_closed:
2038 embedded_scm_bare_arg
2039 | scm_function_call_closed
2043 scm_function_call_closed:
2044 SCM_FUNCTION function_arglist_closed {
2045 $$ = MAKE_SYNTAX ("music-function", @$,
2050 music_function_call:
2051 MUSIC_FUNCTION function_arglist {
2052 $$ = MAKE_SYNTAX ("music-function", @$,
2059 /**/ { $$ = SCM_EOL; }
2060 | '=' simple_string {
2067 | repeated_music { $$ = $1; }
2068 | re_rhythmed_music { $$ = $1; }
2069 | complex_music_prefix music
2071 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2075 complex_music_prefix:
2076 CONTEXT symbol optional_id optional_context_mod {
2077 Context_mod *ctxmod = unsmob_context_mod ($4);
2080 mods = ctxmod->get_mods ();
2081 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2083 | NEWCONTEXT symbol optional_id optional_context_mod {
2084 Context_mod *ctxmod = unsmob_context_mod ($4);
2087 mods = ctxmod->get_mods ();
2088 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2093 mode_changing_head grouped_music_list {
2094 if ($1 == ly_symbol2scm ("chords"))
2096 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2102 parser->lexer_->pop_state ();
2104 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2105 Context_mod *ctxmod = unsmob_context_mod ($2);
2108 mods = ctxmod->get_mods ();
2109 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2110 if ($1 == ly_symbol2scm ("ChordNames"))
2112 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2114 parser->lexer_->pop_state ();
2120 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2121 parser->lexer_->push_note_state (nn);
2123 $$ = ly_symbol2scm ("notes");
2127 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2128 parser->lexer_->push_note_state (nn);
2130 $$ = ly_symbol2scm ("drums");
2133 parser->lexer_->push_figuredbass_state ();
2135 $$ = ly_symbol2scm ("figures");
2138 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2139 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2140 nn = parser->lexer_->lookup_identifier ("pitchnames");
2141 parser->lexer_->push_chord_state (nn);
2142 $$ = ly_symbol2scm ("chords");
2146 { parser->lexer_->push_lyric_state ();
2147 $$ = ly_symbol2scm ("lyrics");
2151 mode_changing_head_with_context:
2153 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2154 parser->lexer_->push_note_state (nn);
2156 $$ = ly_symbol2scm ("DrumStaff");
2159 parser->lexer_->push_figuredbass_state ();
2161 $$ = ly_symbol2scm ("FiguredBass");
2164 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2165 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2166 nn = parser->lexer_->lookup_identifier ("pitchnames");
2167 parser->lexer_->push_chord_state (nn);
2168 $$ = ly_symbol2scm ("ChordNames");
2171 { parser->lexer_->push_lyric_state ();
2172 $$ = ly_symbol2scm ("Lyrics");
2177 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2180 /* Can also use music at the expensive of two S/Rs similar to
2181 \repeat \alternative */
2182 parser->lexer_->pop_state ();
2184 $$ = scm_cons ($3, SCM_EOL);
2186 | new_lyrics ADDLYRICS {
2187 parser->lexer_->push_lyric_state ();
2189 parser->lexer_->pop_state ();
2190 $$ = scm_cons ($4, $1);
2195 composite_music new_lyrics {
2196 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2198 | LYRICSTO simple_string {
2199 parser->lexer_->push_lyric_state ();
2201 parser->lexer_->pop_state ();
2202 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2207 CHANGE STRING '=' STRING {
2208 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
2215 $$ = scm_reverse_x ($1, SCM_EOL);
2217 | symbol_list_rev property_path {
2218 $$ = scm_reverse_x ($1, $2);
2224 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2227 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2229 | OVERRIDE property_path '=' scalar {
2230 if (scm_ilength ($2) < 2) {
2231 parser->parser_error (@2, _("bad grob property path"));
2234 $$ = scm_cons (ly_symbol2scm ("push"),
2235 scm_cons2 (scm_car ($2),
2240 | REVERT revert_arg {
2241 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2245 // This is all quite awkward for the sake of substantial backward
2246 // compatibility while at the same time allowing a more "natural" form
2247 // of specification not separating grob specification from grob
2248 // property path. The purpose of this definition of revert_arg is to
2249 // allow the symbol list which specifies grob and property to revert
2250 // to be optionally be split into two parts after the grob (which in
2251 // this case is just the first element of the list). symbol_list_part
2252 // is only one path component, but it can be parsed without lookahead,
2253 // so we can follow it with a synthetic BACKUP token when needed. If
2254 // the first symbol_list_part already contains multiple elements (only
2255 // possible if a Scheme expression provides them), we just parse for
2256 // additional elements introduced by '.', which is what the
2257 // SYMBOL_LIST backup in connection with the immediately following
2258 // rule using symbol_list_arg does.
2260 // As long as we don't have our coffers filled with both grob and at
2261 // least one grob property specification, the rest of the required
2262 // symbol list chain may be provided either with or without a leading
2263 // dot. This is for both allowing the traditional
2264 // \revert Accidental #'color
2265 // as well as well as the "naive" form
2266 // \revert Accidental.color
2269 revert_arg_backup BACKUP symbol_list_arg
2278 if (scm_is_null ($1)
2279 || scm_is_null (scm_cdr ($1)))
2280 MYBACKUP (SCM_ARG, $1, @1);
2282 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2286 // revert_arg_part delivers results in reverse
2289 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2291 $$ = scm_append_x (scm_list_2 ($5, $3));
2293 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2295 $$ = scm_append_x (scm_list_2 ($4, $3));
2300 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2301 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2303 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2304 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2305 | DENIES { $$ = ly_symbol2scm ("denies"); }
2307 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2308 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2309 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2310 | NAME { $$ = ly_symbol2scm ("context-name"); }
2314 property_operation { $$ = $1; }
2315 | context_def_mod STRING {
2316 $$ = scm_list_2 ($1, $2);
2318 | context_def_mod embedded_scm
2320 if (!scm_is_string ($2)
2321 && ly_symbol2scm ("consists") != $1
2322 && ly_symbol2scm ("remove") != $1)
2325 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2329 $$ = scm_list_2 ($1, $2);
2334 // If defined, at least two members.
2338 SCM l = scm_reverse_x ($1, SCM_EOL);
2341 (scm_object_property (scm_car (l),
2342 ly_symbol2scm ("is-grob?"))))
2343 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2344 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2345 parser->parser_error (@1, _ ("bad grob property path"));
2352 // If defined, at least three members
2356 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2358 parser->parser_error (@1, _ ("bad grob property path"));
2362 | grob_prop_spec property_path
2364 if (!SCM_UNBNDP ($1)) {
2365 $$ = scm_append_x (scm_list_2 ($1, $2));
2366 if (scm_is_null (scm_cddr ($$))) {
2367 parser->parser_error (@$, _ ("bad grob property path"));
2375 // Exactly two elements or undefined
2379 SCM l = scm_reverse_x ($1, SCM_EOL);
2380 switch (scm_ilength (l)) {
2382 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2386 parser->parser_error (@1, _ ("bad context property path"));
2393 simple_music_property_def:
2394 OVERRIDE grob_prop_path '=' scalar {
2395 if (SCM_UNBNDP ($2))
2398 $$ = scm_list_5 (scm_car ($2),
2399 ly_symbol2scm ("OverrideProperty"),
2405 | REVERT simple_revert_context revert_arg {
2406 $$ = scm_list_4 ($2,
2407 ly_symbol2scm ("RevertProperty"),
2411 | SET context_prop_spec '=' scalar {
2412 if (SCM_UNBNDP ($2))
2415 $$ = scm_list_4 (scm_car ($2),
2416 ly_symbol2scm ("PropertySet"),
2420 | UNSET context_prop_spec {
2421 if (SCM_UNBNDP ($2))
2424 $$ = scm_list_3 (scm_car ($2),
2425 ly_symbol2scm ("PropertyUnset"),
2431 // This is all quite awkward for the sake of substantial backward
2432 // compatibility while at the same time allowing a more "natural" form
2433 // of specification not separating grob specification from grob
2434 // property path. The purpose of this definition of
2435 // simple_revert_context is to allow the symbol list which specifies
2436 // grob and property to revert to be optionally be split into two
2437 // parts after the grob (which may be preceded by a context
2438 // specification, a case which we distinguish by checking whether the
2439 // first symbol is a valid grob symbol instead).
2441 // See revert_arg above for the main work horse of this arrangement.
2442 // simple_revert_context just caters for the context and delegates the
2443 // rest of the job to revert_arg.
2445 simple_revert_context:
2448 $1 = scm_reverse_x ($1, SCM_EOL);
2449 if (scm_is_null ($1)
2451 (scm_object_property (scm_car ($1),
2452 ly_symbol2scm ("is-grob?")))) {
2453 $$ = ly_symbol2scm ("Bottom");
2454 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2457 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2464 simple_music_property_def {
2465 if (SCM_UNBNDP ($1))
2466 $$ = MAKE_SYNTAX ("void-music", @1);
2468 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2479 simple_string: STRING {
2484 if (scm_is_string ($1)) {
2487 parser->parser_error (@1, (_ ("simple string expected")));
2488 $$ = scm_string (SCM_EOL);
2495 $$ = scm_string_to_symbol ($1);
2499 // This is a bit of overkill but makes the same
2500 // routine responsible for all symbol interpretations.
2501 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2503 if (SCM_UNBNDP ($$))
2505 parser->parser_error (@1, (_ ("symbol expected")));
2506 // Generate a unique symbol in case it is used
2507 // for an assignment or similar
2508 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2517 // The following is a rather defensive variant of admitting
2518 // negative numbers: the grammar would permit number_factor or
2519 // even number_expression. However, function arguments allow
2520 // only this simple kind of negative number, so to have things
2521 // like \tweak and \override behave reasonably similar, it
2522 // makes sense to rule out things like -- which are rather an
2523 // accent in function argument contexts.
2526 $$ = scm_difference ($2, SCM_UNDEFINED);
2534 simple_element post_events {
2535 // Let the rhythmic music iterator sort this mess out.
2536 if (scm_is_pair ($2)) {
2537 $$ = make_music_from_simple (parser, @1, $1);
2538 if (unsmob_music ($$))
2539 unsmob_music ($$)->set_property ("articulations",
2540 scm_reverse_x ($2, SCM_EOL));
2543 parser->parser_error (@1, _("music expected"));
2544 $$ = MAKE_SYNTAX ("void-music", @1);
2548 | simple_chord_elements post_events {
2549 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2552 /* why is this giving wrong start location? -ns
2554 i.set_location (@1, @2);
2555 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2557 | CHORD_REPETITION optional_notemode_duration post_events {
2559 i.set_location (@1, @3);
2560 $$ = MAKE_SYNTAX ("repetition-chord", i,
2561 $2, scm_reverse_x ($3, SCM_EOL));
2563 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2565 i.set_location (@1, @3);
2566 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2567 scm_reverse_x ($3, SCM_EOL));
2570 | note_chord_element
2575 chord_body optional_notemode_duration post_events
2577 Music *m = unsmob_music ($1);
2578 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2579 SCM es = m->get_property ("elements");
2580 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2582 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2583 unsmob_music (scm_car (s))->set_property ("duration", dur);
2584 es = ly_append2 (es, postevs);
2586 m-> set_property ("elements", es);
2588 $$ = m->self_scm ();
2593 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2595 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2597 | CHORD_BODY_IDENTIFIER
2600 chord_body_elements:
2601 /* empty */ { $$ = SCM_EOL; }
2602 | chord_body_elements chord_body_element {
2603 if (!SCM_UNBNDP ($2))
2604 $$ = scm_cons ($2, $1);
2609 pitch exclamations questions octave_check post_events
2611 bool q = to_boolean ($3);
2612 bool ex = to_boolean ($2);
2616 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2617 n->set_property ("pitch", $1);
2619 n->set_property ("cautionary", SCM_BOOL_T);
2621 n->set_property ("force-accidental", SCM_BOOL_T);
2623 if (scm_is_pair (post)) {
2624 SCM arts = scm_reverse_x (post, SCM_EOL);
2625 n->set_property ("articulations", arts);
2627 if (scm_is_number (check))
2629 int q = scm_to_int (check);
2630 n->set_property ("absolute-octave", scm_from_int (q-1));
2633 $$ = n->unprotect ();
2635 | DRUM_PITCH post_events {
2636 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2637 n->set_property ("drum-type", $1);
2639 if (scm_is_pair ($2)) {
2640 SCM arts = scm_reverse_x ($2, SCM_EOL);
2641 n->set_property ("articulations", arts);
2643 $$ = n->unprotect ();
2645 | music_function_chord_body
2647 Music *m = unsmob_music ($1);
2649 while (m && m->is_mus_type ("music-wrapper-music")) {
2650 $$ = m->get_property ("element");
2651 m = unsmob_music ($$);
2654 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2655 parser->parser_error (@$, _ ("not a rhythmic event"));
2661 music_function_chord_body:
2666 // Event functions may only take closed arglists, otherwise it would
2667 // not be clear whether a following postevent should be associated
2668 // with the last argument of the event function or with the expression
2669 // for which the function call acts itself as event.
2671 music_function_call_closed:
2672 MUSIC_FUNCTION function_arglist_closed {
2673 $$ = MAKE_SYNTAX ("music-function", @$,
2678 event_function_event:
2679 EVENT_FUNCTION function_arglist_closed {
2680 $$ = MAKE_SYNTAX ("music-function", @$,
2702 | post_events post_event {
2704 if (Music *m = unsmob_music ($2))
2706 if (m->is_mus_type ("post-event-wrapper"))
2708 for (SCM p = m->get_property ("elements");
2712 $$ = scm_cons (scm_car (p), $$);
2716 $$ = scm_cons ($2, $$);
2722 post_event_nofinger:
2723 direction_less_event {
2726 | script_dir music_function_call_closed {
2728 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2729 parser->parser_error (@2, _ ("post-event expected"));
2730 $$ = SCM_UNSPECIFIED;
2731 } else if (!SCM_UNBNDP ($1))
2733 unsmob_music ($$)->set_property ("direction", $1);
2737 if (!parser->lexer_->is_lyric_state ())
2738 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2739 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2742 if (!parser->lexer_->is_lyric_state ())
2743 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2744 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2746 | script_dir direction_reqd_event {
2747 if (!SCM_UNBNDP ($1))
2749 Music *m = unsmob_music ($2);
2750 m->set_property ("direction", $1);
2754 | script_dir direction_less_event {
2755 if (!SCM_UNBNDP ($1))
2757 Music *m = unsmob_music ($2);
2758 m->set_property ("direction", $1);
2765 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2770 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2781 string_number_event:
2783 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2784 s->set_property ("string-number", $1);
2785 $$ = s->unprotect ();
2789 direction_less_event:
2791 | EVENT_IDENTIFIER {
2795 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2796 a->set_property ("tremolo-type", $1);
2797 $$ = a->unprotect ();
2799 | event_function_event
2802 direction_reqd_event:
2806 | script_abbreviation {
2807 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2808 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2809 if (scm_is_string (s))
2810 a->set_property ("articulation-type", s);
2811 else parser->parser_error (@1, _ ("expecting string as script definition"));
2812 $$ = a->unprotect ();
2817 /**/ { $$ = SCM_EOL; }
2818 | '=' quotes { $$ = $2; }
2832 $$ = scm_from_int (1);
2835 $$ = scm_oneplus ($1);
2841 $$ = scm_from_int (-1);
2844 $$ = scm_oneminus ($1);
2849 NOTENAME_PITCH quotes {
2850 if (!scm_is_eq (SCM_INUM0, $2))
2852 Pitch p = *unsmob_pitch ($1);
2853 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2854 $$ = p.smobbed_copy ();
2864 TONICNAME_PITCH quotes {
2865 if (!scm_is_eq (SCM_INUM0, $2))
2867 Pitch p = *unsmob_pitch ($1);
2868 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2869 $$ = p.smobbed_copy ();
2881 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2882 t->set_property ("text", $1);
2883 $$ = t->unprotect ();
2886 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2887 t->set_property ("text",
2888 make_simple_markup ($1));
2889 $$ = t->unprotect ();
2891 | embedded_scm_closed
2893 Music *m = unsmob_music ($1);
2894 if (m && m->is_mus_type ("post-event"))
2896 else if (Text_interface::is_markup ($1)) {
2897 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2898 t->set_property ("text", $1);
2899 $$ = t->unprotect ();
2901 parser->parser_error (@1, _ ("not an articulation"));
2907 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2908 t->set_property ("digit", $1);
2909 $$ = t->unprotect ();
2913 script_abbreviation:
2915 $$ = scm_from_locale_string ("Hat");
2918 $$ = scm_from_locale_string ("Plus");
2921 $$ = scm_from_locale_string ("Dash");
2924 $$ = scm_from_locale_string ("Bang");
2927 $$ = scm_from_locale_string ("Larger");
2930 $$ = scm_from_locale_string ("Dot");
2933 $$ = scm_from_locale_string ("Underscore");
2938 '_' { $$ = scm_from_int (DOWN); }
2939 | '^' { $$ = scm_from_int (UP); }
2940 | '-' { $$ = SCM_UNDEFINED; }
2944 multiplied_duration {
2949 maybe_notemode_duration:
2953 | multiplied_duration {
2955 parser->default_duration_ = *unsmob_duration ($$);
2960 optional_notemode_duration:
2961 maybe_notemode_duration
2963 if (SCM_UNBNDP ($$))
2964 $$ = parser->default_duration_.smobbed_copy ();
2970 $$ = make_duration ($1, scm_to_int ($2));
2971 if (SCM_UNBNDP ($$))
2973 parser->parser_error (@1, _ ("not a duration"));
2974 $$ = Duration ().smobbed_copy ();
2977 | DURATION_IDENTIFIER dots {
2978 Duration *d = unsmob_duration ($1);
2979 Duration k (d->duration_log (),
2980 d->dot_count () + scm_to_int ($2));
2981 k = k.compressed (d->factor ());
2982 scm_remember_upto_here_1 ($1);
2983 $$ = k.smobbed_copy ();
2987 multiplied_duration:
2991 | multiplied_duration '*' UNSIGNED {
2992 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2994 | multiplied_duration '*' FRACTION {
2995 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2997 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
3006 $$ = scm_oneplus ($1);
3015 if (SCM_UNBNDP (make_duration ($2)))
3016 parser->parser_error (@2, _ ("not a duration"));
3022 UNSIGNED { $$ = $1; }
3023 | STRING { $$ = $1; }
3024 | full_markup { $$ = $1; }
3027 // as an integer, it needs to be non-negative, and otherwise
3028 // it needs to be suitable as a markup.
3029 if (scm_is_integer ($1)
3030 ? scm_is_true (scm_negative_p ($1))
3031 : !Text_interface::is_markup ($1))
3033 parser->parser_error (@1, _ ("bass number expected"));
3039 figured_bass_alteration:
3040 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3041 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3042 | '!' { $$ = scm_from_int (0); }
3047 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3048 $$ = bfr->unprotect ();
3051 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3052 $$ = bfr->self_scm ();
3054 if (scm_is_number ($1))
3055 bfr->set_property ("figure", $1);
3056 else if (Text_interface::is_markup ($1))
3057 bfr->set_property ("text", $1);
3063 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3065 | bass_figure figured_bass_alteration {
3066 Music *m = unsmob_music ($1);
3067 if (scm_to_double ($2)) {
3068 SCM salter = m->get_property ("alteration");
3069 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3070 m->set_property ("alteration",
3071 scm_sum (alter, $2));
3073 m->set_property ("alteration", scm_from_int (0));
3076 | bass_figure figured_bass_modification {
3077 Music *m = unsmob_music ($1);
3078 m->set_property ($2, SCM_BOOL_T);
3083 figured_bass_modification:
3085 $$ = ly_symbol2scm ("augmented");
3088 $$ = ly_symbol2scm ("no-continuation");
3091 $$ = ly_symbol2scm ("diminished");
3094 $$ = ly_symbol2scm ("augmented-slash");
3104 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3112 | figure_list br_bass_figure {
3113 $$ = scm_cons ($2, $1);
3118 FIGURE_OPEN figure_list FIGURE_CLOSE {
3119 $$ = scm_reverse_x ($2, SCM_EOL);
3125 /**/ { $$ = SCM_BOOL_F; }
3126 | REST { $$ = SCM_BOOL_T; }
3130 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3131 if (!parser->lexer_->is_note_state ())
3132 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3133 if (!SCM_UNBNDP ($2)
3135 || scm_is_number ($4)
3137 || scm_is_true ($6))
3140 if (scm_is_true ($6))
3141 n = MY_MAKE_MUSIC ("RestEvent", @$);
3143 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3145 n->set_property ("pitch", $1);
3146 if (SCM_UNBNDP ($5))
3147 n->set_property ("duration",
3148 parser->default_duration_.smobbed_copy ());
3150 n->set_property ("duration", $5);
3152 if (scm_is_number ($4))
3154 int q = scm_to_int ($4);
3155 n->set_property ("absolute-octave", scm_from_int (q-1));
3158 if (to_boolean ($3))
3159 n->set_property ("cautionary", SCM_BOOL_T);
3160 if (to_boolean ($2) || to_boolean ($3))
3161 n->set_property ("force-accidental", SCM_BOOL_T);
3163 $$ = n->unprotect ();
3166 | DRUM_PITCH optional_notemode_duration {
3167 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3168 n->set_property ("duration", $2);
3169 n->set_property ("drum-type", $1);
3171 $$ = n->unprotect ();
3173 | RESTNAME optional_notemode_duration {
3175 if (ly_scm2string ($1) == "s") {
3177 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3180 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3183 ev->set_property ("duration", $2);
3184 $$ = ev->unprotect ();
3188 simple_chord_elements:
3190 if (!parser->lexer_->is_chord_state ())
3191 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3194 | figure_spec optional_notemode_duration {
3195 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3197 unsmob_music (scm_car (s))->set_property ("duration", $2);
3205 if (!parser->lexer_->is_lyric_state ())
3206 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3210 if (!parser->lexer_->is_lyric_state ())
3211 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3217 lyric_element_music:
3218 lyric_element optional_notemode_duration post_events {
3219 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3220 if (scm_is_pair ($3))
3221 unsmob_music ($$)->set_property
3222 ("articulations", scm_reverse_x ($3, SCM_EOL));
3227 steno_tonic_pitch optional_notemode_duration {
3228 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3230 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3231 SCM its = scm_reverse_x ($4, SCM_EOL);
3232 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3240 | chord_items chord_item {
3241 $$ = scm_cons ($2, $$);
3247 $$ = ly_symbol2scm ("chord-colon");
3250 $$ = ly_symbol2scm ("chord-caret");
3252 | CHORD_SLASH steno_tonic_pitch {
3253 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3255 | CHORD_BASS steno_tonic_pitch {
3256 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3265 $$ = scm_reverse_x ($1, SCM_EOL);
3273 step_number { $$ = scm_cons ($1, SCM_EOL); }
3274 | step_numbers '.' step_number {
3275 $$ = scm_cons ($3, $$);
3281 $$ = make_chord_step ($1, 0);
3284 $$ = make_chord_step ($1, SHARP_ALTERATION);
3286 | UNSIGNED CHORD_MINUS {
3287 $$ = make_chord_step ($1, FLAT_ALTERATION);
3295 | UNSIGNED '-' UNSIGNED {
3296 $$ = scm_cons ($1, $3);
3303 TODO: should deprecate in favor of Scheme?
3307 number_expression '+' number_term {
3308 $$ = scm_sum ($1, $3);
3310 | number_expression '-' number_term {
3311 $$ = scm_difference ($1, $3);
3320 | number_factor '*' number_factor {
3321 $$ = scm_product ($1, $3);
3323 | number_factor '/' number_factor {
3324 $$ = scm_divide ($1, $3);
3329 '-' number_factor { /* %prec UNARY_MINUS */
3330 $$ = scm_difference ($2, SCM_UNDEFINED);
3336 bare_number_common_closed
3337 | REAL NUMBER_IDENTIFIER
3339 $$ = scm_product ($1, $2);
3343 bare_number_common_closed:
3351 | UNSIGNED NUMBER_IDENTIFIER {
3352 $$ = scm_product ($1, $2);
3358 | bare_number_common_closed
3367 { $$ = SCM_UNDEFINED; }
3370 if (SCM_UNBNDP ($1))
3378 { $$ = SCM_UNDEFINED; }
3381 if (SCM_UNBNDP ($1))
3390 { parser->lexer_->push_markup_state (); }
3393 parser->lexer_->pop_state ();
3399 { parser->lexer_->push_markup_state (); }
3402 parser->lexer_->pop_state ();
3408 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3410 | markup_head_1_list simple_markup
3412 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3413 @2, $1, scm_list_1 ($2)));
3423 if (Text_interface::is_markup ($1))
3424 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3425 else if (Text_interface::is_markup_list ($1))
3426 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3428 parser->parser_error (@1, _ ("not a markup"));
3429 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3436 markup_composed_list {
3439 | markup_uncomposed_list
3442 markup_uncomposed_list:
3443 markup_braced_list {
3446 | markup_command_list {
3447 $$ = scm_list_1 ($1);
3449 | markup_scm MARKUPLIST_IDENTIFIER
3454 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3455 parser->lexer_->push_note_state (nn);
3456 } '{' score_body '}' {
3457 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3458 parser->lexer_->pop_state ();
3462 markup_composed_list:
3463 markup_head_1_list markup_uncomposed_list {
3464 $$ = MAKE_SYNTAX ("composed-markup-list",
3470 '{' markup_braced_list_body '}' {
3471 $$ = scm_reverse_x ($2, SCM_EOL);
3475 markup_braced_list_body:
3476 /* empty */ { $$ = SCM_EOL; }
3477 | markup_braced_list_body markup {
3478 $$ = scm_cons ($2, $1);
3480 | markup_braced_list_body markup_list {
3481 $$ = scm_reverse_x ($2, $1);
3485 markup_command_list:
3486 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3487 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3491 markup_command_basic_arguments:
3492 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3493 $$ = scm_cons ($3, $2);
3495 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3496 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3498 | EXPECT_NO_MORE_ARGS {
3503 markup_command_list_arguments:
3504 markup_command_basic_arguments { $$ = $1; }
3505 | EXPECT_MARKUP markup_command_list_arguments markup {
3506 $$ = scm_cons ($3, $2);
3511 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3512 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3517 markup_head_1_item {
3518 $$ = scm_list_1 ($1);
3520 | markup_head_1_list markup_head_1_item {
3521 $$ = scm_cons ($2, $1);
3527 $$ = make_simple_markup ($1);
3530 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3531 parser->lexer_->push_note_state (nn);
3532 } '{' score_body '}' {
3533 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3534 parser->lexer_->pop_state ();
3536 | MARKUP_FUNCTION markup_command_basic_arguments {
3537 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3539 | markup_scm MARKUP_IDENTIFIER
3546 markup_head_1_list simple_markup
3548 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3549 @2, $1, scm_list_1 ($2)));
3559 Lily_parser::set_yydebug (bool x)
3565 Lily_parser::do_yyparse ()
3567 SCM retval = SCM_UNDEFINED;
3568 yyparse (this, &retval);
3578 It is a little strange to have this function in this file, but
3579 otherwise, we have to import music classes into the lexer.
3583 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3585 if (unsmob_book (sid)) {
3586 Book *book = unsmob_book (sid)->clone ();
3587 *destination = book->self_scm ();
3590 return BOOK_IDENTIFIER;
3591 } else if (scm_is_number (sid)) {
3593 return NUMBER_IDENTIFIER;
3594 } else if (unsmob_context_def (sid)) {
3595 Context_def *def= unsmob_context_def (sid)->clone ();
3597 *destination = def->self_scm ();
3600 return CONTEXT_DEF_IDENTIFIER;
3601 } else if (unsmob_context_mod (sid)) {
3602 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3604 return CONTEXT_MOD_IDENTIFIER;
3605 } else if (Music *mus = unsmob_music (sid)) {
3606 mus = mus->clone ();
3607 *destination = mus->self_scm ();
3608 bool is_event = mus->is_mus_type ("post-event");
3610 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3611 } else if (unsmob_pitch (sid)) {
3612 *destination = unsmob_pitch (sid)->smobbed_copy ();
3613 return PITCH_IDENTIFIER;
3614 } else if (unsmob_duration (sid)) {
3615 *destination = unsmob_duration (sid)->smobbed_copy ();
3616 return DURATION_IDENTIFIER;
3617 } else if (unsmob_output_def (sid)) {
3618 Output_def *p = unsmob_output_def (sid);
3621 *destination = p->self_scm ();
3623 return OUTPUT_DEF_IDENTIFIER;
3630 get_next_unique_context_id ()
3632 return scm_from_locale_string ("$uniqueContextId");
3637 get_next_unique_lyrics_context_id ()
3639 static int new_context_count;
3641 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3642 return scm_from_locale_string (s);
3645 // check_scheme_arg checks one argument with a given predicate for use
3646 // in an argument list and throws a syntax error if it is unusable.
3647 // The argument is prepended to the argument list in any case. After
3648 // throwing a syntax error, the argument list is terminated with #f as
3649 // its last cdr in order to mark it as uncallable while not losing
3650 // track of its total length.
3652 // There are a few special considerations: if optional argument disp
3653 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3654 // instead of arg in a prospective error message. This is useful if
3655 // arg is not the actual argument but rather a transformation of it.
3657 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3658 // and an error message using disp is produced unconditionally.
3660 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3661 SCM arg, SCM args, SCM pred, SCM disp)
3663 if (SCM_UNBNDP (arg))
3664 args = scm_cons (disp, args);
3666 args = scm_cons (arg, args);
3667 if (scm_is_true (scm_call_1 (pred, arg)))
3670 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3671 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3672 SCM_UNBNDP (disp) ? arg : disp);
3673 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3677 SCM loc_on_music (Input loc, SCM arg)
3679 if (Music *m = unsmob_music (arg))
3683 return m->unprotect ();
3689 try_string_variants (SCM pred, SCM str)
3691 // a matching predicate is always ok
3692 if (scm_is_true (scm_call_1 (pred, str)))
3694 // a symbol may be interpreted as a list of symbols if it helps
3695 if (scm_is_symbol (str)) {
3696 str = scm_list_1 (str);
3697 if (scm_is_true (scm_call_1 (pred, str)))
3699 return SCM_UNDEFINED;
3702 // If this cannot be a string representation of a symbol list,
3705 if (!is_regular_identifier (str, true))
3706 return SCM_UNDEFINED;
3708 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3709 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3710 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3712 // Let's attempt the symbol list interpretation first.
3714 if (scm_is_true (scm_call_1 (pred, str)))
3717 // If there is just one symbol in the list, we might interpret
3718 // it as a single symbol
3720 if (scm_is_null (scm_cdr (str)))
3722 str = scm_car (str);
3723 if (scm_is_true (scm_call_1 (pred, str)))
3727 return SCM_UNDEFINED;
3731 is_regular_identifier (SCM id, bool multiple)
3733 if (!scm_is_string (id))
3736 string str = ly_scm2string (id);
3738 bool middle = false;
3740 for (string::iterator it=str.begin(); it != str.end (); it++)
3743 if ((c >= 'a' && c <= 'z')
3744 || (c >= 'A' && c <= 'Z')
3747 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3756 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3758 if (unsmob_music (simple))
3760 if (parser->lexer_->is_note_state ()) {
3761 if (scm_is_symbol (simple)) {
3762 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3763 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3764 n->set_property ("drum-type", simple);
3765 return n->unprotect ();
3767 if (unsmob_pitch (simple)) {
3768 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3769 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3770 n->set_property ("pitch", simple);
3771 return n->unprotect ();
3774 } else if (parser->lexer_->is_lyric_state ()) {
3775 if (Text_interface::is_markup (simple))
3776 return MAKE_SYNTAX ("lyric-event", loc, simple,
3777 parser->default_duration_.smobbed_copy ());
3778 } else if (parser->lexer_->is_chord_state ()) {
3779 if (unsmob_pitch (simple))
3780 return make_chord_elements (loc, simple,
3781 parser->default_duration_.smobbed_copy (),
3788 make_music_with_input (SCM name, Input where)
3790 Music *m = make_music_by_name (name);
3791 m->set_spot (where);
3796 make_simple_markup (SCM a)
3802 make_duration (SCM d, int dots)
3804 int t = scm_to_int (d);
3805 if (t > 0 && (t & (t-1)) == 0)
3806 return Duration (intlog2 (t), dots).smobbed_copy ();
3808 return SCM_UNDEFINED;
3812 make_chord_step (SCM step_scm, Rational alter)
3814 int step = scm_to_int (step_scm);
3817 alter += FLAT_ALTERATION;
3821 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3822 return m.smobbed_copy ();
3827 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3829 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3830 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3831 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3833 unsmob_music (scm_car (s))->set_spot (loc);
3839 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3841 Lily_lexer *lex = parser->lexer_;
3845 lex->prepare_for_next_token ();
3846 return lex->yylex ();