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 (), parser->lexer_->override_input (location).smobbed_copy (), ##__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 (), parser->lexer_->override_input (location).smobbed_copy (), 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 (Book::unsmob($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 (Score::unsmob ($1))
449 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
450 scm_call_2 (proc, parser->self_scm (), $1);
451 } else if (Output_def * od = Output_def::unsmob ($1)) {
454 if (od->c_variable ("is-paper") == SCM_BOOL_T)
455 id = ly_symbol2scm ("$defaultpaper");
456 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
457 id = ly_symbol2scm ("$defaultmidi");
458 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
459 id = ly_symbol2scm ("$defaultlayout");
461 parser->lexer_->set_identifier (id, $1);
462 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
463 parser->parser_error (@1, _("bad expression type"));
467 Output_def * od = Output_def::unsmob ($1);
469 if (od->c_variable ("is-paper") == SCM_BOOL_T)
470 id = ly_symbol2scm ("$defaultpaper");
471 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
472 id = ly_symbol2scm ("$defaultmidi");
473 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
474 id = ly_symbol2scm ("$defaultlayout");
476 parser->lexer_->set_identifier (id, $1);
483 $$ = parser->lexer_->eval_scm_token ($1, @1);
493 embedded_scm_bare_arg:
497 $$ = parser->lexer_->eval_scm_token ($1, @1);
501 | context_modification
503 | context_def_spec_block
509 /* The generic version may end in music, or not */
516 /* embedded_scm_arg is _not_ casting pitches to music by default, this
517 * has to be done by the function itself. Note that this may cause
518 * the results of scm_function_call or embedded_scm_bare_arg to be
519 * turned into music from pitches as well. Note that this creates a
520 * distinctly awkward situation for calculated drum pitches. Those
521 * are at the current point of time rejected as music constituents as
522 * they can't be distinguished from "proper" symbols.
526 embedded_scm_bare_arg
532 SCM_FUNCTION function_arglist {
533 $$ = MAKE_SYNTAX ("music-function", @$,
538 embedded_lilypond_number:
539 '-' embedded_lilypond_number
541 $$ = scm_difference ($2, SCM_UNDEFINED);
544 | UNSIGNED NUMBER_IDENTIFIER
546 $$ = scm_product ($1, $2);
553 // FIXME: @$ does not contain a useful source location
554 // for empty rules, and the only token in the whole
555 // production, EMBEDDED_LILY, is synthetic and also
556 // contains no source location.
557 $$ = MAKE_SYNTAX ("void-music", @$);
559 | identifier_init_nonumber
560 | embedded_lilypond_number
561 | post_event post_events
563 $$ = scm_reverse_x ($2, SCM_EOL);
564 if (Music *m = Music::unsmob ($1))
566 if (m->is_mus_type ("post-event-wrapper"))
568 (scm_list_2 (m->get_property ("elements"),
571 $$ = scm_cons ($1, $$);
574 && scm_is_null (scm_cdr ($$)))
578 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
579 m->set_property ("elements", $$);
580 $$ = m->unprotect ();
583 | multiplied_duration
584 | music_embedded music_embedded music_list {
585 $3 = scm_reverse_x ($3, SCM_EOL);
586 if (Music::unsmob ($2))
587 $3 = scm_cons ($2, $3);
588 if (Music::unsmob ($1))
589 $3 = scm_cons ($1, $3);
590 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
593 parser->error_level_ = 1;
594 $$ = SCM_UNSPECIFIED;
596 | INVALID embedded_lilypond {
597 parser->error_level_ = 1;
603 lilypond_header_body:
604 /* empty */ { $$ = SCM_UNSPECIFIED; }
605 | lilypond_header_body assignment {
608 | lilypond_header_body embedded_scm {
614 HEADER '{' lilypond_header_body '}' {
615 $$ = parser->lexer_->remove_scope ();
627 assignment_id '=' identifier_init {
628 parser->lexer_->set_identifier ($1, $3);
629 $$ = SCM_UNSPECIFIED;
631 | assignment_id property_path '=' identifier_init {
632 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
633 parser->lexer_->set_identifier (path, $4);
634 $$ = SCM_UNSPECIFIED;
636 | assignment_id '.' property_path '=' identifier_init {
637 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
638 parser->lexer_->set_identifier (path, $5);
639 $$ = SCM_UNSPECIFIED;
645 identifier_init_nonumber
647 | post_event_nofinger post_events
649 $$ = scm_reverse_x ($2, SCM_EOL);
650 if (Music *m = Music::unsmob ($1))
652 if (m->is_mus_type ("post-event-wrapper"))
654 (scm_list_2 (m->get_property ("elements"),
657 $$ = scm_cons ($1, $$);
660 && scm_is_null (scm_cdr ($$)))
664 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
665 m->set_property ("elements", $$);
666 $$ = m->unprotect ();
671 identifier_init_nonumber:
676 | context_def_spec_block
683 | context_modification
686 context_def_spec_block:
687 CONTEXT '{' context_def_spec_body '}'
690 Context_def *td = Context_def::unsmob ($$);
692 $$ = Context_def::make_scm ();
693 td = Context_def::unsmob ($$);
695 td->origin ()->set_spot (@$);
703 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
704 parser->lexer_->push_note_state (nn);
708 parser->lexer_->pop_state ();
714 context_def_spec_body:
716 $$ = SCM_UNSPECIFIED;
718 | context_def_spec_body context_mod {
719 if (!SCM_UNBNDP ($2)) {
720 Context_def *td = Context_def::unsmob ($$);
722 $$ = Context_def::make_scm ();
723 td = Context_def::unsmob ($$);
725 Context_def::unsmob ($$)->add_context_mod ($2);
728 | context_def_spec_body context_modification {
729 Context_def *td = Context_def::unsmob ($$);
731 $$ = Context_def::make_scm ();
732 td = Context_def::unsmob ($$);
734 SCM new_mods = Context_mod::unsmob ($2)->get_mods ();
735 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
736 td->add_context_mod (scm_car (m));
739 | context_def_spec_body context_mod_arg {
740 Context_def *td = Context_def::unsmob ($1);
741 if (scm_is_eq ($2, SCM_UNSPECIFIED))
743 else if (!td && Context_def::unsmob ($2))
747 $$ = Context_def::make_scm ();
748 td = Context_def::unsmob ($$);
750 if (Music::unsmob ($2)) {
751 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
752 $2 = scm_call_2 (proc, parser->self_scm (), $2);
754 if (Context_mod *cm = Context_mod::unsmob ($2)) {
755 for (SCM m = cm->get_mods (); scm_is_pair (m); m = scm_cdr (m)) {
756 td->add_context_mod (scm_car (m));
759 parser->parser_error (@2, _ ("not a context mod"));
767 BOOK '{' book_body '}' {
769 Book::unsmob ($$)->origin ()->set_spot (@$);
771 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
776 * Use 'handlers' like for toplevel-* stuff?
777 * grok \layout and \midi? */
780 Book *book = new Book;
781 init_papers (parser);
782 book->paper_ = dynamic_cast<Output_def*> (Output_def::unsmob (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
783 book->paper_->unprotect ();
784 push_paper (parser, book->paper_);
785 book->header_ = get_header (parser);
786 $$ = book->unprotect ();
787 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
790 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
792 | book_body paper_block {
793 Book::unsmob ($1)->paper_ = Output_def::unsmob ($2);
794 set_paper (parser, Output_def::unsmob ($2));
796 | book_body bookpart_block {
797 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
798 scm_call_2 (proc, $1, $2);
800 | book_body score_block {
801 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
802 scm_call_2 (proc, $1, $2);
804 | book_body composite_music {
805 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
806 scm_call_3 (proc, parser->self_scm (), $1, $2);
808 | book_body full_markup {
809 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
810 scm_call_2 (proc, $1, scm_list_1 ($2));
812 | book_body full_markup_list {
813 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
814 scm_call_2 (proc, $1, $2);
816 | book_body SCM_TOKEN {
817 // Evaluate and ignore #xxx, as opposed to \xxx
818 parser->lexer_->eval_scm_token ($2, @2);
820 | book_body embedded_scm_active
822 SCM out = SCM_UNDEFINED;
823 if (Text_interface::is_markup ($2))
824 out = scm_list_1 ($2);
825 else if (Text_interface::is_markup_list ($2))
827 if (scm_is_pair (out))
829 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
830 scm_call_2 (proc, $1, out);
831 } else if (Score::unsmob ($2))
833 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
834 scm_call_2 (proc, $1, $2);
835 } else if (Output_def *od = Output_def::unsmob ($2)) {
838 if (od->c_variable ("is-paper") == SCM_BOOL_T)
839 id = ly_symbol2scm ("$defaultpaper");
840 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
841 id = ly_symbol2scm ("$defaultmidi");
842 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
843 id = ly_symbol2scm ("$defaultlayout");
845 parser->lexer_->set_identifier (id, $2);
846 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
847 parser->parser_error (@2, _("bad expression type"));
851 parser->lexer_->add_scope (Book::unsmob ($1)->header_);
854 Book *book = Book::unsmob ($1);
856 book->scores_ = SCM_EOL;
857 book->bookparts_ = SCM_EOL;
862 BOOKPART '{' bookpart_body '}' {
864 Book::unsmob ($$)->origin ()->set_spot (@$);
865 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
871 Book *book = new Book;
872 $$ = book->unprotect ();
873 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
876 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
878 | bookpart_body paper_block {
879 Book::unsmob ($$)->paper_ = Output_def::unsmob ($2);
881 | bookpart_body score_block {
882 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
883 scm_call_2 (proc, $1, $2);
885 | bookpart_body composite_music {
886 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
887 scm_call_3 (proc, parser->self_scm (), $1, $2);
889 | bookpart_body full_markup {
890 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
891 scm_call_2 (proc, $1, scm_list_1 ($2));
893 | bookpart_body full_markup_list {
894 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
895 scm_call_2 (proc, $1, $2);
897 | bookpart_body SCM_TOKEN {
898 // Evaluate and ignore #xxx, as opposed to \xxx
899 parser->lexer_->eval_scm_token ($2, @2);
901 | bookpart_body embedded_scm_active
903 SCM out = SCM_UNDEFINED;
904 if (Text_interface::is_markup ($2))
905 out = scm_list_1 ($2);
906 else if (Text_interface::is_markup_list ($2))
908 if (scm_is_pair (out))
910 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
911 scm_call_2 (proc, $1, out);
912 } else if (Score::unsmob ($2))
914 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
915 scm_call_2 (proc, $1, $2);
916 } else if (Output_def *od = Output_def::unsmob ($2)) {
919 if (od->c_variable ("is-paper") == SCM_BOOL_T)
920 id = ly_symbol2scm ("$defaultpaper");
921 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
922 id = ly_symbol2scm ("$defaultmidi");
923 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
924 id = ly_symbol2scm ("$defaultlayout");
926 parser->lexer_->set_identifier (id, $2);
927 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
928 parser->parser_error (@2, _("bad expression type"));
932 Book *book = Book::unsmob ($1);
933 if (!ly_is_module (book->header_))
934 book->header_ = ly_make_module (false);
935 parser->lexer_->add_scope (book->header_);
937 | bookpart_body error {
938 Book *book = Book::unsmob ($1);
940 book->scores_ = SCM_EOL;
945 SCORE '{' score_body '}' {
946 Score::unsmob ($3)->origin ()->set_spot (@$);
953 if (!Score::unsmob ($1)) {
954 parser->parser_error (@1, _("Missing music in \\score"));
955 $$ = (new Score)->unprotect ();
956 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
958 Score::unsmob ($$)->set_header (scm_car ($1));
961 for (SCM p = scm_reverse_x ($1, SCM_EOL);
962 scm_is_pair (p); p = scm_cdr (p))
965 add_output_def (Output_def::unsmob (scm_car (p)));
970 Score::unsmob ($$)->error_found_ = true;
985 | score_items score_item
987 Output_def *od = Output_def::unsmob ($2);
989 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
991 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
993 $2 = SCM_UNSPECIFIED;
995 } else if (!Score::unsmob ($$)) {
996 if (Music::unsmob ($2)) {
997 SCM scorify = ly_lily_module_constant ("scorify-music");
998 $2 = scm_call_2 (scorify, $2, parser->self_scm ());
1000 if (Score::unsmob ($2))
1003 $2 = SCM_UNSPECIFIED;
1006 Score *score = Score::unsmob ($$);
1007 if (score && scm_is_pair ($1)) {
1008 if (ly_is_module (scm_car ($1)))
1010 score->set_header (scm_car ($1));
1013 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1014 scm_is_pair (p); p = scm_cdr (p))
1016 score->add_output_def (Output_def::unsmob (scm_car (p)));
1021 score->add_output_def (od);
1022 else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1023 scm_set_cdr_x ($$, scm_cons ($2, scm_cdr ($$)));
1025 $$ = scm_cons ($2, $$);
1026 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1027 parser->parser_error (@2, _("Spurious expression in \\score"));
1031 if (Score *score = Score::unsmob ($1)) {
1032 if (!ly_is_module (score->get_header ()))
1033 score->set_header (ly_make_module (false));
1034 parser->lexer_->add_scope (score->get_header ());
1036 if (!scm_is_pair ($1) || !ly_is_module (scm_car ($1)))
1037 $1 = scm_cons (ly_make_module (false), $1);
1038 parser->lexer_->add_scope (scm_car ($1));
1053 Output_def *od = Output_def::unsmob ($1);
1055 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1057 parser->parser_error (@1, _ ("need \\paper for paper block"));
1058 $$ = get_paper (parser)->unprotect ();
1065 output_def_body '}' {
1066 if (scm_is_pair ($1))
1069 parser->lexer_->remove_scope ();
1070 parser->lexer_->pop_state ();
1076 Output_def *p = get_paper (parser);
1077 p->input_origin_ = @$;
1078 parser->lexer_->add_scope (p->scope_);
1079 $$ = p->unprotect ();
1082 Output_def *p = get_midi (parser);
1083 $$ = p->unprotect ();
1084 parser->lexer_->add_scope (p->scope_);
1087 Output_def *p = get_layout (parser);
1089 parser->lexer_->add_scope (p->scope_);
1090 $$ = p->unprotect ();
1094 output_def_head_with_mode_switch:
1096 parser->lexer_->push_initial_state ();
1101 // We need this weird nonterminal because both music as well as a
1102 // context definition can start with \context and the difference is
1103 // only apparent after looking at the next token. If it is '{', there
1104 // is still time to escape from notes mode.
1106 music_or_context_def:
1108 | context_def_spec_block
1112 output_def_head_with_mode_switch '{' {
1113 Output_def::unsmob ($1)->input_origin_.set_spot (@$);
1114 // This is a stupid trick to mark the beginning of the
1115 // body for deciding whether to allow
1116 // embedded_scm_active to have an output definition
1117 $$ = scm_list_1 ($1);
1119 | output_def_body assignment {
1120 if (scm_is_pair ($1))
1123 | output_def_body embedded_scm_active
1125 // We don't switch into note mode for Scheme functions
1126 // here. Does not seem warranted/required in output
1128 if (scm_is_pair ($1))
1130 Output_def *o = Output_def::unsmob ($2);
1132 o->input_origin_.set_spot (@$);
1133 $1 = o->self_scm ();
1134 parser->lexer_->remove_scope ();
1135 parser->lexer_->add_scope (o->scope_);
1136 $2 = SCM_UNSPECIFIED;
1140 if (Context_def::unsmob ($2))
1141 assign_context_def (Output_def::unsmob ($1), $2);
1142 // Seems unlikely, but let's be complete:
1143 else if (Music::unsmob ($2))
1145 SCM proc = parser->lexer_->lookup_identifier
1146 ("output-def-music-handler");
1147 scm_call_3 (proc, parser->self_scm (),
1149 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1150 parser->parser_error (@2, _("bad expression type"));
1153 | output_def_body SCM_TOKEN {
1154 if (scm_is_pair ($1))
1156 // Evaluate and ignore #xxx, as opposed to \xxx
1157 parser->lexer_->eval_scm_token ($2, @2);
1161 if (scm_is_pair ($1))
1163 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1164 parser->lexer_->push_note_state (nn);
1165 } music_or_context_def
1167 parser->lexer_->pop_state ();
1168 if (Context_def::unsmob ($3))
1169 assign_context_def (Output_def::unsmob ($1), $3);
1172 SCM proc = parser->lexer_->lookup_identifier
1173 ("output-def-music-handler");
1174 scm_call_3 (proc, parser->self_scm (),
1179 | output_def_body error {
1185 TEMPO steno_duration '=' tempo_range {
1186 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1188 | TEMPO scalar steno_duration '=' tempo_range {
1189 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1192 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1197 The representation of a list is reversed to have efficient append. */
1203 | music_list music_embedded {
1204 if (Music::unsmob ($2))
1205 $$ = scm_cons ($2, $1);
1207 | music_list error {
1208 Music *m = MY_MAKE_MUSIC("Music", @$);
1210 m->set_property ("error-found", SCM_BOOL_T);
1211 $$ = scm_cons (m->self_scm (), $1);
1212 m->unprotect (); /* UGH */
1219 $$ = scm_reverse_x ($2, SCM_EOL);
1224 | lyric_element_music
1227 $$ = make_music_from_simple (parser, @1, $1);
1228 if (!Music::unsmob ($$))
1230 parser->parser_error (@1, _ ("music expected"));
1231 $$ = MAKE_SYNTAX ("void-music", @$);
1239 if (Music::unsmob ($1)->is_mus_type ("post-event")) {
1240 parser->parser_error (@1, _ ("unexpected post-event"));
1241 $$ = SCM_UNSPECIFIED;
1244 | music_embedded_backup
1248 | music_embedded_backup BACKUP lyric_element_music
1252 | multiplied_duration post_events
1254 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1256 parser->default_duration_ = *Duration::unsmob ($1);
1257 n->set_property ("duration", $1);
1259 if (scm_is_pair ($2))
1260 n->set_property ("articulations",
1261 scm_reverse_x ($2, SCM_EOL));
1262 $$ = n->unprotect ();
1266 music_embedded_backup:
1269 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1271 else if (Music *m = Music::unsmob ($1)) {
1272 if (m->is_mus_type ("post-event")) {
1273 parser->parser_error
1274 (@1, _ ("unexpected post-event"));
1275 $$ = SCM_UNSPECIFIED;
1278 } else if (parser->lexer_->is_lyric_state ()
1279 && Text_interface::is_markup ($1))
1280 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1282 @$.warning (_ ("Ignoring non-music expression"));
1288 // music_assign does not need to contain lyrics: there are no
1289 // assignments in lyricmode.
1292 | composite_music %prec COMPOSITE
1296 REPEAT simple_string unsigned_number music
1298 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1300 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1302 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1307 SEQUENTIAL braced_music_list {
1308 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1310 | braced_music_list {
1311 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1316 SIMULTANEOUS braced_music_list {
1317 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1319 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1320 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1326 | music_property_def
1330 context_modification:
1333 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1334 parser->lexer_->push_note_state (nn);
1335 } '{' context_mod_list '}'
1337 parser->lexer_->pop_state ();
1340 | WITH CONTEXT_MOD_IDENTIFIER
1344 | CONTEXT_MOD_IDENTIFIER
1348 | WITH context_modification_arg
1350 if (Music::unsmob ($2)) {
1351 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1352 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1354 if (Context_mod::unsmob ($2))
1357 parser->parser_error (@2, _ ("not a context mod"));
1358 $$ = Context_mod ().smobbed_copy ();
1363 context_modification_arg:
1368 optional_context_mod:
1372 | context_modification
1380 $$ = Context_mod ().smobbed_copy ();
1382 | context_mod_list context_mod {
1383 if (!SCM_UNBNDP ($2))
1384 Context_mod::unsmob ($1)->add_context_mod ($2);
1386 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1387 Context_mod *md = Context_mod::unsmob ($2);
1389 Context_mod::unsmob ($1)->add_context_mods (md->get_mods ());
1391 | context_mod_list context_mod_arg {
1392 if (scm_is_eq ($2, SCM_UNSPECIFIED))
1394 else if (Music::unsmob ($2)) {
1395 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1396 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1398 if (Context_mod::unsmob ($2))
1399 Context_mod::unsmob ($$)->add_context_mods
1400 (Context_mod::unsmob ($2)->get_mods ());
1402 parser->parser_error (@2, _ ("not a context mod"));
1408 CONTEXT symbol optional_id optional_context_mod {
1409 Context_mod *ctxmod = Context_mod::unsmob ($4);
1412 mods = ctxmod->get_mods ();
1413 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1415 | NEWCONTEXT symbol optional_id optional_context_mod {
1416 Context_mod *ctxmod = Context_mod::unsmob ($4);
1419 mods = ctxmod->get_mods ();
1420 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1426 | repeated_music { $$ = $1; }
1427 | re_rhythmed_music { $$ = $1; }
1428 | context_prefix music
1430 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1438 | grouped_music_list
1442 simultaneous_music { $$ = $1; }
1443 | sequential_music { $$ = $1; }
1446 /* Function argument lists are arguably the most complex part in the
1447 * parser. They are pretty tricky to understand because of the way
1448 * they are processed, and because of optional arguments that can be
1449 * omitted. When there are several optional arguments in a row,
1450 * omitting one automatically omits all following arguments. Optional
1451 * arguments can only be omitted when either
1453 * a) the omission is explicitly started with \default
1454 * b) the omission is implicitly started by an argument not matching
1455 * its predicate, and there is a mandatory argument later that can
1456 * "catch" the argument that does not fit.
1458 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1459 * (corresponding to mandatory arguments and having a predicate
1460 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1461 * the semantic value of the EXPECT_OPTIONAL token is the default to
1462 * use when the optional argument is omitted, and EXPECT_SCM again has
1463 * the argument predicate as semantic value) in reverse order to the
1464 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1465 * processed inside-out while actual tokens are consumed.
1467 * This means that the argument list tokens determine the actions
1468 * taken as they arrive. The structure of the argument list is known
1469 * to the parser and stored in its parse stack when the first argument
1470 * is being parsed. What the parser does not know is which predicates
1471 * will match and whether or not \default will be appearing in the
1472 * argument list, and where.
1474 * Sequences of 0 or more optional arguments are scanned using either
1475 * function_arglist_backup or function_arglist_nonbackup. The first
1476 * is used when optional arguments are followed by at least one
1477 * mandatory argument: in that case optional arguments may be skipped
1478 * by either a false predicate (in which case the expression will be
1479 * pushed back as one or more tokens, preceded by a BACKUP token) or
1480 * by using \default.
1482 * If optional arguments are at the end of the argument list, they are
1483 * instead scanned using function_arglist_nonbackup: here the only
1484 * manner to enter into skipping of optional arguments is the use of
1487 * The argument list of a normal function call is parsed using
1488 * function_arglist. The part of an argument list before a mandatory
1489 * argument is parsed using function_arglist_optional.
1491 * The difference is that leading optional arguments are scanned using
1492 * function_arglist_nonbackup and function_arglist_backup,
1495 * Most other details are obvious in the rules themselves.
1501 | SYMBOL_LIST '.' symbol_list_rev
1503 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1509 | symbol_list_rev '.' symbol_list_part
1511 $$ = scm_append_x (scm_list_2 ($3, $1));
1515 // symbol_list_part delivers elements in reverse copy.
1520 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1521 $$ = try_string_variants (sym_l_p, $1);
1522 if (SCM_UNBNDP ($$)) {
1523 parser->parser_error (@1, _("not a symbol"));
1526 $$ = scm_reverse ($$);
1531 symbol_list_element:
1537 function_arglist_nonbackup:
1538 function_arglist_common
1539 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1541 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1543 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1545 SCM n = scm_difference ($5, SCM_UNDEFINED);
1546 if (scm_is_true (scm_call_1 ($2, n)))
1547 $$ = scm_cons (n, $3);
1549 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1550 t->set_property ("digit", $5);
1551 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1555 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1557 $$ = check_scheme_arg (parser, @4,
1558 scm_difference ($5, SCM_UNDEFINED),
1561 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1563 $$ = check_scheme_arg (parser, @4,
1564 scm_difference ($5, SCM_UNDEFINED),
1567 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1569 if (scm_is_true (scm_call_1 ($2, $4)))
1570 $$ = scm_cons ($4, $3);
1572 $$ = check_scheme_arg (parser, @4,
1573 make_music_from_simple
1577 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1579 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1581 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1583 if (scm_is_true (scm_call_1 ($2, $3)))
1584 $$ = scm_cons ($3, $1);
1586 $$ = check_scheme_arg (parser, @3,
1587 make_music_from_simple
1591 | function_arglist_nonbackup_reparse REPARSE duration_length
1593 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1595 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1597 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1599 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1601 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1603 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1605 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1607 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1609 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1613 function_arglist_nonbackup_reparse:
1614 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1617 SCM res = try_string_variants ($2, $4);
1618 if (!SCM_UNBNDP (res))
1619 if (scm_is_pair (res))
1620 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1622 MYREPARSE (@4, $2, SCM_ARG, res);
1623 else if (scm_is_true
1625 ($2, make_music_from_simple
1627 MYREPARSE (@4, $2, STRING, $4);
1629 MYREPARSE (@4, $2, SCM_ARG, $4);
1631 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1636 ($2, make_music_from_simple
1638 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1640 MYREPARSE (@4, $2, SCM_ARG, $4);
1642 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1647 ($2, make_music_from_simple
1649 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1651 MYREPARSE (@4, $2, SCM_ARG, $4);
1653 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1656 SCM res = try_string_variants ($2, $4);
1657 if (!SCM_UNBNDP (res))
1658 if (scm_is_pair (res))
1659 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1661 MYREPARSE (@4, $2, SCM_ARG, res);
1662 else if (scm_is_true
1664 ($2, make_music_from_simple
1666 MYREPARSE (@4, $2, STRING, $4);
1668 MYREPARSE (@4, $2, SCM_ARG, $4);
1670 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1673 if (scm_is_true (scm_call_1 ($2, $4)))
1674 MYREPARSE (@4, $2, SCM_ARG, $4);
1675 else if (scm_is_true
1677 ($2, make_music_from_simple
1679 MYREPARSE (@4, $2, STRING, $4);
1681 MYREPARSE (@4, $2, SCM_ARG, $4);
1683 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1686 if (scm_is_true (scm_call_1 ($2, $4)))
1687 MYREPARSE (@4, $2, REAL, $4);
1689 SCM d = make_duration ($4);
1690 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1691 MYREPARSE (@4, $2, REAL, $4); // trigger error
1693 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1696 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1698 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1703 // function_arglist_backup can't occur at the end of an argument
1705 function_arglist_backup:
1706 function_arglist_common
1707 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1709 if (scm_is_true (scm_call_1 ($2, $4)))
1710 $$ = scm_cons ($4, $3);
1712 $$ = make_music_from_simple (parser, @4, $4);
1713 if (scm_is_true (scm_call_1 ($2, $$)))
1714 $$ = scm_cons ($$, $3);
1717 $$ = scm_cons (loc_on_music (@3, $1), $3);
1718 MYBACKUP (SCM_ARG, $4, @4);
1722 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1724 if (scm_is_true (scm_call_1 ($2, $4)))
1726 $$ = scm_cons ($4, $3);
1728 $$ = scm_cons (loc_on_music (@3, $1), $3);
1729 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1732 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1736 ($2, make_music_from_simple
1740 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1741 } else if (scm_is_true (scm_call_1 ($2, $4)))
1742 $$ = scm_cons ($4, $3);
1744 $$ = scm_cons (loc_on_music (@3, $1), $3);
1745 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1748 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1752 ($2, make_music_from_simple
1756 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1757 } else if (scm_is_true (scm_call_1 ($2, $4)))
1758 $$ = scm_cons ($4, $3);
1760 $$ = scm_cons (loc_on_music (@3, $1), $3);
1761 MYBACKUP (TONICNAME_PITCH, $4, @4);
1764 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1766 if (scm_is_true (scm_call_1 ($2, $4)))
1767 $$ = scm_cons ($4, $3);
1769 $$ = scm_cons (loc_on_music (@3, $1), $3);
1770 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1773 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1775 if (scm_is_true (scm_call_1 ($2, $4)))
1777 MYREPARSE (@4, $2, REAL, $4);
1780 SCM d = make_duration ($4);
1781 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1783 $$ = scm_cons (loc_on_music (@3, $1), $3);
1784 MYBACKUP (UNSIGNED, $4, @4);
1786 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1791 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1793 if (scm_is_true (scm_call_1 ($2, $4)))
1796 MYREPARSE (@4, $2, REAL, $4);
1798 $$ = scm_cons (loc_on_music (@3, $1), $3);
1799 MYBACKUP (REAL, $4, @4);
1802 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1804 if (scm_is_true (scm_call_1 ($2, $4)))
1806 $$ = scm_cons ($4, $3);
1808 $$ = scm_cons (loc_on_music (@3, $1), $3);
1809 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1812 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1814 SCM n = scm_difference ($5, SCM_UNDEFINED);
1815 if (scm_is_true (scm_call_1 ($2, n))) {
1817 MYREPARSE (@5, $2, REAL, n);
1819 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1820 t->set_property ("digit", $5);
1821 $$ = t->unprotect ();
1822 if (scm_is_true (scm_call_1 ($2, $$)))
1823 $$ = scm_cons ($$, $3);
1825 $$ = scm_cons (loc_on_music (@3, $1), $3);
1826 MYBACKUP (UNSIGNED, $5, @5);
1827 parser->lexer_->push_extra_token (@4, '-');
1831 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1833 SCM n = scm_difference ($5, SCM_UNDEFINED);
1834 if (scm_is_true (scm_call_1 ($2, n))) {
1835 MYREPARSE (@5, $2, REAL, n);
1838 $$ = scm_cons (loc_on_music (@3, $1), $3);
1839 MYBACKUP (REAL, n, @5);
1842 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1844 SCM n = scm_difference ($5, SCM_UNDEFINED);
1845 if (scm_is_true (scm_call_1 ($2, n))) {
1846 $$ = scm_cons (n, $3);
1848 $$ = scm_cons (loc_on_music (@3, $1), $3);
1849 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1852 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1854 if (scm_is_true (scm_call_1 ($2, $4)))
1856 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1859 $$ = scm_cons (loc_on_music (@3, $1), $3);
1860 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1863 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1865 SCM res = try_string_variants ($2, $4);
1866 if (!SCM_UNBNDP (res))
1867 if (scm_is_pair (res)) {
1869 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1872 $$ = scm_cons (res, $3);
1874 $$ = scm_cons (loc_on_music (@3, $1), $3);
1875 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1878 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1880 SCM res = try_string_variants ($2, $4);
1881 if (!SCM_UNBNDP (res))
1882 if (scm_is_pair (res)) {
1884 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1887 $$ = scm_cons (res, $3);
1889 $$ = scm_cons (loc_on_music (@3, $1), $3);
1890 MYBACKUP (STRING, $4, @4);
1893 | function_arglist_backup REPARSE pitch_or_music
1895 if (scm_is_true (scm_call_1 ($2, $3)))
1896 $$ = scm_cons ($3, $1);
1898 $$ = check_scheme_arg (parser, @3,
1899 make_music_from_simple
1903 | function_arglist_backup REPARSE bare_number_common
1905 $$ = check_scheme_arg (parser, @3,
1908 | function_arglist_backup REPARSE duration_length
1910 $$ = check_scheme_arg (parser, @3,
1913 | function_arglist_backup REPARSE symbol_list_arg
1915 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1920 function_arglist_nonbackup
1921 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1923 $$ = scm_cons (loc_on_music (@4, $1), $3);
1927 function_arglist_skip_nonbackup:
1928 function_arglist_nonbackup
1929 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1931 $$ = scm_cons (loc_on_music (@3, $1), $3);
1935 function_arglist_common:
1936 EXPECT_NO_MORE_ARGS {
1939 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1941 if (scm_is_true (scm_call_1 ($1, $3)))
1942 $$ = scm_cons ($3, $2);
1944 $$ = check_scheme_arg (parser, @3,
1945 make_music_from_simple
1949 | EXPECT_SCM function_arglist_optional bare_number_common
1951 $$ = check_scheme_arg (parser, @3,
1954 | EXPECT_SCM function_arglist_optional post_event_nofinger
1956 $$ = check_scheme_arg (parser, @3,
1959 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1961 SCM n = scm_difference ($4, SCM_UNDEFINED);
1962 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1964 | function_arglist_common_reparse REPARSE SCM_ARG
1966 $$ = check_scheme_arg (parser, @3,
1969 | function_arglist_common_reparse REPARSE lyric_element_music
1971 $$ = check_scheme_arg (parser, @3,
1974 | function_arglist_common_reparse REPARSE pitch_or_music
1976 if (scm_is_true (scm_call_1 ($2, $3)))
1977 $$ = scm_cons ($3, $1);
1979 $$ = check_scheme_arg (parser, @3,
1980 make_music_from_simple
1984 | function_arglist_common_reparse REPARSE bare_number_common
1986 $$ = check_scheme_arg (parser, @3,
1989 | function_arglist_common_reparse REPARSE duration_length
1991 $$ = check_scheme_arg (parser, @3,
1994 | function_arglist_common_reparse REPARSE symbol_list_arg
1996 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2000 function_arglist_common_reparse:
2001 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2004 SCM res = try_string_variants ($1, $3);
2005 if (!SCM_UNBNDP (res))
2006 if (scm_is_pair (res))
2007 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2009 MYREPARSE (@3, $1, SCM_ARG, res);
2010 else if (scm_is_true
2012 ($1, make_music_from_simple (parser, @3, $3))))
2013 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2015 // This is going to flag a syntax error, we
2016 // know the predicate to be false.
2017 MYREPARSE (@3, $1, SCM_ARG, $3);
2019 | EXPECT_SCM function_arglist_optional pitch
2024 ($1, make_music_from_simple
2026 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2028 MYREPARSE (@3, $1, SCM_ARG, $3);
2030 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2035 ($1, make_music_from_simple
2037 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2039 MYREPARSE (@3, $1, SCM_ARG, $3);
2041 | EXPECT_SCM function_arglist_optional STRING
2044 SCM res = try_string_variants ($1, $3);
2045 if (!SCM_UNBNDP (res))
2046 if (scm_is_pair (res))
2047 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2049 MYREPARSE (@3, $1, SCM_ARG, res);
2050 else if (scm_is_true
2052 ($1, make_music_from_simple (parser, @3, $3))))
2053 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2055 // This is going to flag a syntax error, we
2056 // know the predicate to be false.
2057 MYREPARSE (@3, $1, SCM_ARG, $3);
2059 | EXPECT_SCM function_arglist_optional full_markup
2062 if (scm_is_true (scm_call_1 ($1, $3)))
2063 MYREPARSE (@3, $1, SCM_ARG, $3);
2064 else if (scm_is_true
2066 ($1, make_music_from_simple (parser, @3, $3))))
2067 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2069 // This is going to flag a syntax error, we
2070 // know the predicate to be false.
2071 MYREPARSE (@3, $1, SCM_ARG, $3);
2073 | EXPECT_SCM function_arglist_optional UNSIGNED
2076 if (scm_is_true (scm_call_1 ($1, $3)))
2077 MYREPARSE (@3, $1, REAL, $3);
2079 SCM d = make_duration ($3);
2080 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
2081 MYREPARSE (@3, $1, REAL, $3);
2083 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2086 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2089 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2091 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2094 SCM n = scm_difference ($4, SCM_UNDEFINED);
2095 if (scm_is_true (scm_call_1 ($1, n)))
2096 MYREPARSE (@4, $1, REAL, n);
2098 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2099 t->set_property ("digit", $4);
2100 SCM m = t->unprotect ();
2101 if (scm_is_true (scm_call_1 ($1, m)))
2102 MYREPARSE (@4, $1, SCM_ARG, m);
2104 MYREPARSE (@4, $1, SCM_ARG, $4);
2107 | EXPECT_SCM function_arglist_optional '-' REAL
2110 SCM n = scm_difference ($4, SCM_UNDEFINED);
2111 MYREPARSE (@4, $1, REAL, n);
2115 function_arglist_optional:
2116 function_arglist_backup
2117 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2119 $$ = scm_cons (loc_on_music (@4, $1), $3);
2121 | function_arglist_skip_backup BACKUP
2124 function_arglist_skip_backup:
2125 function_arglist_backup
2126 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2128 $$ = scm_cons (loc_on_music (@3, $1), $3);
2132 music_function_call:
2133 MUSIC_FUNCTION function_arglist {
2134 $$ = MAKE_SYNTAX ("music-function", @$,
2141 /**/ { $$ = SCM_EOL; }
2142 | '=' simple_string {
2147 // We must not have lookahead tokens parsed in lyric mode. In order
2148 // to save confusion, we take almost the same set as permitted with
2149 // \lyricmode and/or \lyrics. However, music identifiers are also
2150 // allowed, and they obviously do not require switching into lyrics
2151 // mode for parsing.
2155 parser->lexer_->push_lyric_state ();
2156 } grouped_music_list
2158 parser->lexer_->pop_state ();
2165 mode_changing_head grouped_music_list {
2166 if ($1 == ly_symbol2scm ("chords"))
2168 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2174 parser->lexer_->pop_state ();
2176 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2177 Context_mod *ctxmod = Context_mod::unsmob ($2);
2180 mods = ctxmod->get_mods ();
2181 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2182 if ($1 == ly_symbol2scm ("ChordNames"))
2184 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2186 parser->lexer_->pop_state ();
2192 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2193 parser->lexer_->push_note_state (nn);
2195 $$ = ly_symbol2scm ("notes");
2199 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2200 parser->lexer_->push_note_state (nn);
2202 $$ = ly_symbol2scm ("drums");
2205 parser->lexer_->push_figuredbass_state ();
2207 $$ = ly_symbol2scm ("figures");
2210 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2211 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2212 nn = parser->lexer_->lookup_identifier ("pitchnames");
2213 parser->lexer_->push_chord_state (nn);
2214 $$ = ly_symbol2scm ("chords");
2218 { parser->lexer_->push_lyric_state ();
2219 $$ = ly_symbol2scm ("lyrics");
2223 mode_changing_head_with_context:
2225 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2226 parser->lexer_->push_note_state (nn);
2228 $$ = ly_symbol2scm ("DrumStaff");
2231 parser->lexer_->push_figuredbass_state ();
2233 $$ = ly_symbol2scm ("FiguredBass");
2236 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2237 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2238 nn = parser->lexer_->lookup_identifier ("pitchnames");
2239 parser->lexer_->push_chord_state (nn);
2240 $$ = ly_symbol2scm ("ChordNames");
2243 { parser->lexer_->push_lyric_state ();
2244 $$ = ly_symbol2scm ("Lyrics");
2249 ADDLYRICS lyric_mode_music {
2250 $$ = scm_list_1 ($2);
2252 | new_lyrics ADDLYRICS lyric_mode_music {
2253 $$ = scm_cons ($3, $1);
2258 composite_music new_lyrics {
2259 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2261 | LYRICSTO simple_string lyric_mode_music {
2262 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $3);
2267 CHANGE symbol '=' simple_string {
2268 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2275 $$ = scm_reverse_x ($1, SCM_EOL);
2277 | symbol_list_rev property_path {
2278 $$ = scm_reverse_x ($1, $2);
2284 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2287 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2289 | OVERRIDE property_path '=' scalar {
2290 if (scm_ilength ($2) < 2) {
2291 parser->parser_error (@2, _("bad grob property path"));
2294 $$ = scm_cons (ly_symbol2scm ("push"),
2295 scm_cons2 (scm_car ($2),
2300 | REVERT revert_arg {
2301 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2305 // This is all quite awkward for the sake of substantial backward
2306 // compatibility while at the same time allowing a more "natural" form
2307 // of specification not separating grob specification from grob
2308 // property path. The purpose of this definition of revert_arg is to
2309 // allow the symbol list which specifies grob and property to revert
2310 // to be optionally be split into two parts after the grob (which in
2311 // this case is just the first element of the list). symbol_list_part
2312 // is only one path component, but it can be parsed without lookahead,
2313 // so we can follow it with a synthetic BACKUP token when needed. If
2314 // the first symbol_list_part already contains multiple elements (only
2315 // possible if a Scheme expression provides them), we just parse for
2316 // additional elements introduced by '.', which is what the
2317 // SYMBOL_LIST backup in connection with the immediately following
2318 // rule using symbol_list_arg does.
2320 // As long as we don't have our coffers filled with both grob and at
2321 // least one grob property specification, the rest of the required
2322 // symbol list chain may be provided either with or without a leading
2323 // dot. This is for both allowing the traditional
2324 // \revert Accidental #'color
2325 // as well as well as the "naive" form
2326 // \revert Accidental.color
2329 revert_arg_backup BACKUP symbol_list_arg
2338 if (scm_is_null ($1)
2339 || scm_is_null (scm_cdr ($1)))
2340 MYBACKUP (SCM_ARG, $1, @1);
2342 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2346 // revert_arg_part delivers results in reverse
2349 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2351 $$ = scm_append_x (scm_list_2 ($5, $3));
2353 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2355 $$ = scm_append_x (scm_list_2 ($4, $3));
2360 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2361 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2363 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2364 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2365 | DENIES { $$ = ly_symbol2scm ("denies"); }
2367 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2368 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2369 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2370 | NAME { $$ = ly_symbol2scm ("context-name"); }
2374 property_operation { $$ = $1; }
2375 | context_def_mod STRING {
2376 $$ = scm_list_2 ($1, $2);
2378 | context_def_mod embedded_scm
2380 if (!scm_is_string ($2)
2381 && ly_symbol2scm ("consists") != $1
2382 && ly_symbol2scm ("remove") != $1)
2385 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2389 $$ = scm_list_2 ($1, $2);
2394 // If defined, at least two members.
2398 SCM l = scm_reverse_x ($1, SCM_EOL);
2401 (scm_object_property (scm_car (l),
2402 ly_symbol2scm ("is-grob?"))))
2403 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2404 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2405 parser->parser_error (@1, _ ("bad grob property path"));
2412 // If defined, at least three members
2416 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2418 parser->parser_error (@1, _ ("bad grob property path"));
2422 | grob_prop_spec property_path
2424 if (!SCM_UNBNDP ($1)) {
2425 $$ = scm_append_x (scm_list_2 ($1, $2));
2426 if (scm_is_null (scm_cddr ($$))) {
2427 parser->parser_error (@$, _ ("bad grob property path"));
2435 // Exactly two elements or undefined
2439 SCM l = scm_reverse_x ($1, SCM_EOL);
2440 switch (scm_ilength (l)) {
2442 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2446 parser->parser_error (@1, _ ("bad context property path"));
2453 simple_music_property_def:
2454 OVERRIDE grob_prop_path '=' scalar {
2455 if (SCM_UNBNDP ($2))
2458 $$ = scm_list_5 (scm_car ($2),
2459 ly_symbol2scm ("OverrideProperty"),
2465 | REVERT simple_revert_context revert_arg {
2466 $$ = scm_list_4 ($2,
2467 ly_symbol2scm ("RevertProperty"),
2471 | SET context_prop_spec '=' scalar {
2472 if (SCM_UNBNDP ($2))
2475 $$ = scm_list_4 (scm_car ($2),
2476 ly_symbol2scm ("PropertySet"),
2480 | UNSET context_prop_spec {
2481 if (SCM_UNBNDP ($2))
2484 $$ = scm_list_3 (scm_car ($2),
2485 ly_symbol2scm ("PropertyUnset"),
2491 // This is all quite awkward for the sake of substantial backward
2492 // compatibility while at the same time allowing a more "natural" form
2493 // of specification not separating grob specification from grob
2494 // property path. The purpose of this definition of
2495 // simple_revert_context is to allow the symbol list which specifies
2496 // grob and property to revert to be optionally be split into two
2497 // parts after the grob (which may be preceded by a context
2498 // specification, a case which we distinguish by checking whether the
2499 // first symbol is a valid grob symbol instead).
2501 // See revert_arg above for the main work horse of this arrangement.
2502 // simple_revert_context just caters for the context and delegates the
2503 // rest of the job to revert_arg.
2505 simple_revert_context:
2508 $1 = scm_reverse_x ($1, SCM_EOL);
2509 if (scm_is_null ($1)
2511 (scm_object_property (scm_car ($1),
2512 ly_symbol2scm ("is-grob?")))) {
2513 $$ = ly_symbol2scm ("Bottom");
2514 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2517 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2524 simple_music_property_def {
2525 if (SCM_UNBNDP ($1))
2526 $$ = MAKE_SYNTAX ("void-music", @1);
2528 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), @$.smobbed_copy (), $1));
2539 simple_string: STRING {
2544 if (scm_is_string ($1)) {
2547 parser->parser_error (@1, (_ ("simple string expected")));
2548 $$ = scm_string (SCM_EOL);
2555 $$ = scm_string_to_symbol ($1);
2559 // This is a bit of overkill but makes the same
2560 // routine responsible for all symbol interpretations.
2561 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2563 if (SCM_UNBNDP ($$))
2565 parser->parser_error (@1, (_ ("symbol expected")));
2566 // Generate a unique symbol in case it is used
2567 // for an assignment or similar
2568 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2578 // The following is a rather defensive variant of admitting
2579 // negative numbers: the grammar would permit number_factor or
2580 // even number_expression. However, function arguments allow
2581 // only this simple kind of negative number, so to have things
2582 // like \tweak and \override behave reasonably similar, it
2583 // makes sense to rule out things like -- which are rather an
2584 // accent in function argument contexts.
2587 $$ = scm_difference ($2, SCM_UNDEFINED);
2593 simple_element post_events {
2594 // Let the rhythmic music iterator sort this mess out.
2595 if (scm_is_pair ($2)) {
2596 Music::unsmob ($$)->set_property ("articulations",
2597 scm_reverse_x ($2, SCM_EOL));
2600 | CHORD_REPETITION optional_notemode_duration post_events {
2602 i.set_location (@1, @3);
2603 $$ = MAKE_SYNTAX ("repetition-chord", i,
2604 $2, scm_reverse_x ($3, SCM_EOL));
2606 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2608 i.set_location (@1, @3);
2609 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2610 scm_reverse_x ($3, SCM_EOL));
2613 | note_chord_element
2618 chord_body optional_notemode_duration post_events
2620 Music *m = Music::unsmob ($1);
2621 SCM dur = Duration::unsmob ($2)->smobbed_copy ();
2622 SCM es = m->get_property ("elements");
2623 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2625 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2626 Music::unsmob (scm_car (s))->set_property ("duration", dur);
2627 es = ly_append2 (es, postevs);
2629 m-> set_property ("elements", es);
2631 $$ = m->self_scm ();
2636 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2638 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2640 | FIGURE_OPEN figure_list FIGURE_CLOSE
2642 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2646 chord_body_elements:
2647 /* empty */ { $$ = SCM_EOL; }
2648 | chord_body_elements chord_body_element {
2649 if (!SCM_UNBNDP ($2))
2650 $$ = scm_cons ($2, $1);
2655 pitch_or_tonic_pitch exclamations questions octave_check post_events
2657 bool q = to_boolean ($3);
2658 bool ex = to_boolean ($2);
2662 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2663 n->set_property ("pitch", $1);
2665 n->set_property ("cautionary", SCM_BOOL_T);
2667 n->set_property ("force-accidental", SCM_BOOL_T);
2669 if (scm_is_pair (post)) {
2670 SCM arts = scm_reverse_x (post, SCM_EOL);
2671 n->set_property ("articulations", arts);
2673 if (scm_is_number (check))
2675 int q = scm_to_int (check);
2676 n->set_property ("absolute-octave", scm_from_int (q-1));
2679 $$ = n->unprotect ();
2681 | DRUM_PITCH post_events {
2682 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2683 n->set_property ("drum-type", $1);
2685 if (scm_is_pair ($2)) {
2686 SCM arts = scm_reverse_x ($2, SCM_EOL);
2687 n->set_property ("articulations", arts);
2689 $$ = n->unprotect ();
2691 | music_function_chord_body
2693 Music *m = Music::unsmob ($1);
2695 while (m && m->is_mus_type ("music-wrapper-music")) {
2696 $$ = m->get_property ("element");
2697 m = Music::unsmob ($$);
2700 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2701 parser->parser_error (@$, _ ("not a rhythmic event"));
2707 music_function_chord_body:
2713 event_function_event:
2714 EVENT_FUNCTION function_arglist {
2715 $$ = MAKE_SYNTAX ("music-function", @$,
2724 | post_events post_event {
2726 if (Music *m = Music::unsmob ($2))
2728 if (m->is_mus_type ("post-event-wrapper"))
2730 for (SCM p = m->get_property ("elements");
2734 $$ = scm_cons (scm_car (p), $$);
2738 $$ = scm_cons ($2, $$);
2744 post_event_nofinger:
2745 direction_less_event {
2748 | script_dir music_function_call {
2750 if (!Music::unsmob ($2)->is_mus_type ("post-event")) {
2751 parser->parser_error (@2, _ ("post-event expected"));
2752 $$ = SCM_UNSPECIFIED;
2753 } else if (!SCM_UNBNDP ($1))
2755 Music::unsmob ($$)->set_property ("direction", $1);
2759 if (!parser->lexer_->is_lyric_state ())
2760 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2761 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2764 if (!parser->lexer_->is_lyric_state ())
2765 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2766 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2768 | script_dir direction_reqd_event {
2769 if (!SCM_UNBNDP ($1))
2771 Music *m = Music::unsmob ($2);
2772 m->set_property ("direction", $1);
2776 | script_dir direction_less_event {
2777 if (!SCM_UNBNDP ($1))
2779 Music *m = Music::unsmob ($2);
2780 m->set_property ("direction", $1);
2787 Music::unsmob ($$)->set_property ("direction", scm_from_int (UP));
2792 Music::unsmob ($$)->set_property ("direction", scm_from_int (DOWN));
2803 string_number_event:
2805 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2806 s->set_property ("string-number", $1);
2807 $$ = s->unprotect ();
2811 direction_less_event:
2813 | EVENT_IDENTIFIER {
2817 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2818 a->set_property ("tremolo-type", $1);
2819 $$ = a->unprotect ();
2821 | event_function_event
2824 direction_reqd_event:
2828 | script_abbreviation {
2829 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2830 if (scm_is_string (s)) {
2831 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2832 a->set_property ("articulation-type", s);
2833 $$ = a->unprotect ();
2835 Music *original = Music::unsmob (s);
2836 if (original && original->is_mus_type ("post-event")) {
2837 Music *a = original->clone ();
2838 a->set_spot (parser->lexer_->override_input (@$));
2839 $$ = a->unprotect ();
2841 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2842 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2849 /**/ { $$ = SCM_EOL; }
2850 | '=' quotes { $$ = $2; }
2864 $$ = scm_from_int (1);
2867 $$ = scm_oneplus ($1);
2873 $$ = scm_from_int (-1);
2876 $$ = scm_oneminus ($1);
2881 NOTENAME_PITCH quotes {
2882 if (!scm_is_eq (SCM_INUM0, $2))
2884 Pitch p = *Pitch::unsmob ($1);
2885 p = p.transposed (Pitch (scm_to_int ($2), 0));
2886 $$ = p.smobbed_copy ();
2896 TONICNAME_PITCH quotes {
2897 if (!scm_is_eq (SCM_INUM0, $2))
2899 Pitch p = *Pitch::unsmob ($1);
2900 p = p.transposed (Pitch (scm_to_int ($2), 0));
2901 $$ = p.smobbed_copy ();
2908 | PITCH_IDENTIFIER quotes {
2909 if (!scm_is_eq (SCM_INUM0, $2))
2911 Pitch p = *Pitch::unsmob ($1);
2912 p = p.transposed (Pitch (scm_to_int ($2), 0));
2913 $$ = p.smobbed_copy ();
2918 pitch_or_tonic_pitch:
2925 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2926 t->set_property ("text", $1);
2927 $$ = t->unprotect ();
2930 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2931 t->set_property ("text",
2932 make_simple_markup ($1));
2933 $$ = t->unprotect ();
2937 Music *m = Music::unsmob ($1);
2938 if (m && m->is_mus_type ("post-event"))
2940 else if (Text_interface::is_markup ($1)) {
2941 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2942 t->set_property ("text", $1);
2943 $$ = t->unprotect ();
2945 parser->parser_error (@1, _ ("not an articulation"));
2951 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2952 t->set_property ("digit", $1);
2953 $$ = t->unprotect ();
2957 script_abbreviation:
2959 $$ = scm_from_locale_string ("Hat");
2962 $$ = scm_from_locale_string ("Plus");
2965 $$ = scm_from_locale_string ("Dash");
2968 $$ = scm_from_locale_string ("Bang");
2971 $$ = scm_from_locale_string ("Larger");
2974 $$ = scm_from_locale_string ("Dot");
2977 $$ = scm_from_locale_string ("Underscore");
2982 '_' { $$ = scm_from_int (DOWN); }
2983 | '^' { $$ = scm_from_int (UP); }
2984 | '-' { $$ = SCM_UNDEFINED; }
2988 multiplied_duration {
2993 maybe_notemode_duration:
2997 | multiplied_duration {
2999 parser->default_duration_ = *Duration::unsmob ($$);
3004 optional_notemode_duration:
3005 maybe_notemode_duration
3007 if (SCM_UNBNDP ($$))
3008 $$ = parser->default_duration_.smobbed_copy ();
3014 $$ = make_duration ($1, scm_to_int ($2));
3015 if (SCM_UNBNDP ($$))
3017 parser->parser_error (@1, _ ("not a duration"));
3018 $$ = Duration ().smobbed_copy ();
3021 | DURATION_IDENTIFIER dots {
3022 Duration *d = Duration::unsmob ($1);
3023 Duration k (d->duration_log (),
3024 d->dot_count () + scm_to_int ($2));
3025 k = k.compressed (d->factor ());
3026 scm_remember_upto_here_1 ($1);
3027 $$ = k.smobbed_copy ();
3031 multiplied_duration:
3035 | multiplied_duration '*' UNSIGNED {
3036 $$ = Duration::unsmob ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
3038 | multiplied_duration '*' FRACTION {
3039 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
3041 $$ = Duration::unsmob ($$)->compressed (m).smobbed_copy ();
3050 $$ = scm_oneplus ($1);
3056 $$ = scm_from_int (parser->default_tremolo_type_);
3059 if (SCM_UNBNDP (make_duration ($2))) {
3060 parser->parser_error (@2, _ ("not a duration"));
3061 $$ = scm_from_int (parser->default_tremolo_type_);
3064 parser->default_tremolo_type_ = scm_to_int ($2);
3070 UNSIGNED { $$ = $1; }
3071 | STRING { $$ = $1; }
3072 | full_markup { $$ = $1; }
3075 // as an integer, it needs to be non-negative, and otherwise
3076 // it needs to be suitable as a markup.
3077 if (scm_is_integer ($1)
3078 ? scm_is_true (scm_negative_p ($1))
3079 : !Text_interface::is_markup ($1))
3081 parser->parser_error (@1, _ ("bass number expected"));
3087 figured_bass_alteration:
3088 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3089 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3090 | '!' { $$ = scm_from_int (0); }
3095 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3096 $$ = bfr->unprotect ();
3099 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3100 $$ = bfr->self_scm ();
3102 if (scm_is_number ($1))
3103 bfr->set_property ("figure", $1);
3104 else if (Text_interface::is_markup ($1))
3105 bfr->set_property ("text", $1);
3111 Music::unsmob ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3113 | bass_figure figured_bass_alteration {
3114 Music *m = Music::unsmob ($1);
3115 if (scm_to_double ($2)) {
3116 SCM salter = m->get_property ("alteration");
3117 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3118 m->set_property ("alteration",
3119 scm_sum (alter, $2));
3121 m->set_property ("alteration", scm_from_int (0));
3124 | bass_figure figured_bass_modification {
3125 Music *m = Music::unsmob ($1);
3126 m->set_property ($2, SCM_BOOL_T);
3131 figured_bass_modification:
3133 $$ = ly_symbol2scm ("augmented");
3136 $$ = ly_symbol2scm ("no-continuation");
3139 $$ = ly_symbol2scm ("diminished");
3142 $$ = ly_symbol2scm ("augmented-slash");
3152 Music::unsmob ($$)->set_property ("bracket-start", SCM_BOOL_T);
3160 | figure_list br_bass_figure {
3161 $$ = scm_cons ($2, $1);
3166 /**/ { $$ = SCM_BOOL_F; }
3167 | REST { $$ = SCM_BOOL_T; }
3171 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3172 if (!parser->lexer_->is_note_state ())
3173 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3174 if (!SCM_UNBNDP ($2)
3176 || scm_is_number ($4)
3179 || scm_is_pair ($7))
3182 if (scm_is_true ($6))
3183 n = MY_MAKE_MUSIC ("RestEvent", @$);
3185 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3187 n->set_property ("pitch", $1);
3188 if (SCM_UNBNDP ($5))
3189 n->set_property ("duration",
3190 parser->default_duration_.smobbed_copy ());
3192 n->set_property ("duration", $5);
3194 if (scm_is_number ($4))
3196 int q = scm_to_int ($4);
3197 n->set_property ("absolute-octave", scm_from_int (q-1));
3200 if (to_boolean ($3))
3201 n->set_property ("cautionary", SCM_BOOL_T);
3202 if (to_boolean ($2) || to_boolean ($3))
3203 n->set_property ("force-accidental", SCM_BOOL_T);
3204 if (scm_is_pair ($7))
3205 n->set_property ("articulations",
3206 scm_reverse_x ($7, SCM_EOL));
3207 $$ = n->unprotect ();
3210 | new_chord post_events {
3211 if (!parser->lexer_->is_chord_state ())
3212 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3213 if (scm_is_pair ($2)) {
3214 if (Pitch::unsmob ($1))
3215 $1 = make_chord_elements (@1,
3217 parser->default_duration_.smobbed_copy (),
3220 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3222 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
3223 } else if (!Pitch::unsmob ($1))
3224 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
3225 // A mere pitch drops through.
3230 DRUM_PITCH optional_notemode_duration {
3231 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3232 n->set_property ("duration", $2);
3233 n->set_property ("drum-type", $1);
3235 $$ = n->unprotect ();
3237 | RESTNAME optional_notemode_duration {
3239 if (ly_scm2string ($1) == "s") {
3241 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3244 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3247 ev->set_property ("duration", $2);
3248 $$ = ev->unprotect ();
3254 if (!parser->lexer_->is_lyric_state ())
3255 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3259 if (!parser->lexer_->is_lyric_state ())
3260 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3266 lyric_element_music:
3267 lyric_element optional_notemode_duration post_events {
3268 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3269 if (scm_is_pair ($3))
3270 Music::unsmob ($$)->set_property
3271 ("articulations", scm_reverse_x ($3, SCM_EOL));
3275 // Can return a single pitch rather than a list.
3277 steno_tonic_pitch maybe_notemode_duration {
3278 if (SCM_UNBNDP ($2))
3281 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3283 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3284 SCM its = scm_reverse_x ($4, SCM_EOL);
3285 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3293 | chord_items chord_item {
3294 $$ = scm_cons ($2, $$);
3300 $$ = ly_symbol2scm ("chord-colon");
3303 $$ = ly_symbol2scm ("chord-caret");
3305 | CHORD_SLASH steno_tonic_pitch {
3306 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3308 | CHORD_BASS steno_tonic_pitch {
3309 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3318 $$ = scm_reverse_x ($1, SCM_EOL);
3326 step_number { $$ = scm_cons ($1, SCM_EOL); }
3327 | step_numbers '.' step_number {
3328 $$ = scm_cons ($3, $$);
3334 $$ = make_chord_step ($1, 0);
3337 $$ = make_chord_step ($1, SHARP_ALTERATION);
3339 | UNSIGNED CHORD_MINUS {
3340 $$ = make_chord_step ($1, FLAT_ALTERATION);
3348 | unsigned_number '-' unsigned_number {
3349 $$ = scm_cons ($1, $3);
3356 TODO: should deprecate in favor of Scheme?
3360 number_expression '+' number_term {
3361 $$ = scm_sum ($1, $3);
3363 | number_expression '-' number_term {
3364 $$ = scm_difference ($1, $3);
3373 | number_factor '*' number_factor {
3374 $$ = scm_product ($1, $3);
3376 | number_factor '/' number_factor {
3377 $$ = scm_divide ($1, $3);
3382 '-' number_factor { /* %prec UNARY_MINUS */
3383 $$ = scm_difference ($2, SCM_UNDEFINED);
3391 | REAL NUMBER_IDENTIFIER
3393 $$ = scm_product ($1, $2);
3400 | UNSIGNED NUMBER_IDENTIFIER {
3401 $$ = scm_product ($1, $2);
3409 if (!scm_is_integer ($1)
3410 || scm_is_true (scm_negative_p ($1)))
3412 parser->parser_error (@1, _("not an unsigned integer"));
3418 if (!scm_is_integer ($1)
3419 || scm_is_true (scm_negative_p ($1)))
3421 parser->parser_error (@1, _("not an unsigned integer"));
3428 { $$ = SCM_UNDEFINED; }
3431 if (SCM_UNBNDP ($1))
3439 // This precedence rule is rather weird. It triggers when '!' is
3440 // encountered after a pitch, and is used for deciding whether to save
3441 // this instead for a figure modification. This should not actually
3442 // occur in practice as pitches and figures are generated in different
3443 // modes. Using a greedy (%right) precedence makes sure that we don't
3444 // get stuck in a wrong interpretation.
3445 { $$ = SCM_UNDEFINED; } %prec ':'
3448 if (SCM_UNBNDP ($1))
3457 { parser->lexer_->push_markup_state (); }
3460 parser->lexer_->pop_state ();
3466 { parser->lexer_->push_markup_state (); }
3469 parser->lexer_->pop_state ();
3475 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3477 | markup_head_1_list simple_markup
3479 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3480 @2, $1, scm_list_1 ($2)));
3490 if (Text_interface::is_markup ($1))
3491 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3492 else if (Text_interface::is_markup_list ($1))
3493 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3495 parser->parser_error (@1, _ ("not a markup"));
3496 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3503 markup_composed_list {
3506 | markup_uncomposed_list
3509 markup_uncomposed_list:
3510 markup_braced_list {
3513 | markup_command_list {
3514 $$ = scm_list_1 ($1);
3516 | markup_scm MARKUPLIST_IDENTIFIER
3521 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3522 parser->lexer_->push_note_state (nn);
3523 } '{' score_body '}' {
3524 Score *sc = Score::unsmob ($4);
3525 sc->origin ()->set_spot (@$);
3526 if (sc->defs_.empty ()) {
3527 Output_def *od = get_layout (parser);
3528 sc->add_output_def (od);
3531 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3532 parser->lexer_->pop_state ();
3536 markup_composed_list:
3537 markup_head_1_list markup_uncomposed_list {
3538 $$ = MAKE_SYNTAX ("composed-markup-list",
3544 '{' markup_braced_list_body '}' {
3545 $$ = scm_reverse_x ($2, SCM_EOL);
3549 markup_braced_list_body:
3550 /* empty */ { $$ = SCM_EOL; }
3551 | markup_braced_list_body markup {
3552 $$ = scm_cons ($2, $1);
3554 | markup_braced_list_body markup_list {
3555 $$ = scm_reverse_x ($2, $1);
3559 markup_command_list:
3560 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3561 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3565 markup_command_basic_arguments:
3566 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3567 $$ = scm_cons ($3, $2);
3569 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3570 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3572 | EXPECT_NO_MORE_ARGS {
3577 markup_command_list_arguments:
3578 markup_command_basic_arguments { $$ = $1; }
3579 | EXPECT_MARKUP markup_command_list_arguments markup {
3580 $$ = scm_cons ($3, $2);
3585 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3586 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3591 markup_head_1_item {
3592 $$ = scm_list_1 ($1);
3594 | markup_head_1_list markup_head_1_item {
3595 $$ = scm_cons ($2, $1);
3601 $$ = make_simple_markup ($1);
3604 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3605 parser->lexer_->push_note_state (nn);
3606 } '{' score_body '}' {
3607 Score *sc = Score::unsmob ($4);
3608 sc->origin ()->set_spot (@$);
3609 if (sc->defs_.empty ()) {
3610 Output_def *od = get_layout (parser);
3611 sc->add_output_def (od);
3614 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3615 parser->lexer_->pop_state ();
3617 | MARKUP_FUNCTION markup_command_basic_arguments {
3618 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3620 | markup_scm MARKUP_IDENTIFIER
3627 markup_head_1_list simple_markup
3629 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3630 @2, $1, scm_list_1 ($2)));
3640 Lily_parser::set_yydebug (bool x)
3646 Lily_parser::do_yyparse ()
3648 SCM retval = SCM_UNDEFINED;
3649 yyparse (this, &retval);
3659 It is a little strange to have this function in this file, but
3660 otherwise, we have to import music classes into the lexer.
3664 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3666 if (Book::unsmob (sid)) {
3667 Book *book = Book::unsmob (sid)->clone ();
3668 *destination = book->self_scm ();
3671 return BOOK_IDENTIFIER;
3672 } else if (scm_is_number (sid)) {
3674 return NUMBER_IDENTIFIER;
3675 } else if (Context_def::unsmob (sid))
3677 *destination = Context_def::unsmob (sid)->clone ()->unprotect ();
3678 return SCM_IDENTIFIER;
3679 } else if (Context_mod::unsmob (sid)) {
3680 *destination = Context_mod::unsmob (sid)->smobbed_copy ();
3681 return CONTEXT_MOD_IDENTIFIER;
3682 } else if (Music *mus = Music::unsmob (sid)) {
3683 mus = mus->clone ();
3684 *destination = mus->self_scm ();
3685 bool is_event = mus->is_mus_type ("post-event");
3687 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3688 } else if (Pitch::unsmob (sid)) {
3689 *destination = Pitch::unsmob (sid)->smobbed_copy ();
3690 return PITCH_IDENTIFIER;
3691 } else if (Duration::unsmob (sid)) {
3692 *destination = Duration::unsmob (sid)->smobbed_copy ();
3693 return DURATION_IDENTIFIER;
3694 } else if (Output_def::unsmob (sid)) {
3695 *destination = Output_def::unsmob (sid)->clone ()->unprotect ();
3696 return SCM_IDENTIFIER;
3697 } else if (Score::unsmob (sid)) {
3698 *destination = Score::unsmob (sid)->clone ()->unprotect ();
3699 return SCM_IDENTIFIER;
3706 get_next_unique_context_id ()
3708 return scm_from_locale_string ("$uniqueContextId");
3713 get_next_unique_lyrics_context_id ()
3715 static int new_context_count;
3717 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3718 return scm_from_locale_string (s);
3721 // check_scheme_arg checks one argument with a given predicate for use
3722 // in an argument list and throws a syntax error if it is unusable.
3723 // The argument is prepended to the argument list in any case. After
3724 // throwing a syntax error, the argument list is terminated with #f as
3725 // its last cdr in order to mark it as uncallable while not losing
3726 // track of its total length.
3728 // There are a few special considerations: if optional argument disp
3729 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3730 // instead of arg in a prospective error message. This is useful if
3731 // arg is not the actual argument but rather a transformation of it.
3733 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3734 // and an error message using disp is produced unconditionally.
3736 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3737 SCM arg, SCM args, SCM pred, SCM disp)
3739 if (SCM_UNBNDP (arg))
3740 args = scm_cons (disp, args);
3742 args = scm_cons (arg, args);
3743 if (scm_is_true (scm_call_1 (pred, arg)))
3746 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3747 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3748 SCM_UNBNDP (disp) ? arg : disp);
3749 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3753 SCM loc_on_music (Input loc, SCM arg)
3755 if (Music *m = Music::unsmob (arg))
3759 return m->unprotect ();
3765 try_string_variants (SCM pred, SCM str)
3767 // a matching predicate is always ok
3768 if (scm_is_true (scm_call_1 (pred, str)))
3770 // a symbol may be interpreted as a list of symbols if it helps
3771 if (scm_is_symbol (str)) {
3772 str = scm_list_1 (str);
3773 if (scm_is_true (scm_call_1 (pred, str)))
3775 return SCM_UNDEFINED;
3778 // If this cannot be a string representation of a symbol list,
3781 if (!is_regular_identifier (str, true))
3782 return SCM_UNDEFINED;
3784 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3785 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3786 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3788 // Let's attempt the symbol list interpretation first.
3790 if (scm_is_true (scm_call_1 (pred, str)))
3793 // If there is just one symbol in the list, we might interpret
3794 // it as a single symbol
3796 if (scm_is_null (scm_cdr (str)))
3798 str = scm_car (str);
3799 if (scm_is_true (scm_call_1 (pred, str)))
3803 return SCM_UNDEFINED;
3807 is_regular_identifier (SCM id, bool multiple)
3809 if (!scm_is_string (id))
3812 string str = ly_scm2string (id);
3814 bool middle = false;
3816 for (string::iterator it=str.begin(); it != str.end (); it++)
3819 if ((c >= 'a' && c <= 'z')
3820 || (c >= 'A' && c <= 'Z')
3823 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3832 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3834 if (Music::unsmob (simple))
3836 if (parser->lexer_->is_note_state ()) {
3837 if (scm_is_symbol (simple)) {
3838 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3839 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3840 n->set_property ("drum-type", simple);
3841 return n->unprotect ();
3843 if (Pitch::unsmob (simple)) {
3844 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3845 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3846 n->set_property ("pitch", simple);
3847 return n->unprotect ();
3850 } else if (parser->lexer_->is_lyric_state ()) {
3851 if (Text_interface::is_markup (simple))
3852 return MAKE_SYNTAX ("lyric-event", loc, simple,
3853 parser->default_duration_.smobbed_copy ());
3854 } else if (parser->lexer_->is_chord_state ()) {
3855 if (Pitch::unsmob (simple))
3859 make_chord_elements (loc, simple,
3860 parser->default_duration_.smobbed_copy (),
3867 make_music_with_input (SCM name, Input where)
3869 Music *m = make_music_by_name (name);
3870 m->set_spot (where);
3875 make_simple_markup (SCM a)
3881 make_duration (SCM d, int dots)
3883 int t = scm_to_int (d);
3884 if (t > 0 && (t & (t-1)) == 0)
3885 return Duration (intlog2 (t), dots).smobbed_copy ();
3887 return SCM_UNDEFINED;
3891 make_chord_step (SCM step_scm, Rational alter)
3893 int step = scm_to_int (step_scm);
3896 alter += FLAT_ALTERATION;
3900 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3901 return m.smobbed_copy ();
3906 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3908 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3909 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3910 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3912 Music::unsmob (scm_car (s))->set_spot (loc);
3918 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3920 Lily_lexer *lex = parser->lexer_;
3924 int tok = lex->pop_extra_token ();
3927 lex->prepare_for_next_token ();
3928 return lex->yylex ();