1 /* -*- mode: c++; c-file-style: "linux"; indent-tabs-mode: t -*- */
3 This file is part of LilyPond, the GNU music typesetter.
5 Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 Jan Nieuwenhuizen <janneke@gnu.org>
8 LilyPond is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 /* Mode and indentation are at best a rough approximation based on TAB
23 * formatting (reasonable for compatibility with unspecific editor
24 * modes as Bison modes are hard to find) and need manual correction
25 * frequently. Without a reasonably dependable way of formatting a
26 * Bison file sensibly, there is little point in trying to fix the
27 * inconsistent state of indentation.
32 #define yyerror Lily_parser::parser_error
34 /* We use custom location type: Input objects */
37 #define YYLLOC_DEFAULT(Current,Rhs,N) \
38 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
40 #define YYPRINT(file, type, value) \
42 if (scm_is_eq (value, SCM_UNSPECIFIED)) \
44 char *p = scm_to_locale_string \
45 (scm_simple_format (SCM_BOOL_F, \
46 scm_from_locale_string ("~S"), \
47 scm_list_1 (value))); \
54 %parse-param {Lily_parser *parser}
55 %parse-param {SCM *retval}
56 %lex-param {Lily_parser *parser}
60 /* We use SCMs to do strings, because it saves us the trouble of
61 deleting them. Let's hope that a stack overflow doesn't trigger a move
62 of the parse stack onto the heap. */
68 /* The above precedences tackle the shift/reduce problem
71 \repeat .. \alternative
73 \repeat { \repeat .. \alternative }
77 \repeat { \repeat } \alternative
83 %right ':' UNSIGNED REAL E_UNSIGNED EVENT_IDENTIFIER EVENT_FUNCTION '^' '_'
84 HYPHEN EXTENDER DURATION_IDENTIFIER '!'
86 /* The above are needed for collecting tremoli and other items (that
87 could otherwise be interpreted as belonging to the next function
88 argument) greedily, and together with the next rule will serve to
89 join numbers and units greedily instead of allowing them into
90 separate function arguments
93 %nonassoc NUMBER_IDENTIFIER
105 %{ // -*-Fundamental-*-
110 * The rules for who is protecting what are very shady. Uniformise
113 * There are too many lexical modes?
124 #include "context-def.hh"
125 #include "context-mod.hh"
126 #include "dimensions.hh"
127 #include "file-path.hh"
129 #include "international.hh"
130 #include "lily-guile.hh"
131 #include "lily-lexer.hh"
132 #include "lily-parser.hh"
136 #include "output-def.hh"
137 #include "paper-book.hh"
138 #include "scm-hash.hh"
140 #include "text-interface.hh"
144 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
146 parser->parser_error (*i, s);
149 // The following are somewhat precarious constructs as they may change
150 // the value of the lookahead token. That implies that the lookahead
151 // token must not yet have made an impact on the state stack other
152 // than causing the reduction of the current rule, or switching the
153 // lookahead token while Bison is mulling it over will cause trouble.
155 #define MYBACKUP(Token, Value, Location) \
157 if (yychar != YYEMPTY) \
158 parser->lexer_->push_extra_token \
159 (yylloc, yychar, yylval); \
161 parser->lexer_->push_extra_token \
162 (Location, Token, Value); \
163 parser->lexer_->push_extra_token (Location, BACKUP); \
168 #define MYREPARSE(Location, Pred, Token, Value) \
170 if (yychar != YYEMPTY) \
171 parser->lexer_->push_extra_token \
172 (yylloc, yychar, yylval); \
173 parser->lexer_->push_extra_token \
174 (Location, Token, Value); \
175 parser->lexer_->push_extra_token \
176 (Location, REPARSE, Pred); \
185 #define MY_MAKE_MUSIC(x, spot) \
186 make_music_with_input (ly_symbol2scm (x), \
187 parser->lexer_->override_input (spot))
190 - Don't use lily module, create a new module instead.
191 - delay application of the function
193 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
194 scm_apply_0 (proc, args)
195 /* Syntactic Sugar. */
196 #define MAKE_SYNTAX(name, location, ...) \
197 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (parser->lexer_->override_input (location)), ##__VA_ARGS__, SCM_UNDEFINED))
198 #define START_MAKE_SYNTAX(name, ...) \
199 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
200 #define FINISH_MAKE_SYNTAX(start, location, ...) \
201 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (parser->lexer_->override_input (location)), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
203 SCM get_next_unique_context_id ();
204 SCM get_next_unique_lyrics_context_id ();
211 #define _(x) gettext (x)
215 static Music *make_music_with_input (SCM name, Input where);
216 SCM check_scheme_arg (Lily_parser *parser, Input loc,
217 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
218 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
219 SCM loc_on_music (Input loc, SCM arg);
220 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
221 SCM make_chord_step (SCM step, Rational alter);
222 SCM make_simple_markup (SCM a);
223 SCM make_duration (SCM t, int dots = 0);
224 bool is_regular_identifier (SCM id, bool multiple=false);
225 SCM try_string_variants (SCM pred, SCM str);
226 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
230 /* The third option is an alias that will be used to display the
231 syntax error. Bison CVS now correctly handles backslash escapes.
233 FIXME: Bison needs to translate some of these, eg, STRING.
237 /* Keyword tokens with plain escaped name. */
238 %token END_OF_FILE 0 "end of input"
239 %token ACCEPTS "\\accepts"
240 %token ADDLYRICS "\\addlyrics"
241 %token ALIAS "\\alias"
242 %token ALTERNATIVE "\\alternative"
244 %token BOOKPART "\\bookpart"
245 %token CHANGE "\\change"
246 %token CHORDMODE "\\chordmode"
247 %token CHORDS "\\chords"
248 %token CONSISTS "\\consists"
249 %token CONTEXT "\\context"
250 %token DEFAULT "\\default"
251 %token DEFAULTCHILD "\\defaultchild"
252 %token DENIES "\\denies"
253 %token DESCRIPTION "\\description"
254 %token DRUMMODE "\\drummode"
255 %token DRUMS "\\drums"
256 %token FIGUREMODE "\\figuremode"
257 %token FIGURES "\\figures"
258 %token HEADER "\\header"
259 %token INVALID "\\version-error"
260 %token LAYOUT "\\layout"
261 %token LYRICMODE "\\lyricmode"
262 %token LYRICS "\\lyrics"
263 %token LYRICSTO "\\lyricsto"
264 %token MARKUP "\\markup"
265 %token MARKUPLIST "\\markuplist"
268 %token NOTEMODE "\\notemode"
269 %token OVERRIDE "\\override"
270 %token PAPER "\\paper"
271 %token REMOVE "\\remove"
272 %token REPEAT "\\repeat"
274 %token REVERT "\\revert"
275 %token SCORE "\\score"
276 %token SCORELINES "\\score-lines"
277 %token SEQUENTIAL "\\sequential"
279 %token SIMULTANEOUS "\\simultaneous"
280 %token TEMPO "\\tempo"
282 %token UNSET "\\unset"
285 /* Keyword token exceptions. */
286 %token NEWCONTEXT "\\new"
289 /* Other string tokens. */
291 %token CHORD_BASS "/+"
292 %token CHORD_CARET "^"
293 %token CHORD_COLON ":"
294 %token CHORD_MINUS "-"
295 %token CHORD_SLASH "/"
296 %token ANGLE_OPEN "<"
297 %token ANGLE_CLOSE ">"
298 %token DOUBLE_ANGLE_OPEN "<<"
299 %token DOUBLE_ANGLE_CLOSE ">>"
300 %token E_BACKSLASH "\\"
301 %token E_EXCLAMATION "\\!"
306 If we give names, Bison complains.
308 %token FIGURE_CLOSE /* "\\>" */
309 %token FIGURE_OPEN /* "\\<" */
310 %token FIGURE_SPACE "_"
313 %token MULTI_MEASURE_REST
319 /* Artificial tokens, for more generic function syntax */
320 %token EXPECT_MARKUP "markup?"
321 %token EXPECT_SCM "scheme?"
322 %token BACKUP "(backed-up?)"
323 %token REPARSE "(reparsed?)"
324 %token EXPECT_MARKUP_LIST "markup-list?"
325 %token EXPECT_OPTIONAL "optional?"
326 /* After the last argument. */
327 %token EXPECT_NO_MORE_ARGS;
329 /* An artificial token for parsing embedded Lilypond */
330 %token EMBEDDED_LILY "#{"
332 %token BOOK_IDENTIFIER
333 %token CHORD_MODIFIER
334 %token CHORD_REPETITION
335 %token CONTEXT_DEF_IDENTIFIER
336 %token CONTEXT_MOD_IDENTIFIER
338 %token PITCH_IDENTIFIER
340 %token DURATION_IDENTIFIER
341 %token EVENT_IDENTIFIER
342 %token EVENT_FUNCTION
345 %token MARKUP_FUNCTION
346 %token MARKUP_LIST_FUNCTION
347 %token MARKUP_IDENTIFIER
348 %token MARKUPLIST_IDENTIFIER
349 %token MUSIC_FUNCTION
350 %token MUSIC_IDENTIFIER
351 %token NOTENAME_PITCH
352 %token NUMBER_IDENTIFIER
353 %token OUTPUT_DEF_IDENTIFIER
358 %token SCM_IDENTIFIER
362 %token TONICNAME_PITCH
366 /* We don't assign precedence to / and *, because we might need varied
367 prec levels in different prods */
376 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
377 parser->lexer_->push_note_state (nn);
378 } embedded_lilypond {
379 parser->lexer_->pop_state ();
384 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
385 | lilypond toplevel_expression {
387 | lilypond assignment {
390 parser->error_level_ = 1;
393 parser->error_level_ = 1;
400 parser->lexer_->add_scope (get_header (parser));
402 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
405 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
406 scm_call_2 (proc, parser->self_scm (), $1);
409 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
410 scm_call_2 (proc, parser->self_scm (), $1);
413 SCM proc = parser->lexer_->lookup_identifier
414 (unsmob_book($1)->paper_
415 ? "toplevel-book-handler"
416 : "toplevel-bookpart-handler");
417 scm_call_2 (proc, parser->self_scm (), $1);
420 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
421 scm_call_2 (proc, parser->self_scm (), $1);
424 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
425 scm_call_2 (proc, parser->self_scm (), $1);
428 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
429 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
432 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
433 scm_call_2 (proc, parser->self_scm (), $1);
436 // Evaluate and ignore #xxx, as opposed to \xxx
437 parser->lexer_->eval_scm_token ($1);
439 | embedded_scm_active
441 SCM out = SCM_UNDEFINED;
442 if (Text_interface::is_markup ($1))
443 out = scm_list_1 ($1);
444 else if (Text_interface::is_markup_list ($1))
446 if (scm_is_pair (out))
448 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
449 scm_call_2 (proc, parser->self_scm (), out);
450 } else if (unsmob_score ($1))
452 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
453 scm_call_2 (proc, parser->self_scm (), $1);
454 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
455 parser->parser_error (@1, _("bad expression type"));
459 Output_def * od = unsmob_output_def ($1);
461 if (od->c_variable ("is-paper") == SCM_BOOL_T)
462 id = ly_symbol2scm ("$defaultpaper");
463 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
464 id = ly_symbol2scm ("$defaultmidi");
465 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
466 id = ly_symbol2scm ("$defaultlayout");
468 parser->lexer_->set_identifier (id, $1);
475 $$ = parser->lexer_->eval_scm_token ($1);
485 embedded_scm_bare_arg:
489 $$ = parser->lexer_->eval_scm_token ($1);
493 | context_modification
495 | context_def_spec_block
501 /* The generic version may end in music, or not */
508 /* embedded_scm_arg is _not_ casting pitches to music by default, this
509 * has to be done by the function itself. Note that this may cause
510 * the results of scm_function_call or embedded_scm_bare_arg to be
511 * turned into music from pitches as well. Note that this creates a
512 * distinctly awkward situation for calculated drum pitches. Those
513 * are at the current point of time rejected as music constituents as
514 * they can't be distinguished from "proper" symbols.
518 embedded_scm_bare_arg
524 SCM_FUNCTION function_arglist {
525 $$ = MAKE_SYNTAX ("music-function", @$,
530 embedded_lilypond_number:
531 '-' embedded_lilypond_number
533 $$ = scm_difference ($2, SCM_UNDEFINED);
536 | UNSIGNED NUMBER_IDENTIFIER
538 $$ = scm_product ($1, $2);
545 // FIXME: @$ does not contain a useful source location
546 // for empty rules, and the only token in the whole
547 // production, EMBEDDED_LILY, is synthetic and also
548 // contains no source location.
549 $$ = MAKE_SYNTAX ("void-music", @$);
551 | identifier_init_nonumber
552 | embedded_lilypond_number
553 | post_event post_events
555 $$ = scm_reverse_x ($2, SCM_EOL);
556 if (Music *m = unsmob_music ($1))
558 if (m->is_mus_type ("post-event-wrapper"))
560 (scm_list_2 (m->get_property ("elements"),
563 $$ = scm_cons ($1, $$);
566 && scm_is_null (scm_cdr ($$)))
570 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
571 m->set_property ("elements", $$);
572 $$ = m->unprotect ();
575 | multiplied_duration
576 | music_embedded music_embedded music_list {
577 $3 = scm_reverse_x ($3, SCM_EOL);
578 if (unsmob_music ($2))
579 $3 = scm_cons ($2, $3);
580 if (unsmob_music ($1))
581 $3 = scm_cons ($1, $3);
582 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
585 parser->error_level_ = 1;
586 $$ = SCM_UNSPECIFIED;
588 | INVALID embedded_lilypond {
589 parser->error_level_ = 1;
595 lilypond_header_body:
596 /* empty */ { $$ = SCM_UNSPECIFIED; }
597 | lilypond_header_body assignment {
600 | lilypond_header_body embedded_scm {
606 HEADER '{' lilypond_header_body '}' {
607 $$ = parser->lexer_->remove_scope ();
619 assignment_id '=' identifier_init {
620 parser->lexer_->set_identifier ($1, $3);
621 $$ = SCM_UNSPECIFIED;
623 | assignment_id property_path '=' identifier_init {
624 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
625 parser->lexer_->set_identifier (path, $4);
626 $$ = SCM_UNSPECIFIED;
632 identifier_init_nonumber
634 | post_event_nofinger post_events
636 $$ = scm_reverse_x ($2, SCM_EOL);
637 if (Music *m = unsmob_music ($1))
639 if (m->is_mus_type ("post-event-wrapper"))
641 (scm_list_2 (m->get_property ("elements"),
644 $$ = scm_cons ($1, $$);
647 && scm_is_null (scm_cdr ($$)))
651 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
652 m->set_property ("elements", $$);
653 $$ = m->unprotect ();
658 identifier_init_nonumber:
663 | context_def_spec_block
669 | context_modification
672 context_def_spec_block:
673 CONTEXT '{' context_def_spec_body '}'
676 unsmob_context_def ($$)->origin ()->set_spot (@$);
684 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
685 parser->lexer_->push_note_state (nn);
689 parser->lexer_->pop_state ();
694 context_mod_embedded:
697 if (unsmob_music ($1)) {
698 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
699 $1 = scm_call_2 (proc, parser->self_scm (), $1);
701 if (unsmob_context_mod ($1))
704 parser->parser_error (@1, _ ("not a context mod"));
705 $$ = Context_mod ().smobbed_copy ();
711 context_def_spec_body:
713 $$ = Context_def::make_scm ();
715 | CONTEXT_DEF_IDENTIFIER {
718 | context_def_spec_body context_mod {
719 if (!SCM_UNBNDP ($2))
720 unsmob_context_def ($$)->add_context_mod ($2);
722 | context_def_spec_body context_modification {
723 Context_def *td = unsmob_context_def ($$);
724 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
725 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
726 td->add_context_mod (scm_car (m));
729 | context_def_spec_body context_mod_embedded {
730 Context_def *td = unsmob_context_def ($$);
731 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
732 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
733 td->add_context_mod (scm_car (m));
741 BOOK '{' book_body '}' {
743 unsmob_book ($$)->origin ()->set_spot (@$);
745 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
750 * Use 'handlers' like for toplevel-* stuff?
751 * grok \layout and \midi? */
754 Book *book = new Book;
755 init_papers (parser);
756 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
757 book->paper_->unprotect ();
758 push_paper (parser, book->paper_);
759 book->header_ = get_header (parser);
760 $$ = book->unprotect ();
761 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
764 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
766 | book_body paper_block {
767 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
768 set_paper (parser, unsmob_output_def ($2));
770 | book_body bookpart_block {
771 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
772 scm_call_2 (proc, $1, $2);
774 | book_body score_block {
775 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
776 scm_call_2 (proc, $1, $2);
778 | book_body composite_music {
779 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
780 scm_call_3 (proc, parser->self_scm (), $1, $2);
782 | book_body full_markup {
783 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
784 scm_call_2 (proc, $1, scm_list_1 ($2));
786 | book_body full_markup_list {
787 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
788 scm_call_2 (proc, $1, $2);
790 | book_body SCM_TOKEN {
791 // Evaluate and ignore #xxx, as opposed to \xxx
792 parser->lexer_->eval_scm_token ($2);
794 | book_body embedded_scm_active
796 SCM out = SCM_UNDEFINED;
797 if (Text_interface::is_markup ($2))
798 out = scm_list_1 ($2);
799 else if (Text_interface::is_markup_list ($2))
801 if (scm_is_pair (out))
803 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
804 scm_call_2 (proc, $1, out);
805 } else if (unsmob_score ($2))
807 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
808 scm_call_2 (proc, $1, $2);
809 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
810 parser->parser_error (@2, _("bad expression type"));
814 parser->lexer_->add_scope (unsmob_book ($1)->header_);
817 Book *book = unsmob_book ($1);
819 book->scores_ = SCM_EOL;
820 book->bookparts_ = SCM_EOL;
825 BOOKPART '{' bookpart_body '}' {
827 unsmob_book ($$)->origin ()->set_spot (@$);
828 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
834 Book *book = new Book;
835 $$ = book->unprotect ();
836 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
839 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
841 | bookpart_body paper_block {
842 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
844 | bookpart_body score_block {
845 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
846 scm_call_2 (proc, $1, $2);
848 | bookpart_body composite_music {
849 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
850 scm_call_3 (proc, parser->self_scm (), $1, $2);
852 | bookpart_body full_markup {
853 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
854 scm_call_2 (proc, $1, scm_list_1 ($2));
856 | bookpart_body full_markup_list {
857 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
858 scm_call_2 (proc, $1, $2);
860 | bookpart_body SCM_TOKEN {
861 // Evaluate and ignore #xxx, as opposed to \xxx
862 parser->lexer_->eval_scm_token ($2);
864 | bookpart_body embedded_scm_active
866 SCM out = SCM_UNDEFINED;
867 if (Text_interface::is_markup ($2))
868 out = scm_list_1 ($2);
869 else if (Text_interface::is_markup_list ($2))
871 if (scm_is_pair (out))
873 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
874 scm_call_2 (proc, $1, out);
875 } else if (unsmob_score ($2))
877 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
878 scm_call_2 (proc, $1, $2);
879 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
880 parser->parser_error (@2, _("bad expression type"));
884 Book *book = unsmob_book ($1);
885 if (!ly_is_module (book->header_))
886 book->header_ = ly_make_module (false);
887 parser->lexer_->add_scope (book->header_);
889 | bookpart_body error {
890 Book *book = unsmob_book ($1);
892 book->scores_ = SCM_EOL;
897 SCORE '{' score_body '}' {
898 unsmob_score ($3)->origin ()->set_spot (@$);
910 if (!scm_is_pair ($1)
911 || !ly_is_module (scm_car ($1)))
912 $1 = scm_cons (ly_make_module (false), $1);
913 parser->lexer_->add_scope (scm_car ($1));
918 | score_headers output_def
920 Output_def *od = unsmob_output_def ($2);
921 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
923 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
928 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
929 scm_set_cdr_x ($1, scm_cons ($2, scm_cdr ($1)));
931 $$ = scm_cons ($2, $1);
939 score_headers music {
940 SCM scorify = ly_lily_module_constant ("scorify-music");
941 $$ = scm_call_2 (scorify, $2, parser->self_scm ());
943 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
945 unsmob_score ($$)->set_header (scm_car ($1));
948 for (SCM p = scm_reverse_x ($1, SCM_EOL);
949 scm_is_pair (p); p = scm_cdr (p))
952 add_output_def (unsmob_output_def (scm_car (p)));
955 | embedded_scm_active {
956 if (!unsmob_score ($1))
958 $$ = (new Score)->unprotect ();
959 parser->parser_error (@1, _("score expected"));
964 Score *score = unsmob_score ($1);
965 if (!ly_is_module (score->get_header ()))
966 score->set_header (ly_make_module (false));
967 parser->lexer_->add_scope (score->get_header ());
969 | score_body output_def {
970 Output_def *od = unsmob_output_def ($2);
971 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
973 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
978 unsmob_score ($1)->add_output_def (od);
982 unsmob_score ($$)->error_found_ = true;
993 Output_def *od = unsmob_output_def ($1);
995 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
997 parser->parser_error (@1, _ ("need \\paper for paper block"));
998 $$ = get_paper (parser)->unprotect ();
1005 output_def_body '}' {
1008 parser->lexer_->remove_scope ();
1009 parser->lexer_->pop_state ();
1015 Output_def *p = get_paper (parser);
1016 p->input_origin_ = @$;
1017 parser->lexer_->add_scope (p->scope_);
1018 $$ = p->unprotect ();
1021 Output_def *p = get_midi (parser);
1022 $$ = p->unprotect ();
1023 parser->lexer_->add_scope (p->scope_);
1026 Output_def *p = get_layout (parser);
1028 parser->lexer_->add_scope (p->scope_);
1029 $$ = p->unprotect ();
1033 output_def_head_with_mode_switch:
1035 parser->lexer_->push_initial_state ();
1040 // We need this weird nonterminal because both music as well as a
1041 // context definition can start with \context and the difference is
1042 // only apparent after looking at the next token. If it is '{', there
1043 // is still time to escape from notes mode.
1045 music_or_context_def:
1047 | context_def_spec_block
1051 output_def_head_with_mode_switch '{' {
1053 unsmob_output_def ($$)->input_origin_.set_spot (@$);
1055 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1056 Output_def *o = unsmob_output_def ($3);
1057 o->input_origin_.set_spot (@$);
1058 $$ = o->self_scm ();
1059 parser->lexer_->remove_scope ();
1060 parser->lexer_->add_scope (o->scope_);
1062 | output_def_body assignment {
1065 | output_def_body embedded_scm {
1070 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1071 parser->lexer_->push_note_state (nn);
1072 } music_or_context_def
1074 parser->lexer_->pop_state ();
1075 if (unsmob_context_def ($3))
1076 assign_context_def (unsmob_output_def ($1), $3);
1079 SCM proc = parser->lexer_->lookup_identifier
1080 ("output-def-music-handler");
1081 scm_call_3 (proc, parser->self_scm (),
1085 | output_def_body error {
1091 TEMPO steno_duration '=' tempo_range {
1092 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1094 | TEMPO scalar steno_duration '=' tempo_range {
1095 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1098 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1103 The representation of a list is reversed to have efficient append. */
1109 | music_list music_embedded {
1110 if (unsmob_music ($2))
1111 $$ = scm_cons ($2, $1);
1113 | music_list error {
1114 Music *m = MY_MAKE_MUSIC("Music", @$);
1116 m->set_property ("error-found", SCM_BOOL_T);
1117 $$ = scm_cons (m->self_scm (), $1);
1118 m->unprotect (); /* UGH */
1125 $$ = scm_reverse_x ($2, SCM_EOL);
1130 | lyric_element_music
1136 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1137 parser->parser_error (@1, _ ("unexpected post-event"));
1138 $$ = SCM_UNSPECIFIED;
1141 | music_embedded_backup
1145 | music_embedded_backup BACKUP lyric_element_music
1149 | multiplied_duration post_events
1151 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1153 parser->default_duration_ = *unsmob_duration ($1);
1154 n->set_property ("duration", $1);
1156 if (scm_is_pair ($2))
1157 n->set_property ("articulations",
1158 scm_reverse_x ($2, SCM_EOL));
1159 $$ = n->unprotect ();
1163 music_embedded_backup:
1166 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1168 else if (Music *m = unsmob_music ($1)) {
1169 if (m->is_mus_type ("post-event")) {
1170 parser->parser_error
1171 (@1, _ ("unexpected post-event"));
1172 $$ = SCM_UNSPECIFIED;
1175 } else if (parser->lexer_->is_lyric_state ()
1176 && Text_interface::is_markup ($1))
1177 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1179 @$.warning (_ ("Ignoring non-music expression"));
1188 $$ = make_music_from_simple (parser, @1, $1);
1189 if (!unsmob_music ($$))
1191 parser->parser_error (@1, _ ("music expected"));
1192 $$ = MAKE_SYNTAX ("void-music", @$);
1195 | composite_music %prec COMPOSITE
1200 | composite_music %prec COMPOSITE
1204 REPEAT simple_string unsigned_number music
1206 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1208 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1210 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1215 SEQUENTIAL braced_music_list {
1216 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1218 | braced_music_list {
1219 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1224 SIMULTANEOUS braced_music_list {
1225 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1227 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1228 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1234 | music_property_def
1238 context_modification:
1241 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1242 parser->lexer_->push_note_state (nn);
1243 } '{' context_mod_list '}'
1245 parser->lexer_->pop_state ();
1248 | WITH CONTEXT_MOD_IDENTIFIER
1252 | CONTEXT_MOD_IDENTIFIER
1256 | WITH context_modification_arg
1258 if (unsmob_music ($2)) {
1259 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1260 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1262 if (unsmob_context_mod ($2))
1265 parser->parser_error (@2, _ ("not a context mod"));
1266 $$ = Context_mod ().smobbed_copy ();
1271 context_modification_arg:
1276 optional_context_mod:
1280 | context_modification
1288 $$ = Context_mod ().smobbed_copy ();
1290 | context_mod_list context_mod {
1291 if (!SCM_UNBNDP ($2))
1292 unsmob_context_mod ($1)->add_context_mod ($2);
1294 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1295 Context_mod *md = unsmob_context_mod ($2);
1297 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1299 | context_mod_list context_mod_embedded {
1300 unsmob_context_mod ($1)->add_context_mods
1301 (unsmob_context_mod ($2)->get_mods ());
1313 | grouped_music_list
1317 simultaneous_music { $$ = $1; }
1318 | sequential_music { $$ = $1; }
1321 /* Function argument lists are arguably the most complex part in the
1322 * parser. They are pretty tricky to understand because of the way
1323 * they are processed, and because of optional arguments that can be
1324 * omitted. When there are several optional arguments in a row,
1325 * omitting one automatically omits all following arguments. Optional
1326 * arguments can only be omitted when either
1328 * a) the omission is explicitly started with \default
1329 * b) the omission is implicitly started by an argument not matching
1330 * its predicate, and there is a mandatory argument later that can
1331 * "catch" the argument that does not fit.
1333 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1334 * (corresponding to mandatory arguments and having a predicate
1335 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1336 * the semantic value of the EXPECT_OPTIONAL token is the default to
1337 * use when the optional argument is omitted, and EXPECT_SCM again has
1338 * the argument predicate as semantic value) in reverse order to the
1339 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1340 * processed inside-out while actual tokens are consumed.
1342 * This means that the argument list tokens determine the actions
1343 * taken as they arrive. The structure of the argument list is known
1344 * to the parser and stored in its parse stack when the first argument
1345 * is being parsed. What the parser does not know is which predicates
1346 * will match and whether or not \default will be appearing in the
1347 * argument list, and where.
1349 * Sequences of 0 or more optional arguments are scanned using either
1350 * function_arglist_backup or function_arglist_nonbackup. The first
1351 * is used when optional arguments are followed by at least one
1352 * mandatory argument: in that case optional arguments may be skipped
1353 * by either a false predicate (in which case the expression will be
1354 * pushed back as one or more tokens, preceded by a BACKUP token) or
1355 * by using \default.
1357 * If optional arguments are at the end of the argument list, they are
1358 * instead scanned using function_arglist_nonbackup: here the only
1359 * manner to enter into skipping of optional arguments is the use of
1362 * The argument list of a normal function call is parsed using
1363 * function_arglist. The part of an argument list before a mandatory
1364 * argument is parsed using function_arglist_optional.
1366 * The difference is that leading optional arguments are scanned using
1367 * function_arglist_nonbackup and function_arglist_backup,
1370 * Most other details are obvious in the rules themselves.
1376 | SYMBOL_LIST '.' symbol_list_rev
1378 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1384 | symbol_list_rev '.' symbol_list_part
1386 $$ = scm_append_x (scm_list_2 ($3, $1));
1390 // symbol_list_part delivers elements in reverse copy.
1395 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1396 $$ = try_string_variants (sym_l_p, $1);
1397 if (SCM_UNBNDP ($$)) {
1398 parser->parser_error (@1, _("not a symbol"));
1401 $$ = scm_reverse ($$);
1406 symbol_list_element:
1412 function_arglist_nonbackup:
1413 function_arglist_common
1414 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1416 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1418 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1420 SCM n = scm_difference ($5, SCM_UNDEFINED);
1421 if (scm_is_true (scm_call_1 ($2, n)))
1422 $$ = scm_cons (n, $3);
1424 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1425 t->set_property ("digit", $5);
1426 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1431 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1433 $$ = check_scheme_arg (parser, @4,
1434 scm_difference ($5, SCM_UNDEFINED),
1437 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1439 $$ = check_scheme_arg (parser, @4,
1440 scm_difference ($5, SCM_UNDEFINED),
1443 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1445 if (scm_is_true (scm_call_1 ($2, $4)))
1446 $$ = scm_cons ($4, $3);
1448 $$ = check_scheme_arg (parser, @4,
1449 make_music_from_simple
1453 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1455 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1457 | function_arglist_nonbackup_reparse REPARSE duration_length
1459 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1461 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1463 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1465 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1467 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1469 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1471 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1473 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1475 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1479 function_arglist_nonbackup_reparse:
1480 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1483 SCM res = try_string_variants ($2, $4);
1484 if (!SCM_UNBNDP (res))
1485 if (scm_is_pair (res))
1486 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1488 MYREPARSE (@4, $2, SCM_ARG, res);
1489 else if (scm_is_true
1491 ($2, make_music_from_simple
1493 MYREPARSE (@4, $2, STRING, $4);
1495 MYREPARSE (@4, $2, SCM_ARG, $4);
1497 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1500 SCM res = try_string_variants ($2, $4);
1501 if (!SCM_UNBNDP (res))
1502 if (scm_is_pair (res))
1503 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1505 MYREPARSE (@4, $2, SCM_ARG, res);
1506 else if (scm_is_true
1508 ($2, make_music_from_simple
1510 MYREPARSE (@4, $2, STRING, $4);
1512 MYREPARSE (@4, $2, SCM_ARG, $4);
1514 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1517 if (scm_is_true (scm_call_1 ($2, $4)))
1518 MYREPARSE (@4, $2, SCM_ARG, $4);
1519 else if (scm_is_true
1521 ($2, make_music_from_simple
1523 MYREPARSE (@4, $2, STRING, $4);
1525 MYREPARSE (@4, $2, SCM_ARG, $4);
1527 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1530 if (scm_is_true (scm_call_1 ($2, $4)))
1531 MYREPARSE (@4, $2, REAL, $4);
1533 SCM d = make_duration ($4);
1534 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1535 MYREPARSE (@4, $2, REAL, $4); // trigger error
1537 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1540 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1542 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1547 // function_arglist_backup can't occur at the end of an argument
1549 function_arglist_backup:
1550 function_arglist_common
1551 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1553 if (scm_is_true (scm_call_1 ($2, $4)))
1554 $$ = scm_cons ($4, $3);
1556 $$ = make_music_from_simple (parser, @4, $4);
1557 if (scm_is_true (scm_call_1 ($2, $$)))
1558 $$ = scm_cons ($$, $3);
1561 $$ = scm_cons (loc_on_music (@3, $1), $3);
1562 MYBACKUP (SCM_ARG, $4, @4);
1566 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1568 if (scm_is_true (scm_call_1 ($2, $4)))
1570 $$ = scm_cons ($4, $3);
1572 $$ = scm_cons (loc_on_music (@3, $1), $3);
1573 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1576 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1578 if (scm_is_true (scm_call_1 ($2, $4)))
1579 $$ = scm_cons ($4, $3);
1581 $$ = scm_cons (loc_on_music (@3, $1), $3);
1582 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1585 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1587 if (scm_is_true (scm_call_1 ($2, $4)))
1589 MYREPARSE (@4, $2, REAL, $4);
1592 SCM d = make_duration ($4);
1593 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1595 $$ = scm_cons (loc_on_music (@3, $1), $3);
1596 MYBACKUP (UNSIGNED, $4, @4);
1598 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1603 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1605 if (scm_is_true (scm_call_1 ($2, $4)))
1608 MYREPARSE (@4, $2, REAL, $4);
1610 $$ = scm_cons (loc_on_music (@3, $1), $3);
1611 MYBACKUP (REAL, $4, @4);
1614 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1616 if (scm_is_true (scm_call_1 ($2, $4)))
1618 $$ = scm_cons ($4, $3);
1620 $$ = scm_cons (loc_on_music (@3, $1), $3);
1621 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1624 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1626 SCM n = scm_difference ($5, SCM_UNDEFINED);
1627 if (scm_is_true (scm_call_1 ($2, n))) {
1629 MYREPARSE (@5, $2, REAL, n);
1631 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1632 t->set_property ("digit", $5);
1633 $$ = t->unprotect ();
1634 if (scm_is_true (scm_call_1 ($2, $$)))
1635 $$ = scm_cons ($$, $3);
1637 $$ = scm_cons (loc_on_music (@3, $1), $3);
1638 MYBACKUP (UNSIGNED, $5, @5);
1639 parser->lexer_->push_extra_token (@4, '-');
1644 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1646 SCM n = scm_difference ($5, SCM_UNDEFINED);
1647 if (scm_is_true (scm_call_1 ($2, n))) {
1648 MYREPARSE (@5, $2, REAL, n);
1651 $$ = scm_cons (loc_on_music (@3, $1), $3);
1652 MYBACKUP (REAL, n, @5);
1655 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1657 SCM n = scm_difference ($5, SCM_UNDEFINED);
1658 if (scm_is_true (scm_call_1 ($2, n))) {
1659 $$ = scm_cons (n, $3);
1661 $$ = scm_cons (loc_on_music (@3, $1), $3);
1662 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1665 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1667 if (scm_is_true (scm_call_1 ($2, $4)))
1669 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1672 $$ = scm_cons (loc_on_music (@3, $1), $3);
1673 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1676 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1678 SCM res = try_string_variants ($2, $4);
1679 if (!SCM_UNBNDP (res))
1680 if (scm_is_pair (res)) {
1682 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1685 $$ = scm_cons (res, $3);
1687 $$ = scm_cons (loc_on_music (@3, $1), $3);
1688 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1691 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1693 SCM res = try_string_variants ($2, $4);
1694 if (!SCM_UNBNDP (res))
1695 if (scm_is_pair (res)) {
1697 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1700 $$ = scm_cons (res, $3);
1702 $$ = scm_cons (loc_on_music (@3, $1), $3);
1703 MYBACKUP (STRING, $4, @4);
1706 | function_arglist_backup REPARSE music_assign
1708 if (scm_is_true (scm_call_1 ($2, $3)))
1709 $$ = scm_cons ($3, $1);
1711 $$ = check_scheme_arg (parser, @3,
1712 make_music_from_simple
1716 | function_arglist_backup REPARSE pitch_arg
1718 $$ = check_scheme_arg (parser, @3,
1721 | function_arglist_backup REPARSE bare_number_common
1723 $$ = check_scheme_arg (parser, @3,
1726 | function_arglist_backup REPARSE duration_length
1728 $$ = check_scheme_arg (parser, @3,
1731 | function_arglist_backup REPARSE symbol_list_arg
1733 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1738 function_arglist_nonbackup
1739 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1741 $$ = scm_cons (loc_on_music (@4, $1), $3);
1745 function_arglist_skip_nonbackup:
1746 function_arglist_nonbackup
1747 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1749 $$ = scm_cons (loc_on_music (@3, $1), $3);
1753 function_arglist_common:
1754 EXPECT_NO_MORE_ARGS {
1757 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1759 if (scm_is_true (scm_call_1 ($1, $3)))
1760 $$ = scm_cons ($3, $2);
1762 $$ = check_scheme_arg (parser, @3,
1763 make_music_from_simple
1767 | EXPECT_SCM function_arglist_optional bare_number_common
1769 $$ = check_scheme_arg (parser, @3,
1772 | EXPECT_SCM function_arglist_optional post_event_nofinger
1774 $$ = check_scheme_arg (parser, @3,
1777 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1779 SCM n = scm_difference ($4, SCM_UNDEFINED);
1780 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1782 | function_arglist_common_reparse REPARSE SCM_ARG
1784 $$ = check_scheme_arg (parser, @3,
1787 | function_arglist_common_reparse REPARSE lyric_element_music
1789 $$ = check_scheme_arg (parser, @3,
1792 | function_arglist_common_reparse REPARSE bare_number_common
1794 $$ = check_scheme_arg (parser, @3,
1797 | function_arglist_common_reparse REPARSE duration_length
1799 $$ = check_scheme_arg (parser, @3,
1802 | function_arglist_common_reparse REPARSE symbol_list_arg
1804 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1808 function_arglist_common_reparse:
1809 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1812 SCM res = try_string_variants ($1, $3);
1813 if (!SCM_UNBNDP (res))
1814 if (scm_is_pair (res))
1815 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1817 MYREPARSE (@3, $1, SCM_ARG, res);
1818 else if (scm_is_true
1820 ($1, make_music_from_simple (parser, @3, $3))))
1821 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1823 // This is going to flag a syntax error, we
1824 // know the predicate to be false.
1825 MYREPARSE (@3, $1, SCM_ARG, $3);
1827 | EXPECT_SCM function_arglist_optional STRING
1830 SCM res = try_string_variants ($1, $3);
1831 if (!SCM_UNBNDP (res))
1832 if (scm_is_pair (res))
1833 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1835 MYREPARSE (@3, $1, SCM_ARG, res);
1836 else if (scm_is_true
1838 ($1, make_music_from_simple (parser, @3, $3))))
1839 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1841 // This is going to flag a syntax error, we
1842 // know the predicate to be false.
1843 MYREPARSE (@3, $1, SCM_ARG, $3);
1845 | EXPECT_SCM function_arglist_optional full_markup
1848 if (scm_is_true (scm_call_1 ($1, $3)))
1849 MYREPARSE (@3, $1, SCM_ARG, $3);
1850 else if (scm_is_true
1852 ($1, make_music_from_simple (parser, @3, $3))))
1853 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1855 // This is going to flag a syntax error, we
1856 // know the predicate to be false.
1857 MYREPARSE (@3, $1, SCM_ARG, $3);
1859 | EXPECT_SCM function_arglist_optional UNSIGNED
1862 if (scm_is_true (scm_call_1 ($1, $3)))
1863 MYREPARSE (@3, $1, REAL, $3);
1865 SCM d = make_duration ($3);
1866 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
1867 MYREPARSE (@3, $1, REAL, $3);
1869 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
1872 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
1875 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
1877 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
1880 SCM n = scm_difference ($4, SCM_UNDEFINED);
1881 if (scm_is_true (scm_call_1 ($1, n)))
1882 MYREPARSE (@4, $1, REAL, n);
1884 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1885 t->set_property ("digit", $4);
1886 SCM m = t->unprotect ();
1887 if (scm_is_true (scm_call_1 ($1, m)))
1888 MYREPARSE (@4, $1, SCM_ARG, m);
1890 MYREPARSE (@4, $1, SCM_ARG, $4);
1894 | EXPECT_SCM function_arglist_optional '-' REAL
1897 SCM n = scm_difference ($4, SCM_UNDEFINED);
1898 MYREPARSE (@4, $1, REAL, n);
1902 function_arglist_optional:
1903 function_arglist_backup
1904 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
1906 $$ = scm_cons (loc_on_music (@4, $1), $3);
1908 | function_arglist_skip_backup BACKUP
1911 function_arglist_skip_backup:
1912 function_arglist_backup
1913 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
1915 $$ = scm_cons (loc_on_music (@3, $1), $3);
1919 music_function_call:
1920 MUSIC_FUNCTION function_arglist {
1921 $$ = MAKE_SYNTAX ("music-function", @$,
1928 /**/ { $$ = SCM_EOL; }
1929 | '=' simple_string {
1936 | repeated_music { $$ = $1; }
1937 | re_rhythmed_music { $$ = $1; }
1938 | complex_music_prefix music
1940 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1944 complex_music_prefix:
1945 CONTEXT symbol optional_id optional_context_mod {
1946 Context_mod *ctxmod = unsmob_context_mod ($4);
1949 mods = ctxmod->get_mods ();
1950 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1952 | NEWCONTEXT symbol optional_id optional_context_mod {
1953 Context_mod *ctxmod = unsmob_context_mod ($4);
1956 mods = ctxmod->get_mods ();
1957 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1962 mode_changing_head grouped_music_list {
1963 if ($1 == ly_symbol2scm ("chords"))
1965 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1971 parser->lexer_->pop_state ();
1973 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1974 Context_mod *ctxmod = unsmob_context_mod ($2);
1977 mods = ctxmod->get_mods ();
1978 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1979 if ($1 == ly_symbol2scm ("ChordNames"))
1981 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1983 parser->lexer_->pop_state ();
1989 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1990 parser->lexer_->push_note_state (nn);
1992 $$ = ly_symbol2scm ("notes");
1996 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1997 parser->lexer_->push_note_state (nn);
1999 $$ = ly_symbol2scm ("drums");
2002 parser->lexer_->push_figuredbass_state ();
2004 $$ = ly_symbol2scm ("figures");
2007 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2008 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2009 nn = parser->lexer_->lookup_identifier ("pitchnames");
2010 parser->lexer_->push_chord_state (nn);
2011 $$ = ly_symbol2scm ("chords");
2015 { parser->lexer_->push_lyric_state ();
2016 $$ = ly_symbol2scm ("lyrics");
2020 mode_changing_head_with_context:
2022 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2023 parser->lexer_->push_note_state (nn);
2025 $$ = ly_symbol2scm ("DrumStaff");
2028 parser->lexer_->push_figuredbass_state ();
2030 $$ = ly_symbol2scm ("FiguredBass");
2033 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2034 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2035 nn = parser->lexer_->lookup_identifier ("pitchnames");
2036 parser->lexer_->push_chord_state (nn);
2037 $$ = ly_symbol2scm ("ChordNames");
2040 { parser->lexer_->push_lyric_state ();
2041 $$ = ly_symbol2scm ("Lyrics");
2046 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2049 /* Can also use music at the expensive of two S/Rs similar to
2050 \repeat \alternative */
2051 parser->lexer_->pop_state ();
2053 $$ = scm_cons ($3, SCM_EOL);
2055 | new_lyrics ADDLYRICS {
2056 parser->lexer_->push_lyric_state ();
2058 parser->lexer_->pop_state ();
2059 $$ = scm_cons ($4, $1);
2064 composite_music new_lyrics {
2065 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2067 | LYRICSTO simple_string {
2068 parser->lexer_->push_lyric_state ();
2070 parser->lexer_->pop_state ();
2071 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2076 CHANGE symbol '=' simple_string {
2077 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2084 $$ = scm_reverse_x ($1, SCM_EOL);
2086 | symbol_list_rev property_path {
2087 $$ = scm_reverse_x ($1, $2);
2093 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2096 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2098 | OVERRIDE property_path '=' scalar {
2099 if (scm_ilength ($2) < 2) {
2100 parser->parser_error (@2, _("bad grob property path"));
2103 $$ = scm_cons (ly_symbol2scm ("push"),
2104 scm_cons2 (scm_car ($2),
2109 | REVERT revert_arg {
2110 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2114 // This is all quite awkward for the sake of substantial backward
2115 // compatibility while at the same time allowing a more "natural" form
2116 // of specification not separating grob specification from grob
2117 // property path. The purpose of this definition of revert_arg is to
2118 // allow the symbol list which specifies grob and property to revert
2119 // to be optionally be split into two parts after the grob (which in
2120 // this case is just the first element of the list). symbol_list_part
2121 // is only one path component, but it can be parsed without lookahead,
2122 // so we can follow it with a synthetic BACKUP token when needed. If
2123 // the first symbol_list_part already contains multiple elements (only
2124 // possible if a Scheme expression provides them), we just parse for
2125 // additional elements introduced by '.', which is what the
2126 // SYMBOL_LIST backup in connection with the immediately following
2127 // rule using symbol_list_arg does.
2129 // As long as we don't have our coffers filled with both grob and at
2130 // least one grob property specification, the rest of the required
2131 // symbol list chain may be provided either with or without a leading
2132 // dot. This is for both allowing the traditional
2133 // \revert Accidental #'color
2134 // as well as well as the "naive" form
2135 // \revert Accidental.color
2138 revert_arg_backup BACKUP symbol_list_arg
2147 if (scm_is_null ($1)
2148 || scm_is_null (scm_cdr ($1)))
2149 MYBACKUP (SCM_ARG, $1, @1);
2151 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2155 // revert_arg_part delivers results in reverse
2158 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2160 $$ = scm_append_x (scm_list_2 ($5, $3));
2162 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2164 $$ = scm_append_x (scm_list_2 ($4, $3));
2169 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2170 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2172 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2173 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2174 | DENIES { $$ = ly_symbol2scm ("denies"); }
2176 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2177 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2178 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2179 | NAME { $$ = ly_symbol2scm ("context-name"); }
2183 property_operation { $$ = $1; }
2184 | context_def_mod STRING {
2185 $$ = scm_list_2 ($1, $2);
2187 | context_def_mod embedded_scm
2189 if (!scm_is_string ($2)
2190 && ly_symbol2scm ("consists") != $1
2191 && ly_symbol2scm ("remove") != $1)
2194 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2198 $$ = scm_list_2 ($1, $2);
2203 // If defined, at least two members.
2207 SCM l = scm_reverse_x ($1, SCM_EOL);
2210 (scm_object_property (scm_car (l),
2211 ly_symbol2scm ("is-grob?"))))
2212 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2213 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2214 parser->parser_error (@1, _ ("bad grob property path"));
2221 // If defined, at least three members
2225 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2227 parser->parser_error (@1, _ ("bad grob property path"));
2231 | grob_prop_spec property_path
2233 if (!SCM_UNBNDP ($1)) {
2234 $$ = scm_append_x (scm_list_2 ($1, $2));
2235 if (scm_is_null (scm_cddr ($$))) {
2236 parser->parser_error (@$, _ ("bad grob property path"));
2244 // Exactly two elements or undefined
2248 SCM l = scm_reverse_x ($1, SCM_EOL);
2249 switch (scm_ilength (l)) {
2251 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2255 parser->parser_error (@1, _ ("bad context property path"));
2262 simple_music_property_def:
2263 OVERRIDE grob_prop_path '=' scalar {
2264 if (SCM_UNBNDP ($2))
2267 $$ = scm_list_5 (scm_car ($2),
2268 ly_symbol2scm ("OverrideProperty"),
2274 | REVERT simple_revert_context revert_arg {
2275 $$ = scm_list_4 ($2,
2276 ly_symbol2scm ("RevertProperty"),
2280 | SET context_prop_spec '=' scalar {
2281 if (SCM_UNBNDP ($2))
2284 $$ = scm_list_4 (scm_car ($2),
2285 ly_symbol2scm ("PropertySet"),
2289 | UNSET context_prop_spec {
2290 if (SCM_UNBNDP ($2))
2293 $$ = scm_list_3 (scm_car ($2),
2294 ly_symbol2scm ("PropertyUnset"),
2300 // This is all quite awkward for the sake of substantial backward
2301 // compatibility while at the same time allowing a more "natural" form
2302 // of specification not separating grob specification from grob
2303 // property path. The purpose of this definition of
2304 // simple_revert_context is to allow the symbol list which specifies
2305 // grob and property to revert to be optionally be split into two
2306 // parts after the grob (which may be preceded by a context
2307 // specification, a case which we distinguish by checking whether the
2308 // first symbol is a valid grob symbol instead).
2310 // See revert_arg above for the main work horse of this arrangement.
2311 // simple_revert_context just caters for the context and delegates the
2312 // rest of the job to revert_arg.
2314 simple_revert_context:
2317 $1 = scm_reverse_x ($1, SCM_EOL);
2318 if (scm_is_null ($1)
2320 (scm_object_property (scm_car ($1),
2321 ly_symbol2scm ("is-grob?")))) {
2322 $$ = ly_symbol2scm ("Bottom");
2323 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2326 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2333 simple_music_property_def {
2334 if (SCM_UNBNDP ($1))
2335 $$ = MAKE_SYNTAX ("void-music", @1);
2337 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2348 simple_string: STRING {
2353 if (scm_is_string ($1)) {
2356 parser->parser_error (@1, (_ ("simple string expected")));
2357 $$ = scm_string (SCM_EOL);
2364 $$ = scm_string_to_symbol ($1);
2368 // This is a bit of overkill but makes the same
2369 // routine responsible for all symbol interpretations.
2370 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2372 if (SCM_UNBNDP ($$))
2374 parser->parser_error (@1, (_ ("symbol expected")));
2375 // Generate a unique symbol in case it is used
2376 // for an assignment or similar
2377 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2386 // The following is a rather defensive variant of admitting
2387 // negative numbers: the grammar would permit number_factor or
2388 // even number_expression. However, function arguments allow
2389 // only this simple kind of negative number, so to have things
2390 // like \tweak and \override behave reasonably similar, it
2391 // makes sense to rule out things like -- which are rather an
2392 // accent in function argument contexts.
2395 $$ = scm_difference ($2, SCM_UNDEFINED);
2402 simple_element post_events {
2403 // Let the rhythmic music iterator sort this mess out.
2404 if (scm_is_pair ($2)) {
2405 $$ = make_music_from_simple (parser, @1, $1);
2406 if (unsmob_music ($$))
2407 unsmob_music ($$)->set_property ("articulations",
2408 scm_reverse_x ($2, SCM_EOL));
2411 parser->parser_error (@1, _("music expected"));
2412 $$ = MAKE_SYNTAX ("void-music", @1);
2416 | simple_chord_elements post_events {
2417 if (scm_is_pair ($2)) {
2418 if (unsmob_pitch ($1))
2419 $1 = make_chord_elements (@1,
2421 parser->default_duration_.smobbed_copy (),
2424 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2426 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
2427 } else if (!unsmob_pitch ($1))
2428 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
2429 // A mere pitch drops through.
2431 | CHORD_REPETITION optional_notemode_duration post_events {
2433 i.set_location (@1, @3);
2434 $$ = MAKE_SYNTAX ("repetition-chord", i,
2435 $2, scm_reverse_x ($3, SCM_EOL));
2437 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2439 i.set_location (@1, @3);
2440 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2441 scm_reverse_x ($3, SCM_EOL));
2444 | note_chord_element
2449 chord_body optional_notemode_duration post_events
2451 Music *m = unsmob_music ($1);
2452 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2453 SCM es = m->get_property ("elements");
2454 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2456 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2457 unsmob_music (scm_car (s))->set_property ("duration", dur);
2458 es = ly_append2 (es, postevs);
2460 m-> set_property ("elements", es);
2462 $$ = m->self_scm ();
2467 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2469 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2473 chord_body_elements:
2474 /* empty */ { $$ = SCM_EOL; }
2475 | chord_body_elements chord_body_element {
2476 if (!SCM_UNBNDP ($2))
2477 $$ = scm_cons ($2, $1);
2482 pitch exclamations questions octave_check post_events
2484 bool q = to_boolean ($3);
2485 bool ex = to_boolean ($2);
2489 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2490 n->set_property ("pitch", $1);
2492 n->set_property ("cautionary", SCM_BOOL_T);
2494 n->set_property ("force-accidental", SCM_BOOL_T);
2496 if (scm_is_pair (post)) {
2497 SCM arts = scm_reverse_x (post, SCM_EOL);
2498 n->set_property ("articulations", arts);
2500 if (scm_is_number (check))
2502 int q = scm_to_int (check);
2503 n->set_property ("absolute-octave", scm_from_int (q-1));
2506 $$ = n->unprotect ();
2508 | DRUM_PITCH post_events {
2509 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2510 n->set_property ("drum-type", $1);
2512 if (scm_is_pair ($2)) {
2513 SCM arts = scm_reverse_x ($2, SCM_EOL);
2514 n->set_property ("articulations", arts);
2516 $$ = n->unprotect ();
2518 | music_function_chord_body
2520 Music *m = unsmob_music ($1);
2522 while (m && m->is_mus_type ("music-wrapper-music")) {
2523 $$ = m->get_property ("element");
2524 m = unsmob_music ($$);
2527 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2528 parser->parser_error (@$, _ ("not a rhythmic event"));
2534 music_function_chord_body:
2539 event_function_event:
2540 EVENT_FUNCTION function_arglist {
2541 $$ = MAKE_SYNTAX ("music-function", @$,
2563 | post_events post_event {
2565 if (Music *m = unsmob_music ($2))
2567 if (m->is_mus_type ("post-event-wrapper"))
2569 for (SCM p = m->get_property ("elements");
2573 $$ = scm_cons (scm_car (p), $$);
2577 $$ = scm_cons ($2, $$);
2583 post_event_nofinger:
2584 direction_less_event {
2587 | script_dir music_function_call {
2589 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2590 parser->parser_error (@2, _ ("post-event expected"));
2591 $$ = SCM_UNSPECIFIED;
2592 } else if (!SCM_UNBNDP ($1))
2594 unsmob_music ($$)->set_property ("direction", $1);
2598 if (!parser->lexer_->is_lyric_state ())
2599 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2600 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2603 if (!parser->lexer_->is_lyric_state ())
2604 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2605 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2607 | script_dir direction_reqd_event {
2608 if (!SCM_UNBNDP ($1))
2610 Music *m = unsmob_music ($2);
2611 m->set_property ("direction", $1);
2615 | script_dir direction_less_event {
2616 if (!SCM_UNBNDP ($1))
2618 Music *m = unsmob_music ($2);
2619 m->set_property ("direction", $1);
2626 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2631 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2642 string_number_event:
2644 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2645 s->set_property ("string-number", $1);
2646 $$ = s->unprotect ();
2650 direction_less_event:
2652 | EVENT_IDENTIFIER {
2656 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2657 a->set_property ("tremolo-type", $1);
2658 $$ = a->unprotect ();
2660 | event_function_event
2663 direction_reqd_event:
2667 | script_abbreviation {
2668 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2669 if (scm_is_string (s)) {
2670 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2671 a->set_property ("articulation-type", s);
2672 $$ = a->unprotect ();
2674 Music *original = unsmob_music (s);
2675 if (original && original->is_mus_type ("post-event")) {
2676 Music *a = original->clone ();
2677 a->set_spot (parser->lexer_->override_input (@$));
2678 $$ = a->unprotect ();
2680 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2681 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2688 /**/ { $$ = SCM_EOL; }
2689 | '=' quotes { $$ = $2; }
2703 $$ = scm_from_int (1);
2706 $$ = scm_oneplus ($1);
2712 $$ = scm_from_int (-1);
2715 $$ = scm_oneminus ($1);
2720 NOTENAME_PITCH quotes {
2721 if (!scm_is_eq (SCM_INUM0, $2))
2723 Pitch p = *unsmob_pitch ($1);
2724 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2725 $$ = p.smobbed_copy ();
2735 TONICNAME_PITCH quotes {
2736 if (!scm_is_eq (SCM_INUM0, $2))
2738 Pitch p = *unsmob_pitch ($1);
2739 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2740 $$ = p.smobbed_copy ();
2747 | PITCH_IDENTIFIER quotes {
2748 if (!scm_is_eq (SCM_INUM0, $2))
2750 Pitch p = *unsmob_pitch ($1);
2751 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2752 $$ = p.smobbed_copy ();
2759 if (!scm_is_eq (SCM_INUM0, $2))
2761 Pitch p = *unsmob_pitch ($1);
2762 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2763 $$ = p.smobbed_copy ();
2770 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2771 t->set_property ("text", $1);
2772 $$ = t->unprotect ();
2775 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2776 t->set_property ("text",
2777 make_simple_markup ($1));
2778 $$ = t->unprotect ();
2782 Music *m = unsmob_music ($1);
2783 if (m && m->is_mus_type ("post-event"))
2785 else if (Text_interface::is_markup ($1)) {
2786 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2787 t->set_property ("text", $1);
2788 $$ = t->unprotect ();
2790 parser->parser_error (@1, _ ("not an articulation"));
2796 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2797 t->set_property ("digit", $1);
2798 $$ = t->unprotect ();
2802 script_abbreviation:
2804 $$ = scm_from_locale_string ("Hat");
2807 $$ = scm_from_locale_string ("Plus");
2810 $$ = scm_from_locale_string ("Dash");
2813 $$ = scm_from_locale_string ("Bang");
2816 $$ = scm_from_locale_string ("Larger");
2819 $$ = scm_from_locale_string ("Dot");
2822 $$ = scm_from_locale_string ("Underscore");
2827 '_' { $$ = scm_from_int (DOWN); }
2828 | '^' { $$ = scm_from_int (UP); }
2829 | '-' { $$ = SCM_UNDEFINED; }
2833 multiplied_duration {
2838 maybe_notemode_duration:
2842 | multiplied_duration {
2844 parser->default_duration_ = *unsmob_duration ($$);
2849 optional_notemode_duration:
2850 maybe_notemode_duration
2852 if (SCM_UNBNDP ($$))
2853 $$ = parser->default_duration_.smobbed_copy ();
2859 $$ = make_duration ($1, scm_to_int ($2));
2860 if (SCM_UNBNDP ($$))
2862 parser->parser_error (@1, _ ("not a duration"));
2863 $$ = Duration ().smobbed_copy ();
2866 | DURATION_IDENTIFIER dots {
2867 Duration *d = unsmob_duration ($1);
2868 Duration k (d->duration_log (),
2869 d->dot_count () + scm_to_int ($2));
2870 k = k.compressed (d->factor ());
2871 scm_remember_upto_here_1 ($1);
2872 $$ = k.smobbed_copy ();
2876 multiplied_duration:
2880 | multiplied_duration '*' UNSIGNED {
2881 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2883 | multiplied_duration '*' FRACTION {
2884 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2886 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2895 $$ = scm_oneplus ($1);
2904 if (SCM_UNBNDP (make_duration ($2)))
2905 parser->parser_error (@2, _ ("not a duration"));
2911 UNSIGNED { $$ = $1; }
2912 | STRING { $$ = $1; }
2913 | full_markup { $$ = $1; }
2916 // as an integer, it needs to be non-negative, and otherwise
2917 // it needs to be suitable as a markup.
2918 if (scm_is_integer ($1)
2919 ? scm_is_true (scm_negative_p ($1))
2920 : !Text_interface::is_markup ($1))
2922 parser->parser_error (@1, _ ("bass number expected"));
2928 figured_bass_alteration:
2929 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2930 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2931 | '!' { $$ = scm_from_int (0); }
2936 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2937 $$ = bfr->unprotect ();
2940 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2941 $$ = bfr->self_scm ();
2943 if (scm_is_number ($1))
2944 bfr->set_property ("figure", $1);
2945 else if (Text_interface::is_markup ($1))
2946 bfr->set_property ("text", $1);
2952 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2954 | bass_figure figured_bass_alteration {
2955 Music *m = unsmob_music ($1);
2956 if (scm_to_double ($2)) {
2957 SCM salter = m->get_property ("alteration");
2958 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2959 m->set_property ("alteration",
2960 scm_sum (alter, $2));
2962 m->set_property ("alteration", scm_from_int (0));
2965 | bass_figure figured_bass_modification {
2966 Music *m = unsmob_music ($1);
2967 m->set_property ($2, SCM_BOOL_T);
2972 figured_bass_modification:
2974 $$ = ly_symbol2scm ("augmented");
2977 $$ = ly_symbol2scm ("no-continuation");
2980 $$ = ly_symbol2scm ("diminished");
2983 $$ = ly_symbol2scm ("augmented-slash");
2993 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3001 | figure_list br_bass_figure {
3002 $$ = scm_cons ($2, $1);
3007 FIGURE_OPEN figure_list FIGURE_CLOSE {
3008 $$ = scm_reverse_x ($2, SCM_EOL);
3014 /**/ { $$ = SCM_BOOL_F; }
3015 | REST { $$ = SCM_BOOL_T; }
3019 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3020 if (!parser->lexer_->is_note_state ())
3021 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3022 if (!SCM_UNBNDP ($2)
3024 || scm_is_number ($4)
3026 || scm_is_true ($6))
3029 if (scm_is_true ($6))
3030 n = MY_MAKE_MUSIC ("RestEvent", @$);
3032 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3034 n->set_property ("pitch", $1);
3035 if (SCM_UNBNDP ($5))
3036 n->set_property ("duration",
3037 parser->default_duration_.smobbed_copy ());
3039 n->set_property ("duration", $5);
3041 if (scm_is_number ($4))
3043 int q = scm_to_int ($4);
3044 n->set_property ("absolute-octave", scm_from_int (q-1));
3047 if (to_boolean ($3))
3048 n->set_property ("cautionary", SCM_BOOL_T);
3049 if (to_boolean ($2) || to_boolean ($3))
3050 n->set_property ("force-accidental", SCM_BOOL_T);
3052 $$ = n->unprotect ();
3055 | DRUM_PITCH optional_notemode_duration {
3056 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3057 n->set_property ("duration", $2);
3058 n->set_property ("drum-type", $1);
3060 $$ = n->unprotect ();
3062 | RESTNAME optional_notemode_duration {
3064 if (ly_scm2string ($1) == "s") {
3066 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3069 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3072 ev->set_property ("duration", $2);
3073 $$ = ev->unprotect ();
3077 // Can return a single pitch rather than a list.
3078 simple_chord_elements:
3080 if (!parser->lexer_->is_chord_state ())
3081 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3084 | figure_spec optional_notemode_duration {
3085 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3087 unsmob_music (scm_car (s))->set_property ("duration", $2);
3095 if (!parser->lexer_->is_lyric_state ())
3096 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3100 if (!parser->lexer_->is_lyric_state ())
3101 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3107 lyric_element_music:
3108 lyric_element optional_notemode_duration post_events {
3109 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3110 if (scm_is_pair ($3))
3111 unsmob_music ($$)->set_property
3112 ("articulations", scm_reverse_x ($3, SCM_EOL));
3116 // Can return a single pitch rather than a list.
3118 steno_tonic_pitch maybe_notemode_duration {
3119 if (SCM_UNBNDP ($2))
3122 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3124 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3125 SCM its = scm_reverse_x ($4, SCM_EOL);
3126 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3134 | chord_items chord_item {
3135 $$ = scm_cons ($2, $$);
3141 $$ = ly_symbol2scm ("chord-colon");
3144 $$ = ly_symbol2scm ("chord-caret");
3146 | CHORD_SLASH steno_tonic_pitch {
3147 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3149 | CHORD_BASS steno_tonic_pitch {
3150 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3159 $$ = scm_reverse_x ($1, SCM_EOL);
3167 step_number { $$ = scm_cons ($1, SCM_EOL); }
3168 | step_numbers '.' step_number {
3169 $$ = scm_cons ($3, $$);
3175 $$ = make_chord_step ($1, 0);
3178 $$ = make_chord_step ($1, SHARP_ALTERATION);
3180 | UNSIGNED CHORD_MINUS {
3181 $$ = make_chord_step ($1, FLAT_ALTERATION);
3189 | unsigned_number '-' unsigned_number {
3190 $$ = scm_cons ($1, $3);
3197 TODO: should deprecate in favor of Scheme?
3201 number_expression '+' number_term {
3202 $$ = scm_sum ($1, $3);
3204 | number_expression '-' number_term {
3205 $$ = scm_difference ($1, $3);
3214 | number_factor '*' number_factor {
3215 $$ = scm_product ($1, $3);
3217 | number_factor '/' number_factor {
3218 $$ = scm_divide ($1, $3);
3223 '-' number_factor { /* %prec UNARY_MINUS */
3224 $$ = scm_difference ($2, SCM_UNDEFINED);
3232 | REAL NUMBER_IDENTIFIER
3234 $$ = scm_product ($1, $2);
3241 | UNSIGNED NUMBER_IDENTIFIER {
3242 $$ = scm_product ($1, $2);
3250 if (!scm_is_integer ($1)
3251 || scm_is_true (scm_negative_p ($1)))
3253 parser->parser_error (@1, _("not an unsigned integer"));
3259 if (!scm_is_integer ($1)
3260 || scm_is_true (scm_negative_p ($1)))
3262 parser->parser_error (@1, _("not an unsigned integer"));
3269 { $$ = SCM_UNDEFINED; }
3272 if (SCM_UNBNDP ($1))
3280 // This precedence rule is rather weird. It triggers when '!' is
3281 // encountered after a pitch, and is used for deciding whether to save
3282 // this instead for a figure modification. This should not actually
3283 // occur in practice as pitches and figures are generated in different
3284 // modes. Using a greedy (%right) precedence makes sure that we don't
3285 // get stuck in a wrong interpretation.
3286 { $$ = SCM_UNDEFINED; } %prec ':'
3289 if (SCM_UNBNDP ($1))
3298 { parser->lexer_->push_markup_state (); }
3301 parser->lexer_->pop_state ();
3307 { parser->lexer_->push_markup_state (); }
3310 parser->lexer_->pop_state ();
3316 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3318 | markup_head_1_list simple_markup
3320 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3321 @2, $1, scm_list_1 ($2)));
3331 if (Text_interface::is_markup ($1))
3332 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3333 else if (Text_interface::is_markup_list ($1))
3334 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3336 parser->parser_error (@1, _ ("not a markup"));
3337 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3344 markup_composed_list {
3347 | markup_uncomposed_list
3350 markup_uncomposed_list:
3351 markup_braced_list {
3354 | markup_command_list {
3355 $$ = scm_list_1 ($1);
3357 | markup_scm MARKUPLIST_IDENTIFIER
3362 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3363 parser->lexer_->push_note_state (nn);
3364 } '{' score_body '}' {
3365 unsmob_score ($4)->origin ()->set_spot (@$);
3366 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3367 parser->lexer_->pop_state ();
3371 markup_composed_list:
3372 markup_head_1_list markup_uncomposed_list {
3373 $$ = MAKE_SYNTAX ("composed-markup-list",
3379 '{' markup_braced_list_body '}' {
3380 $$ = scm_reverse_x ($2, SCM_EOL);
3384 markup_braced_list_body:
3385 /* empty */ { $$ = SCM_EOL; }
3386 | markup_braced_list_body markup {
3387 $$ = scm_cons ($2, $1);
3389 | markup_braced_list_body markup_list {
3390 $$ = scm_reverse_x ($2, $1);
3394 markup_command_list:
3395 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3396 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3400 markup_command_basic_arguments:
3401 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3402 $$ = scm_cons ($3, $2);
3404 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3405 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3407 | EXPECT_NO_MORE_ARGS {
3412 markup_command_list_arguments:
3413 markup_command_basic_arguments { $$ = $1; }
3414 | EXPECT_MARKUP markup_command_list_arguments markup {
3415 $$ = scm_cons ($3, $2);
3420 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3421 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3426 markup_head_1_item {
3427 $$ = scm_list_1 ($1);
3429 | markup_head_1_list markup_head_1_item {
3430 $$ = scm_cons ($2, $1);
3436 $$ = make_simple_markup ($1);
3439 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3440 parser->lexer_->push_note_state (nn);
3441 } '{' score_body '}' {
3442 unsmob_score ($4)->origin ()->set_spot (@$);
3443 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3444 parser->lexer_->pop_state ();
3446 | MARKUP_FUNCTION markup_command_basic_arguments {
3447 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3449 | markup_scm MARKUP_IDENTIFIER
3456 markup_head_1_list simple_markup
3458 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3459 @2, $1, scm_list_1 ($2)));
3469 Lily_parser::set_yydebug (bool x)
3475 Lily_parser::do_yyparse ()
3477 SCM retval = SCM_UNDEFINED;
3478 yyparse (this, &retval);
3488 It is a little strange to have this function in this file, but
3489 otherwise, we have to import music classes into the lexer.
3493 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3495 if (unsmob_book (sid)) {
3496 Book *book = unsmob_book (sid)->clone ();
3497 *destination = book->self_scm ();
3500 return BOOK_IDENTIFIER;
3501 } else if (scm_is_number (sid)) {
3503 return NUMBER_IDENTIFIER;
3504 } else if (unsmob_context_def (sid)) {
3505 Context_def *def= unsmob_context_def (sid)->clone ();
3507 *destination = def->self_scm ();
3510 return CONTEXT_DEF_IDENTIFIER;
3511 } else if (unsmob_context_mod (sid)) {
3512 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3514 return CONTEXT_MOD_IDENTIFIER;
3515 } else if (Music *mus = unsmob_music (sid)) {
3516 mus = mus->clone ();
3517 *destination = mus->self_scm ();
3518 bool is_event = mus->is_mus_type ("post-event");
3520 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3521 } else if (unsmob_pitch (sid)) {
3522 *destination = unsmob_pitch (sid)->smobbed_copy ();
3523 return PITCH_IDENTIFIER;
3524 } else if (unsmob_duration (sid)) {
3525 *destination = unsmob_duration (sid)->smobbed_copy ();
3526 return DURATION_IDENTIFIER;
3527 } else if (unsmob_output_def (sid)) {
3528 Output_def *p = unsmob_output_def (sid);
3531 *destination = p->self_scm ();
3533 return OUTPUT_DEF_IDENTIFIER;
3534 } else if (unsmob_score (sid)) {
3535 *destination = unsmob_score (sid)->clone ()->unprotect ();
3536 return SCM_IDENTIFIER;
3543 get_next_unique_context_id ()
3545 return scm_from_locale_string ("$uniqueContextId");
3550 get_next_unique_lyrics_context_id ()
3552 static int new_context_count;
3554 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3555 return scm_from_locale_string (s);
3558 // check_scheme_arg checks one argument with a given predicate for use
3559 // in an argument list and throws a syntax error if it is unusable.
3560 // The argument is prepended to the argument list in any case. After
3561 // throwing a syntax error, the argument list is terminated with #f as
3562 // its last cdr in order to mark it as uncallable while not losing
3563 // track of its total length.
3565 // There are a few special considerations: if optional argument disp
3566 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3567 // instead of arg in a prospective error message. This is useful if
3568 // arg is not the actual argument but rather a transformation of it.
3570 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3571 // and an error message using disp is produced unconditionally.
3573 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3574 SCM arg, SCM args, SCM pred, SCM disp)
3576 if (SCM_UNBNDP (arg))
3577 args = scm_cons (disp, args);
3579 args = scm_cons (arg, args);
3580 if (scm_is_true (scm_call_1 (pred, arg)))
3583 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3584 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3585 SCM_UNBNDP (disp) ? arg : disp);
3586 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3590 SCM loc_on_music (Input loc, SCM arg)
3592 if (Music *m = unsmob_music (arg))
3596 return m->unprotect ();
3602 try_string_variants (SCM pred, SCM str)
3604 // a matching predicate is always ok
3605 if (scm_is_true (scm_call_1 (pred, str)))
3607 // a symbol may be interpreted as a list of symbols if it helps
3608 if (scm_is_symbol (str)) {
3609 str = scm_list_1 (str);
3610 if (scm_is_true (scm_call_1 (pred, str)))
3612 return SCM_UNDEFINED;
3615 // If this cannot be a string representation of a symbol list,
3618 if (!is_regular_identifier (str, true))
3619 return SCM_UNDEFINED;
3621 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3622 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3623 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3625 // Let's attempt the symbol list interpretation first.
3627 if (scm_is_true (scm_call_1 (pred, str)))
3630 // If there is just one symbol in the list, we might interpret
3631 // it as a single symbol
3633 if (scm_is_null (scm_cdr (str)))
3635 str = scm_car (str);
3636 if (scm_is_true (scm_call_1 (pred, str)))
3640 return SCM_UNDEFINED;
3644 is_regular_identifier (SCM id, bool multiple)
3646 if (!scm_is_string (id))
3649 string str = ly_scm2string (id);
3651 bool middle = false;
3653 for (string::iterator it=str.begin(); it != str.end (); it++)
3656 if ((c >= 'a' && c <= 'z')
3657 || (c >= 'A' && c <= 'Z')
3660 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3669 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3671 if (unsmob_music (simple))
3673 if (parser->lexer_->is_note_state ()) {
3674 if (scm_is_symbol (simple)) {
3675 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3676 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3677 n->set_property ("drum-type", simple);
3678 return n->unprotect ();
3680 if (unsmob_pitch (simple)) {
3681 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3682 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3683 n->set_property ("pitch", simple);
3684 return n->unprotect ();
3687 } else if (parser->lexer_->is_lyric_state ()) {
3688 if (Text_interface::is_markup (simple))
3689 return MAKE_SYNTAX ("lyric-event", loc, simple,
3690 parser->default_duration_.smobbed_copy ());
3691 } else if (parser->lexer_->is_chord_state ()) {
3692 if (unsmob_pitch (simple))
3696 make_chord_elements (loc, simple,
3697 parser->default_duration_.smobbed_copy (),
3704 make_music_with_input (SCM name, Input where)
3706 Music *m = make_music_by_name (name);
3707 m->set_spot (where);
3712 make_simple_markup (SCM a)
3718 make_duration (SCM d, int dots)
3720 int t = scm_to_int (d);
3721 if (t > 0 && (t & (t-1)) == 0)
3722 return Duration (intlog2 (t), dots).smobbed_copy ();
3724 return SCM_UNDEFINED;
3728 make_chord_step (SCM step_scm, Rational alter)
3730 int step = scm_to_int (step_scm);
3733 alter += FLAT_ALTERATION;
3737 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3738 return m.smobbed_copy ();
3743 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3745 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3746 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3747 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3749 unsmob_music (scm_car (s))->set_spot (loc);
3755 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3757 Lily_lexer *lex = parser->lexer_;
3761 int tok = lex->pop_extra_token ();
3764 lex->prepare_for_next_token ();
3765 return lex->yylex ();