1 /* -*- mode: c++; c-file-style: "linux"; indent-tabs-mode: t -*- */
3 This file is part of LilyPond, the GNU music typesetter.
5 Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 Jan Nieuwenhuizen <janneke@gnu.org>
8 LilyPond is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 /* Mode and indentation are at best a rough approximation based on TAB
23 * formatting (reasonable for compatibility with unspecific editor
24 * modes as Bison modes are hard to find) and need manual correction
25 * frequently. Without a reasonably dependable way of formatting a
26 * Bison file sensibly, there is little point in trying to fix the
27 * inconsistent state of indentation.
32 #define yyerror Lily_parser::parser_error
34 /* We use custom location type: Input objects */
37 #define YYLLOC_DEFAULT(Current,Rhs,N) \
38 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
40 #define YYPRINT(file, type, value) \
42 if (scm_is_eq (value, SCM_UNSPECIFIED)) \
44 SCM s = scm_call_2 (ly_lily_module_constant ("value->lily-string"), \
46 parser->self_scm ()); \
47 char *p = scm_to_locale_string (s); \
54 %parse-param {Lily_parser *parser}
55 %parse-param {SCM *retval}
56 %lex-param {Lily_parser *parser}
60 /* We use SCMs to do strings, because it saves us the trouble of
61 deleting them. Let's hope that a stack overflow doesn't trigger a move
62 of the parse stack onto the heap. */
68 /* The above precedences tackle the shift/reduce problem
71 \repeat .. \alternative
73 \repeat { \repeat .. \alternative }
77 \repeat { \repeat } \alternative
83 %right ':' UNSIGNED REAL E_UNSIGNED EVENT_IDENTIFIER EVENT_FUNCTION '^' '_'
84 HYPHEN EXTENDER DURATION_IDENTIFIER '!'
86 /* The above are needed for collecting tremoli and other items (that
87 could otherwise be interpreted as belonging to the next function
88 argument) greedily, and together with the next rule will serve to
89 join numbers and units greedily instead of allowing them into
90 separate function arguments
93 %nonassoc NUMBER_IDENTIFIER
105 %{ // -*-Fundamental-*-
110 * The rules for who is protecting what are very shady. Uniformise
113 * There are too many lexical modes?
124 #include "context-def.hh"
125 #include "context-mod.hh"
126 #include "dimensions.hh"
127 #include "file-path.hh"
129 #include "international.hh"
130 #include "lily-guile.hh"
131 #include "lily-lexer.hh"
132 #include "lily-parser.hh"
136 #include "output-def.hh"
137 #include "paper-book.hh"
138 #include "scm-hash.hh"
140 #include "text-interface.hh"
144 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
146 parser->parser_error (*i, s);
149 // The following are somewhat precarious constructs as they may change
150 // the value of the lookahead token. That implies that the lookahead
151 // token must not yet have made an impact on the state stack other
152 // than causing the reduction of the current rule, or switching the
153 // lookahead token while Bison is mulling it over will cause trouble.
155 #define MYBACKUP(Token, Value, Location) \
157 if (yychar != YYEMPTY) \
158 parser->lexer_->push_extra_token \
159 (yylloc, yychar, yylval); \
161 parser->lexer_->push_extra_token \
162 (Location, Token, Value); \
163 parser->lexer_->push_extra_token (Location, BACKUP); \
168 #define MYREPARSE(Location, Pred, Token, Value) \
170 if (yychar != YYEMPTY) \
171 parser->lexer_->push_extra_token \
172 (yylloc, yychar, yylval); \
173 parser->lexer_->push_extra_token \
174 (Location, Token, Value); \
175 parser->lexer_->push_extra_token \
176 (Location, REPARSE, Pred); \
185 #define MY_MAKE_MUSIC(x, spot) \
186 make_music_with_input (ly_symbol2scm (x), \
187 parser->lexer_->override_input (spot))
190 - Don't use lily module, create a new module instead.
191 - delay application of the function
193 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
194 scm_apply_0 (proc, args)
195 /* Syntactic Sugar. */
196 #define MAKE_SYNTAX(name, location, ...) \
197 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (parser->lexer_->override_input (location)), ##__VA_ARGS__, SCM_UNDEFINED))
198 #define START_MAKE_SYNTAX(name, ...) \
199 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
200 #define FINISH_MAKE_SYNTAX(start, location, ...) \
201 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (parser->lexer_->override_input (location)), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
203 SCM get_next_unique_context_id ();
204 SCM get_next_unique_lyrics_context_id ();
211 #define _(x) gettext (x)
215 static Music *make_music_with_input (SCM name, Input where);
216 SCM check_scheme_arg (Lily_parser *parser, Input loc,
217 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
218 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
219 SCM loc_on_music (Input loc, SCM arg);
220 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
221 SCM make_chord_step (SCM step, Rational alter);
222 SCM make_simple_markup (SCM a);
223 SCM make_duration (SCM t, int dots = 0);
224 bool is_regular_identifier (SCM id, bool multiple=false);
225 SCM try_string_variants (SCM pred, SCM str);
226 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
230 /* The third option is an alias that will be used to display the
231 syntax error. Bison CVS now correctly handles backslash escapes.
233 FIXME: Bison needs to translate some of these, eg, STRING.
237 /* Keyword tokens with plain escaped name. */
238 %token END_OF_FILE 0 "end of input"
239 %token ACCEPTS "\\accepts"
240 %token ADDLYRICS "\\addlyrics"
241 %token ALIAS "\\alias"
242 %token ALTERNATIVE "\\alternative"
244 %token BOOKPART "\\bookpart"
245 %token CHANGE "\\change"
246 %token CHORDMODE "\\chordmode"
247 %token CHORDS "\\chords"
248 %token CONSISTS "\\consists"
249 %token CONTEXT "\\context"
250 %token DEFAULT "\\default"
251 %token DEFAULTCHILD "\\defaultchild"
252 %token DENIES "\\denies"
253 %token DESCRIPTION "\\description"
254 %token DRUMMODE "\\drummode"
255 %token DRUMS "\\drums"
256 %token FIGUREMODE "\\figuremode"
257 %token FIGURES "\\figures"
258 %token HEADER "\\header"
259 %token INVALID "\\version-error"
260 %token LAYOUT "\\layout"
261 %token LYRICMODE "\\lyricmode"
262 %token LYRICS "\\lyrics"
263 %token LYRICSTO "\\lyricsto"
264 %token MARKUP "\\markup"
265 %token MARKUPLIST "\\markuplist"
268 %token NOTEMODE "\\notemode"
269 %token OVERRIDE "\\override"
270 %token PAPER "\\paper"
271 %token REMOVE "\\remove"
272 %token REPEAT "\\repeat"
274 %token REVERT "\\revert"
275 %token SCORE "\\score"
276 %token SCORELINES "\\score-lines"
277 %token SEQUENTIAL "\\sequential"
279 %token SIMULTANEOUS "\\simultaneous"
280 %token TEMPO "\\tempo"
282 %token UNSET "\\unset"
285 /* Keyword token exceptions. */
286 %token NEWCONTEXT "\\new"
289 /* Other string tokens. */
291 %token CHORD_BASS "/+"
292 %token CHORD_CARET "^"
293 %token CHORD_COLON ":"
294 %token CHORD_MINUS "-"
295 %token CHORD_SLASH "/"
296 %token ANGLE_OPEN "<"
297 %token ANGLE_CLOSE ">"
298 %token DOUBLE_ANGLE_OPEN "<<"
299 %token DOUBLE_ANGLE_CLOSE ">>"
300 %token E_BACKSLASH "\\"
301 %token E_EXCLAMATION "\\!"
306 If we give names, Bison complains.
308 %token FIGURE_CLOSE /* "\\>" */
309 %token FIGURE_OPEN /* "\\<" */
310 %token FIGURE_SPACE "_"
313 %token MULTI_MEASURE_REST
319 /* Artificial tokens, for more generic function syntax */
320 %token EXPECT_MARKUP "markup?"
321 %token EXPECT_SCM "scheme?"
322 %token BACKUP "(backed-up?)"
323 %token REPARSE "(reparsed?)"
324 %token EXPECT_MARKUP_LIST "markup-list?"
325 %token EXPECT_OPTIONAL "optional?"
326 /* After the last argument. */
327 %token EXPECT_NO_MORE_ARGS;
329 /* An artificial token for parsing embedded Lilypond */
330 %token EMBEDDED_LILY "#{"
332 %token BOOK_IDENTIFIER
333 %token CHORD_MODIFIER
334 %token CHORD_REPETITION
335 %token CONTEXT_DEF_IDENTIFIER
336 %token CONTEXT_MOD_IDENTIFIER
338 %token PITCH_IDENTIFIER
339 %token DURATION_IDENTIFIER
340 %token EVENT_IDENTIFIER
341 %token EVENT_FUNCTION
344 %token MARKUP_FUNCTION
345 %token MARKUP_LIST_FUNCTION
346 %token MARKUP_IDENTIFIER
347 %token MARKUPLIST_IDENTIFIER
348 %token MUSIC_FUNCTION
349 %token MUSIC_IDENTIFIER
350 %token NOTENAME_PITCH
351 %token NUMBER_IDENTIFIER
352 %token OUTPUT_DEF_IDENTIFIER
357 %token SCM_IDENTIFIER
361 %token TONICNAME_PITCH
365 /* We don't assign precedence to / and *, because we might need varied
366 prec levels in different prods */
375 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
376 parser->lexer_->push_note_state (nn);
377 } embedded_lilypond {
378 parser->lexer_->pop_state ();
383 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
384 | lilypond toplevel_expression {
386 | lilypond assignment {
389 parser->error_level_ = 1;
392 parser->error_level_ = 1;
399 parser->lexer_->add_scope (get_header (parser));
401 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
404 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
405 scm_call_2 (proc, parser->self_scm (), $1);
408 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
409 scm_call_2 (proc, parser->self_scm (), $1);
412 SCM proc = parser->lexer_->lookup_identifier
413 (unsmob_book($1)->paper_
414 ? "toplevel-book-handler"
415 : "toplevel-bookpart-handler");
416 scm_call_2 (proc, parser->self_scm (), $1);
419 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
420 scm_call_2 (proc, parser->self_scm (), $1);
423 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
424 scm_call_2 (proc, parser->self_scm (), $1);
427 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
428 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
431 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
432 scm_call_2 (proc, parser->self_scm (), $1);
435 // Evaluate and ignore #xxx, as opposed to \xxx
436 parser->lexer_->eval_scm_token ($1, @1);
438 | embedded_scm_active
440 SCM out = SCM_UNDEFINED;
441 if (Text_interface::is_markup ($1))
442 out = scm_list_1 ($1);
443 else if (Text_interface::is_markup_list ($1))
445 if (scm_is_pair (out))
447 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
448 scm_call_2 (proc, parser->self_scm (), out);
449 } else if (unsmob_score ($1))
451 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
452 scm_call_2 (proc, parser->self_scm (), $1);
453 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
454 parser->parser_error (@1, _("bad expression type"));
458 Output_def * od = unsmob_output_def ($1);
460 if (od->c_variable ("is-paper") == SCM_BOOL_T)
461 id = ly_symbol2scm ("$defaultpaper");
462 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
463 id = ly_symbol2scm ("$defaultmidi");
464 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
465 id = ly_symbol2scm ("$defaultlayout");
467 parser->lexer_->set_identifier (id, $1);
474 $$ = parser->lexer_->eval_scm_token ($1, @1);
484 embedded_scm_bare_arg:
488 $$ = parser->lexer_->eval_scm_token ($1, @1);
492 | context_modification
494 | context_def_spec_block
500 /* The generic version may end in music, or not */
507 /* embedded_scm_arg is _not_ casting pitches to music by default, this
508 * has to be done by the function itself. Note that this may cause
509 * the results of scm_function_call or embedded_scm_bare_arg to be
510 * turned into music from pitches as well. Note that this creates a
511 * distinctly awkward situation for calculated drum pitches. Those
512 * are at the current point of time rejected as music constituents as
513 * they can't be distinguished from "proper" symbols.
517 embedded_scm_bare_arg
523 SCM_FUNCTION function_arglist {
524 $$ = MAKE_SYNTAX ("music-function", @$,
529 embedded_lilypond_number:
530 '-' embedded_lilypond_number
532 $$ = scm_difference ($2, SCM_UNDEFINED);
535 | UNSIGNED NUMBER_IDENTIFIER
537 $$ = scm_product ($1, $2);
544 // FIXME: @$ does not contain a useful source location
545 // for empty rules, and the only token in the whole
546 // production, EMBEDDED_LILY, is synthetic and also
547 // contains no source location.
548 $$ = MAKE_SYNTAX ("void-music", @$);
550 | identifier_init_nonumber
551 | embedded_lilypond_number
552 | post_event post_events
554 $$ = scm_reverse_x ($2, SCM_EOL);
555 if (Music *m = unsmob_music ($1))
557 if (m->is_mus_type ("post-event-wrapper"))
559 (scm_list_2 (m->get_property ("elements"),
562 $$ = scm_cons ($1, $$);
565 && scm_is_null (scm_cdr ($$)))
569 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
570 m->set_property ("elements", $$);
571 $$ = m->unprotect ();
574 | multiplied_duration
575 | music_embedded music_embedded music_list {
576 $3 = scm_reverse_x ($3, SCM_EOL);
577 if (unsmob_music ($2))
578 $3 = scm_cons ($2, $3);
579 if (unsmob_music ($1))
580 $3 = scm_cons ($1, $3);
581 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
584 parser->error_level_ = 1;
585 $$ = SCM_UNSPECIFIED;
587 | INVALID embedded_lilypond {
588 parser->error_level_ = 1;
594 lilypond_header_body:
595 /* empty */ { $$ = SCM_UNSPECIFIED; }
596 | lilypond_header_body assignment {
599 | lilypond_header_body embedded_scm {
605 HEADER '{' lilypond_header_body '}' {
606 $$ = parser->lexer_->remove_scope ();
618 assignment_id '=' identifier_init {
619 parser->lexer_->set_identifier ($1, $3);
620 $$ = SCM_UNSPECIFIED;
622 | assignment_id property_path '=' identifier_init {
623 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
624 parser->lexer_->set_identifier (path, $4);
625 $$ = SCM_UNSPECIFIED;
627 | assignment_id '.' property_path '=' identifier_init {
628 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
629 parser->lexer_->set_identifier (path, $5);
630 $$ = SCM_UNSPECIFIED;
636 identifier_init_nonumber
638 | post_event_nofinger post_events
640 $$ = scm_reverse_x ($2, SCM_EOL);
641 if (Music *m = unsmob_music ($1))
643 if (m->is_mus_type ("post-event-wrapper"))
645 (scm_list_2 (m->get_property ("elements"),
648 $$ = scm_cons ($1, $$);
651 && scm_is_null (scm_cdr ($$)))
655 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
656 m->set_property ("elements", $$);
657 $$ = m->unprotect ();
662 identifier_init_nonumber:
667 | context_def_spec_block
674 | context_modification
677 context_def_spec_block:
678 CONTEXT '{' context_def_spec_body '}'
681 unsmob_context_def ($$)->origin ()->set_spot (@$);
689 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
690 parser->lexer_->push_note_state (nn);
694 parser->lexer_->pop_state ();
699 context_mod_embedded:
702 if (unsmob_music ($1)) {
703 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
704 $1 = scm_call_2 (proc, parser->self_scm (), $1);
706 if (unsmob_context_mod ($1))
709 parser->parser_error (@1, _ ("not a context mod"));
710 $$ = Context_mod ().smobbed_copy ();
716 context_def_spec_body:
718 $$ = Context_def::make_scm ();
720 | CONTEXT_DEF_IDENTIFIER {
723 | context_def_spec_body context_mod {
724 if (!SCM_UNBNDP ($2))
725 unsmob_context_def ($$)->add_context_mod ($2);
727 | context_def_spec_body context_modification {
728 Context_def *td = unsmob_context_def ($$);
729 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
730 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
731 td->add_context_mod (scm_car (m));
734 | context_def_spec_body context_mod_embedded {
735 Context_def *td = unsmob_context_def ($$);
736 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
737 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
738 td->add_context_mod (scm_car (m));
746 BOOK '{' book_body '}' {
748 unsmob_book ($$)->origin ()->set_spot (@$);
750 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
755 * Use 'handlers' like for toplevel-* stuff?
756 * grok \layout and \midi? */
759 Book *book = new Book;
760 init_papers (parser);
761 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
762 book->paper_->unprotect ();
763 push_paper (parser, book->paper_);
764 book->header_ = get_header (parser);
765 $$ = book->unprotect ();
766 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
769 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
771 | book_body paper_block {
772 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
773 set_paper (parser, unsmob_output_def ($2));
775 | book_body bookpart_block {
776 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
777 scm_call_2 (proc, $1, $2);
779 | book_body score_block {
780 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
781 scm_call_2 (proc, $1, $2);
783 | book_body composite_music {
784 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
785 scm_call_3 (proc, parser->self_scm (), $1, $2);
787 | book_body full_markup {
788 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
789 scm_call_2 (proc, $1, scm_list_1 ($2));
791 | book_body full_markup_list {
792 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
793 scm_call_2 (proc, $1, $2);
795 | book_body SCM_TOKEN {
796 // Evaluate and ignore #xxx, as opposed to \xxx
797 parser->lexer_->eval_scm_token ($2, @2);
799 | book_body embedded_scm_active
801 SCM out = SCM_UNDEFINED;
802 if (Text_interface::is_markup ($2))
803 out = scm_list_1 ($2);
804 else if (Text_interface::is_markup_list ($2))
806 if (scm_is_pair (out))
808 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
809 scm_call_2 (proc, $1, out);
810 } else if (unsmob_score ($2))
812 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
813 scm_call_2 (proc, $1, $2);
814 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
815 parser->parser_error (@2, _("bad expression type"));
819 parser->lexer_->add_scope (unsmob_book ($1)->header_);
822 Book *book = unsmob_book ($1);
824 book->scores_ = SCM_EOL;
825 book->bookparts_ = SCM_EOL;
830 BOOKPART '{' bookpart_body '}' {
832 unsmob_book ($$)->origin ()->set_spot (@$);
833 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
839 Book *book = new Book;
840 $$ = book->unprotect ();
841 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
844 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
846 | bookpart_body paper_block {
847 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
849 | bookpart_body score_block {
850 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
851 scm_call_2 (proc, $1, $2);
853 | bookpart_body composite_music {
854 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
855 scm_call_3 (proc, parser->self_scm (), $1, $2);
857 | bookpart_body full_markup {
858 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
859 scm_call_2 (proc, $1, scm_list_1 ($2));
861 | bookpart_body full_markup_list {
862 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
863 scm_call_2 (proc, $1, $2);
865 | bookpart_body SCM_TOKEN {
866 // Evaluate and ignore #xxx, as opposed to \xxx
867 parser->lexer_->eval_scm_token ($2, @2);
869 | bookpart_body embedded_scm_active
871 SCM out = SCM_UNDEFINED;
872 if (Text_interface::is_markup ($2))
873 out = scm_list_1 ($2);
874 else if (Text_interface::is_markup_list ($2))
876 if (scm_is_pair (out))
878 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
879 scm_call_2 (proc, $1, out);
880 } else if (unsmob_score ($2))
882 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
883 scm_call_2 (proc, $1, $2);
884 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
885 parser->parser_error (@2, _("bad expression type"));
889 Book *book = unsmob_book ($1);
890 if (!ly_is_module (book->header_))
891 book->header_ = ly_make_module (false);
892 parser->lexer_->add_scope (book->header_);
894 | bookpart_body error {
895 Book *book = unsmob_book ($1);
897 book->scores_ = SCM_EOL;
902 SCORE '{' score_body '}' {
903 unsmob_score ($3)->origin ()->set_spot (@$);
915 if (!scm_is_pair ($1)
916 || !ly_is_module (scm_car ($1)))
917 $1 = scm_cons (ly_make_module (false), $1);
918 parser->lexer_->add_scope (scm_car ($1));
923 | score_headers output_def
925 Output_def *od = unsmob_output_def ($2);
926 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
928 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
933 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
934 scm_set_cdr_x ($1, scm_cons ($2, scm_cdr ($1)));
936 $$ = scm_cons ($2, $1);
944 score_headers music {
945 SCM scorify = ly_lily_module_constant ("scorify-music");
946 $$ = scm_call_2 (scorify, $2, parser->self_scm ());
948 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
950 unsmob_score ($$)->set_header (scm_car ($1));
953 for (SCM p = scm_reverse_x ($1, SCM_EOL);
954 scm_is_pair (p); p = scm_cdr (p))
957 add_output_def (unsmob_output_def (scm_car (p)));
960 | embedded_scm_active {
961 if (!unsmob_score ($1))
963 $$ = (new Score)->unprotect ();
964 parser->parser_error (@1, _("score expected"));
969 Score *score = unsmob_score ($1);
970 if (!ly_is_module (score->get_header ()))
971 score->set_header (ly_make_module (false));
972 parser->lexer_->add_scope (score->get_header ());
974 | score_body output_def {
975 Output_def *od = unsmob_output_def ($2);
976 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
978 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
983 unsmob_score ($1)->add_output_def (od);
987 unsmob_score ($$)->error_found_ = true;
998 Output_def *od = unsmob_output_def ($1);
1000 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1002 parser->parser_error (@1, _ ("need \\paper for paper block"));
1003 $$ = get_paper (parser)->unprotect ();
1010 output_def_body '}' {
1011 if (scm_is_pair ($1))
1014 parser->lexer_->remove_scope ();
1015 parser->lexer_->pop_state ();
1021 Output_def *p = get_paper (parser);
1022 p->input_origin_ = @$;
1023 parser->lexer_->add_scope (p->scope_);
1024 $$ = p->unprotect ();
1027 Output_def *p = get_midi (parser);
1028 $$ = p->unprotect ();
1029 parser->lexer_->add_scope (p->scope_);
1032 Output_def *p = get_layout (parser);
1034 parser->lexer_->add_scope (p->scope_);
1035 $$ = p->unprotect ();
1039 output_def_head_with_mode_switch:
1041 parser->lexer_->push_initial_state ();
1046 // We need this weird nonterminal because both music as well as a
1047 // context definition can start with \context and the difference is
1048 // only apparent after looking at the next token. If it is '{', there
1049 // is still time to escape from notes mode.
1051 music_or_context_def:
1053 | context_def_spec_block
1057 output_def_head_with_mode_switch '{' {
1058 unsmob_output_def ($1)->input_origin_.set_spot (@$);
1059 // This is a stupid trick to mark the beginning of the
1060 // body for deciding whether to allow
1061 // embedded_scm_active to have an output definition
1062 $$ = scm_list_1 ($1);
1064 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1065 Output_def *o = unsmob_output_def ($3);
1066 o->input_origin_.set_spot (@$);
1067 $$ = o->self_scm ();
1068 parser->lexer_->remove_scope ();
1069 parser->lexer_->add_scope (o->scope_);
1071 | output_def_body assignment {
1072 if (scm_is_pair ($1))
1075 | output_def_body embedded_scm_active
1077 // We don't switch into note mode for Scheme functions
1078 // here. Does not seem warranted/required in output
1080 if (scm_is_pair ($1))
1082 Output_def *o = unsmob_output_def ($2);
1084 o->input_origin_.set_spot (@$);
1085 $1 = o->self_scm ();
1086 parser->lexer_->remove_scope ();
1087 parser->lexer_->add_scope (o->scope_);
1088 $2 = SCM_UNSPECIFIED;
1092 if (unsmob_context_def ($2))
1093 assign_context_def (unsmob_output_def ($1), $2);
1094 // Seems unlikely, but let's be complete:
1095 else if (unsmob_music ($2))
1097 SCM proc = parser->lexer_->lookup_identifier
1098 ("output-def-music-handler");
1099 scm_call_3 (proc, parser->self_scm (),
1101 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1102 parser->parser_error (@2, _("bad expression type"));
1105 | output_def_body SCM_TOKEN {
1106 if (scm_is_pair ($1))
1108 // Evaluate and ignore #xxx, as opposed to \xxx
1109 parser->lexer_->eval_scm_token ($2, @2);
1113 if (scm_is_pair ($1))
1115 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1116 parser->lexer_->push_note_state (nn);
1117 } music_or_context_def
1119 parser->lexer_->pop_state ();
1120 if (unsmob_context_def ($3))
1121 assign_context_def (unsmob_output_def ($1), $3);
1124 SCM proc = parser->lexer_->lookup_identifier
1125 ("output-def-music-handler");
1126 scm_call_3 (proc, parser->self_scm (),
1131 | output_def_body error {
1137 TEMPO steno_duration '=' tempo_range {
1138 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1140 | TEMPO scalar steno_duration '=' tempo_range {
1141 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1144 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1149 The representation of a list is reversed to have efficient append. */
1155 | music_list music_embedded {
1156 if (unsmob_music ($2))
1157 $$ = scm_cons ($2, $1);
1159 | music_list error {
1160 Music *m = MY_MAKE_MUSIC("Music", @$);
1162 m->set_property ("error-found", SCM_BOOL_T);
1163 $$ = scm_cons (m->self_scm (), $1);
1164 m->unprotect (); /* UGH */
1171 $$ = scm_reverse_x ($2, SCM_EOL);
1176 | lyric_element_music
1179 $$ = make_music_from_simple (parser, @1, $1);
1180 if (!unsmob_music ($$))
1182 parser->parser_error (@1, _ ("music expected"));
1183 $$ = MAKE_SYNTAX ("void-music", @$);
1191 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1192 parser->parser_error (@1, _ ("unexpected post-event"));
1193 $$ = SCM_UNSPECIFIED;
1196 | music_embedded_backup
1200 | music_embedded_backup BACKUP lyric_element_music
1204 | multiplied_duration post_events
1206 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1208 parser->default_duration_ = *unsmob_duration ($1);
1209 n->set_property ("duration", $1);
1211 if (scm_is_pair ($2))
1212 n->set_property ("articulations",
1213 scm_reverse_x ($2, SCM_EOL));
1214 $$ = n->unprotect ();
1218 music_embedded_backup:
1221 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1223 else if (Music *m = unsmob_music ($1)) {
1224 if (m->is_mus_type ("post-event")) {
1225 parser->parser_error
1226 (@1, _ ("unexpected post-event"));
1227 $$ = SCM_UNSPECIFIED;
1230 } else if (parser->lexer_->is_lyric_state ()
1231 && Text_interface::is_markup ($1))
1232 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1234 @$.warning (_ ("Ignoring non-music expression"));
1240 // music_assign does not need to contain lyrics: there are no
1241 // assignments in lyricmode.
1244 | composite_music %prec COMPOSITE
1248 REPEAT simple_string unsigned_number music
1250 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1252 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1254 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1259 SEQUENTIAL braced_music_list {
1260 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1262 | braced_music_list {
1263 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1268 SIMULTANEOUS braced_music_list {
1269 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1271 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1272 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1278 | music_property_def
1282 context_modification:
1285 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1286 parser->lexer_->push_note_state (nn);
1287 } '{' context_mod_list '}'
1289 parser->lexer_->pop_state ();
1292 | WITH CONTEXT_MOD_IDENTIFIER
1296 | CONTEXT_MOD_IDENTIFIER
1300 | WITH context_modification_arg
1302 if (unsmob_music ($2)) {
1303 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1304 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1306 if (unsmob_context_mod ($2))
1309 parser->parser_error (@2, _ ("not a context mod"));
1310 $$ = Context_mod ().smobbed_copy ();
1315 context_modification_arg:
1320 optional_context_mod:
1324 | context_modification
1332 $$ = Context_mod ().smobbed_copy ();
1334 | context_mod_list context_mod {
1335 if (!SCM_UNBNDP ($2))
1336 unsmob_context_mod ($1)->add_context_mod ($2);
1338 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1339 Context_mod *md = unsmob_context_mod ($2);
1341 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1343 | context_mod_list context_mod_embedded {
1344 unsmob_context_mod ($1)->add_context_mods
1345 (unsmob_context_mod ($2)->get_mods ());
1357 | grouped_music_list
1361 simultaneous_music { $$ = $1; }
1362 | sequential_music { $$ = $1; }
1365 /* Function argument lists are arguably the most complex part in the
1366 * parser. They are pretty tricky to understand because of the way
1367 * they are processed, and because of optional arguments that can be
1368 * omitted. When there are several optional arguments in a row,
1369 * omitting one automatically omits all following arguments. Optional
1370 * arguments can only be omitted when either
1372 * a) the omission is explicitly started with \default
1373 * b) the omission is implicitly started by an argument not matching
1374 * its predicate, and there is a mandatory argument later that can
1375 * "catch" the argument that does not fit.
1377 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1378 * (corresponding to mandatory arguments and having a predicate
1379 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1380 * the semantic value of the EXPECT_OPTIONAL token is the default to
1381 * use when the optional argument is omitted, and EXPECT_SCM again has
1382 * the argument predicate as semantic value) in reverse order to the
1383 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1384 * processed inside-out while actual tokens are consumed.
1386 * This means that the argument list tokens determine the actions
1387 * taken as they arrive. The structure of the argument list is known
1388 * to the parser and stored in its parse stack when the first argument
1389 * is being parsed. What the parser does not know is which predicates
1390 * will match and whether or not \default will be appearing in the
1391 * argument list, and where.
1393 * Sequences of 0 or more optional arguments are scanned using either
1394 * function_arglist_backup or function_arglist_nonbackup. The first
1395 * is used when optional arguments are followed by at least one
1396 * mandatory argument: in that case optional arguments may be skipped
1397 * by either a false predicate (in which case the expression will be
1398 * pushed back as one or more tokens, preceded by a BACKUP token) or
1399 * by using \default.
1401 * If optional arguments are at the end of the argument list, they are
1402 * instead scanned using function_arglist_nonbackup: here the only
1403 * manner to enter into skipping of optional arguments is the use of
1406 * The argument list of a normal function call is parsed using
1407 * function_arglist. The part of an argument list before a mandatory
1408 * argument is parsed using function_arglist_optional.
1410 * The difference is that leading optional arguments are scanned using
1411 * function_arglist_nonbackup and function_arglist_backup,
1414 * Most other details are obvious in the rules themselves.
1420 | SYMBOL_LIST '.' symbol_list_rev
1422 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1428 | symbol_list_rev '.' symbol_list_part
1430 $$ = scm_append_x (scm_list_2 ($3, $1));
1434 // symbol_list_part delivers elements in reverse copy.
1439 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1440 $$ = try_string_variants (sym_l_p, $1);
1441 if (SCM_UNBNDP ($$)) {
1442 parser->parser_error (@1, _("not a symbol"));
1445 $$ = scm_reverse ($$);
1450 symbol_list_element:
1456 function_arglist_nonbackup:
1457 function_arglist_common
1458 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1460 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1462 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1464 SCM n = scm_difference ($5, SCM_UNDEFINED);
1465 if (scm_is_true (scm_call_1 ($2, n)))
1466 $$ = scm_cons (n, $3);
1468 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1469 t->set_property ("digit", $5);
1470 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1475 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1477 $$ = check_scheme_arg (parser, @4,
1478 scm_difference ($5, SCM_UNDEFINED),
1481 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1483 $$ = check_scheme_arg (parser, @4,
1484 scm_difference ($5, SCM_UNDEFINED),
1487 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1489 if (scm_is_true (scm_call_1 ($2, $4)))
1490 $$ = scm_cons ($4, $3);
1492 $$ = check_scheme_arg (parser, @4,
1493 make_music_from_simple
1497 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1499 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1501 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1503 if (scm_is_true (scm_call_1 ($2, $3)))
1504 $$ = scm_cons ($3, $1);
1506 $$ = check_scheme_arg (parser, @3,
1507 make_music_from_simple
1511 | function_arglist_nonbackup_reparse REPARSE duration_length
1513 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1515 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1517 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1519 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1521 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1523 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1525 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1527 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1529 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1533 function_arglist_nonbackup_reparse:
1534 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1537 SCM res = try_string_variants ($2, $4);
1538 if (!SCM_UNBNDP (res))
1539 if (scm_is_pair (res))
1540 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1542 MYREPARSE (@4, $2, SCM_ARG, res);
1543 else if (scm_is_true
1545 ($2, make_music_from_simple
1547 MYREPARSE (@4, $2, STRING, $4);
1549 MYREPARSE (@4, $2, SCM_ARG, $4);
1551 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1556 ($2, make_music_from_simple
1558 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1560 MYREPARSE (@4, $2, SCM_ARG, $4);
1562 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1567 ($2, make_music_from_simple
1569 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1571 MYREPARSE (@4, $2, SCM_ARG, $4);
1573 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1576 SCM res = try_string_variants ($2, $4);
1577 if (!SCM_UNBNDP (res))
1578 if (scm_is_pair (res))
1579 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1581 MYREPARSE (@4, $2, SCM_ARG, res);
1582 else if (scm_is_true
1584 ($2, make_music_from_simple
1586 MYREPARSE (@4, $2, STRING, $4);
1588 MYREPARSE (@4, $2, SCM_ARG, $4);
1590 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1593 if (scm_is_true (scm_call_1 ($2, $4)))
1594 MYREPARSE (@4, $2, SCM_ARG, $4);
1595 else if (scm_is_true
1597 ($2, make_music_from_simple
1599 MYREPARSE (@4, $2, STRING, $4);
1601 MYREPARSE (@4, $2, SCM_ARG, $4);
1603 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1606 if (scm_is_true (scm_call_1 ($2, $4)))
1607 MYREPARSE (@4, $2, REAL, $4);
1609 SCM d = make_duration ($4);
1610 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1611 MYREPARSE (@4, $2, REAL, $4); // trigger error
1613 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1616 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1618 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1623 // function_arglist_backup can't occur at the end of an argument
1625 function_arglist_backup:
1626 function_arglist_common
1627 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1629 if (scm_is_true (scm_call_1 ($2, $4)))
1630 $$ = scm_cons ($4, $3);
1632 $$ = make_music_from_simple (parser, @4, $4);
1633 if (scm_is_true (scm_call_1 ($2, $$)))
1634 $$ = scm_cons ($$, $3);
1637 $$ = scm_cons (loc_on_music (@3, $1), $3);
1638 MYBACKUP (SCM_ARG, $4, @4);
1642 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1644 if (scm_is_true (scm_call_1 ($2, $4)))
1646 $$ = scm_cons ($4, $3);
1648 $$ = scm_cons (loc_on_music (@3, $1), $3);
1649 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1652 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1656 ($2, make_music_from_simple
1660 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1661 } else if (scm_is_true (scm_call_1 ($2, $4)))
1662 $$ = scm_cons ($4, $3);
1664 $$ = scm_cons (loc_on_music (@3, $1), $3);
1665 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1668 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1672 ($2, make_music_from_simple
1676 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1677 } else if (scm_is_true (scm_call_1 ($2, $4)))
1678 $$ = scm_cons ($4, $3);
1680 $$ = scm_cons (loc_on_music (@3, $1), $3);
1681 MYBACKUP (TONICNAME_PITCH, $4, @4);
1684 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1686 if (scm_is_true (scm_call_1 ($2, $4)))
1687 $$ = scm_cons ($4, $3);
1689 $$ = scm_cons (loc_on_music (@3, $1), $3);
1690 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1693 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1695 if (scm_is_true (scm_call_1 ($2, $4)))
1697 MYREPARSE (@4, $2, REAL, $4);
1700 SCM d = make_duration ($4);
1701 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1703 $$ = scm_cons (loc_on_music (@3, $1), $3);
1704 MYBACKUP (UNSIGNED, $4, @4);
1706 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1711 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1713 if (scm_is_true (scm_call_1 ($2, $4)))
1716 MYREPARSE (@4, $2, REAL, $4);
1718 $$ = scm_cons (loc_on_music (@3, $1), $3);
1719 MYBACKUP (REAL, $4, @4);
1722 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
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 (NUMBER_IDENTIFIER, $4, @4);
1732 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1734 SCM n = scm_difference ($5, SCM_UNDEFINED);
1735 if (scm_is_true (scm_call_1 ($2, n))) {
1737 MYREPARSE (@5, $2, REAL, n);
1739 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1740 t->set_property ("digit", $5);
1741 $$ = t->unprotect ();
1742 if (scm_is_true (scm_call_1 ($2, $$)))
1743 $$ = scm_cons ($$, $3);
1745 $$ = scm_cons (loc_on_music (@3, $1), $3);
1746 MYBACKUP (UNSIGNED, $5, @5);
1747 parser->lexer_->push_extra_token (@4, '-');
1752 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1754 SCM n = scm_difference ($5, SCM_UNDEFINED);
1755 if (scm_is_true (scm_call_1 ($2, n))) {
1756 MYREPARSE (@5, $2, REAL, n);
1759 $$ = scm_cons (loc_on_music (@3, $1), $3);
1760 MYBACKUP (REAL, n, @5);
1763 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1765 SCM n = scm_difference ($5, SCM_UNDEFINED);
1766 if (scm_is_true (scm_call_1 ($2, n))) {
1767 $$ = scm_cons (n, $3);
1769 $$ = scm_cons (loc_on_music (@3, $1), $3);
1770 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1773 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1775 if (scm_is_true (scm_call_1 ($2, $4)))
1777 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1780 $$ = scm_cons (loc_on_music (@3, $1), $3);
1781 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1784 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1786 SCM res = try_string_variants ($2, $4);
1787 if (!SCM_UNBNDP (res))
1788 if (scm_is_pair (res)) {
1790 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1793 $$ = scm_cons (res, $3);
1795 $$ = scm_cons (loc_on_music (@3, $1), $3);
1796 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1799 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1801 SCM res = try_string_variants ($2, $4);
1802 if (!SCM_UNBNDP (res))
1803 if (scm_is_pair (res)) {
1805 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1808 $$ = scm_cons (res, $3);
1810 $$ = scm_cons (loc_on_music (@3, $1), $3);
1811 MYBACKUP (STRING, $4, @4);
1814 | function_arglist_backup REPARSE pitch_or_music
1816 if (scm_is_true (scm_call_1 ($2, $3)))
1817 $$ = scm_cons ($3, $1);
1819 $$ = check_scheme_arg (parser, @3,
1820 make_music_from_simple
1824 | function_arglist_backup REPARSE bare_number_common
1826 $$ = check_scheme_arg (parser, @3,
1829 | function_arglist_backup REPARSE duration_length
1831 $$ = check_scheme_arg (parser, @3,
1834 | function_arglist_backup REPARSE symbol_list_arg
1836 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1841 function_arglist_nonbackup
1842 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1844 $$ = scm_cons (loc_on_music (@4, $1), $3);
1848 function_arglist_skip_nonbackup:
1849 function_arglist_nonbackup
1850 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1852 $$ = scm_cons (loc_on_music (@3, $1), $3);
1856 function_arglist_common:
1857 EXPECT_NO_MORE_ARGS {
1860 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1862 if (scm_is_true (scm_call_1 ($1, $3)))
1863 $$ = scm_cons ($3, $2);
1865 $$ = check_scheme_arg (parser, @3,
1866 make_music_from_simple
1870 | EXPECT_SCM function_arglist_optional bare_number_common
1872 $$ = check_scheme_arg (parser, @3,
1875 | EXPECT_SCM function_arglist_optional post_event_nofinger
1877 $$ = check_scheme_arg (parser, @3,
1880 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1882 SCM n = scm_difference ($4, SCM_UNDEFINED);
1883 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1885 | function_arglist_common_reparse REPARSE SCM_ARG
1887 $$ = check_scheme_arg (parser, @3,
1890 | function_arglist_common_reparse REPARSE lyric_element_music
1892 $$ = check_scheme_arg (parser, @3,
1895 | function_arglist_common_reparse REPARSE pitch_or_music
1897 if (scm_is_true (scm_call_1 ($2, $3)))
1898 $$ = scm_cons ($3, $1);
1900 $$ = check_scheme_arg (parser, @3,
1901 make_music_from_simple
1905 | function_arglist_common_reparse REPARSE bare_number_common
1907 $$ = check_scheme_arg (parser, @3,
1910 | function_arglist_common_reparse REPARSE duration_length
1912 $$ = check_scheme_arg (parser, @3,
1915 | function_arglist_common_reparse REPARSE symbol_list_arg
1917 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1921 function_arglist_common_reparse:
1922 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1925 SCM res = try_string_variants ($1, $3);
1926 if (!SCM_UNBNDP (res))
1927 if (scm_is_pair (res))
1928 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1930 MYREPARSE (@3, $1, SCM_ARG, res);
1931 else if (scm_is_true
1933 ($1, make_music_from_simple (parser, @3, $3))))
1934 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1936 // This is going to flag a syntax error, we
1937 // know the predicate to be false.
1938 MYREPARSE (@3, $1, SCM_ARG, $3);
1940 | EXPECT_SCM function_arglist_optional pitch
1945 ($1, make_music_from_simple
1947 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
1949 MYREPARSE (@3, $1, SCM_ARG, $3);
1951 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
1956 ($1, make_music_from_simple
1958 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
1960 MYREPARSE (@3, $1, SCM_ARG, $3);
1962 | EXPECT_SCM function_arglist_optional STRING
1965 SCM res = try_string_variants ($1, $3);
1966 if (!SCM_UNBNDP (res))
1967 if (scm_is_pair (res))
1968 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1970 MYREPARSE (@3, $1, SCM_ARG, res);
1971 else if (scm_is_true
1973 ($1, make_music_from_simple (parser, @3, $3))))
1974 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1976 // This is going to flag a syntax error, we
1977 // know the predicate to be false.
1978 MYREPARSE (@3, $1, SCM_ARG, $3);
1980 | EXPECT_SCM function_arglist_optional full_markup
1983 if (scm_is_true (scm_call_1 ($1, $3)))
1984 MYREPARSE (@3, $1, SCM_ARG, $3);
1985 else if (scm_is_true
1987 ($1, make_music_from_simple (parser, @3, $3))))
1988 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1990 // This is going to flag a syntax error, we
1991 // know the predicate to be false.
1992 MYREPARSE (@3, $1, SCM_ARG, $3);
1994 | EXPECT_SCM function_arglist_optional UNSIGNED
1997 if (scm_is_true (scm_call_1 ($1, $3)))
1998 MYREPARSE (@3, $1, REAL, $3);
2000 SCM d = make_duration ($3);
2001 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
2002 MYREPARSE (@3, $1, REAL, $3);
2004 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2007 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2010 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2012 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2015 SCM n = scm_difference ($4, SCM_UNDEFINED);
2016 if (scm_is_true (scm_call_1 ($1, n)))
2017 MYREPARSE (@4, $1, REAL, n);
2019 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2020 t->set_property ("digit", $4);
2021 SCM m = t->unprotect ();
2022 if (scm_is_true (scm_call_1 ($1, m)))
2023 MYREPARSE (@4, $1, SCM_ARG, m);
2025 MYREPARSE (@4, $1, SCM_ARG, $4);
2029 | EXPECT_SCM function_arglist_optional '-' REAL
2032 SCM n = scm_difference ($4, SCM_UNDEFINED);
2033 MYREPARSE (@4, $1, REAL, n);
2037 function_arglist_optional:
2038 function_arglist_backup
2039 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2041 $$ = scm_cons (loc_on_music (@4, $1), $3);
2043 | function_arglist_skip_backup BACKUP
2046 function_arglist_skip_backup:
2047 function_arglist_backup
2048 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2050 $$ = scm_cons (loc_on_music (@3, $1), $3);
2054 music_function_call:
2055 MUSIC_FUNCTION function_arglist {
2056 $$ = MAKE_SYNTAX ("music-function", @$,
2063 /**/ { $$ = SCM_EOL; }
2064 | '=' simple_string {
2071 | repeated_music { $$ = $1; }
2072 | re_rhythmed_music { $$ = $1; }
2073 | complex_music_prefix music
2075 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2079 complex_music_prefix:
2080 CONTEXT symbol optional_id optional_context_mod {
2081 Context_mod *ctxmod = unsmob_context_mod ($4);
2084 mods = ctxmod->get_mods ();
2085 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2087 | NEWCONTEXT symbol optional_id optional_context_mod {
2088 Context_mod *ctxmod = unsmob_context_mod ($4);
2091 mods = ctxmod->get_mods ();
2092 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2097 mode_changing_head grouped_music_list {
2098 if ($1 == ly_symbol2scm ("chords"))
2100 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2106 parser->lexer_->pop_state ();
2108 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2109 Context_mod *ctxmod = unsmob_context_mod ($2);
2112 mods = ctxmod->get_mods ();
2113 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2114 if ($1 == ly_symbol2scm ("ChordNames"))
2116 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2118 parser->lexer_->pop_state ();
2124 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2125 parser->lexer_->push_note_state (nn);
2127 $$ = ly_symbol2scm ("notes");
2131 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2132 parser->lexer_->push_note_state (nn);
2134 $$ = ly_symbol2scm ("drums");
2137 parser->lexer_->push_figuredbass_state ();
2139 $$ = ly_symbol2scm ("figures");
2142 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2143 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2144 nn = parser->lexer_->lookup_identifier ("pitchnames");
2145 parser->lexer_->push_chord_state (nn);
2146 $$ = ly_symbol2scm ("chords");
2150 { parser->lexer_->push_lyric_state ();
2151 $$ = ly_symbol2scm ("lyrics");
2155 mode_changing_head_with_context:
2157 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2158 parser->lexer_->push_note_state (nn);
2160 $$ = ly_symbol2scm ("DrumStaff");
2163 parser->lexer_->push_figuredbass_state ();
2165 $$ = ly_symbol2scm ("FiguredBass");
2168 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2169 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2170 nn = parser->lexer_->lookup_identifier ("pitchnames");
2171 parser->lexer_->push_chord_state (nn);
2172 $$ = ly_symbol2scm ("ChordNames");
2175 { parser->lexer_->push_lyric_state ();
2176 $$ = ly_symbol2scm ("Lyrics");
2181 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2184 /* Can also use music at the expensive of two S/Rs similar to
2185 \repeat \alternative */
2186 parser->lexer_->pop_state ();
2188 $$ = scm_cons ($3, SCM_EOL);
2190 | new_lyrics ADDLYRICS {
2191 parser->lexer_->push_lyric_state ();
2193 parser->lexer_->pop_state ();
2194 $$ = scm_cons ($4, $1);
2199 composite_music new_lyrics {
2200 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2202 | LYRICSTO simple_string {
2203 parser->lexer_->push_lyric_state ();
2205 parser->lexer_->pop_state ();
2206 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2211 CHANGE symbol '=' simple_string {
2212 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2219 $$ = scm_reverse_x ($1, SCM_EOL);
2221 | symbol_list_rev property_path {
2222 $$ = scm_reverse_x ($1, $2);
2228 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2231 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2233 | OVERRIDE property_path '=' scalar {
2234 if (scm_ilength ($2) < 2) {
2235 parser->parser_error (@2, _("bad grob property path"));
2238 $$ = scm_cons (ly_symbol2scm ("push"),
2239 scm_cons2 (scm_car ($2),
2244 | REVERT revert_arg {
2245 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2249 // This is all quite awkward for the sake of substantial backward
2250 // compatibility while at the same time allowing a more "natural" form
2251 // of specification not separating grob specification from grob
2252 // property path. The purpose of this definition of revert_arg is to
2253 // allow the symbol list which specifies grob and property to revert
2254 // to be optionally be split into two parts after the grob (which in
2255 // this case is just the first element of the list). symbol_list_part
2256 // is only one path component, but it can be parsed without lookahead,
2257 // so we can follow it with a synthetic BACKUP token when needed. If
2258 // the first symbol_list_part already contains multiple elements (only
2259 // possible if a Scheme expression provides them), we just parse for
2260 // additional elements introduced by '.', which is what the
2261 // SYMBOL_LIST backup in connection with the immediately following
2262 // rule using symbol_list_arg does.
2264 // As long as we don't have our coffers filled with both grob and at
2265 // least one grob property specification, the rest of the required
2266 // symbol list chain may be provided either with or without a leading
2267 // dot. This is for both allowing the traditional
2268 // \revert Accidental #'color
2269 // as well as well as the "naive" form
2270 // \revert Accidental.color
2273 revert_arg_backup BACKUP symbol_list_arg
2282 if (scm_is_null ($1)
2283 || scm_is_null (scm_cdr ($1)))
2284 MYBACKUP (SCM_ARG, $1, @1);
2286 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2290 // revert_arg_part delivers results in reverse
2293 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2295 $$ = scm_append_x (scm_list_2 ($5, $3));
2297 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2299 $$ = scm_append_x (scm_list_2 ($4, $3));
2304 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2305 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2307 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2308 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2309 | DENIES { $$ = ly_symbol2scm ("denies"); }
2311 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2312 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2313 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2314 | NAME { $$ = ly_symbol2scm ("context-name"); }
2318 property_operation { $$ = $1; }
2319 | context_def_mod STRING {
2320 $$ = scm_list_2 ($1, $2);
2322 | context_def_mod embedded_scm
2324 if (!scm_is_string ($2)
2325 && ly_symbol2scm ("consists") != $1
2326 && ly_symbol2scm ("remove") != $1)
2329 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2333 $$ = scm_list_2 ($1, $2);
2338 // If defined, at least two members.
2342 SCM l = scm_reverse_x ($1, SCM_EOL);
2345 (scm_object_property (scm_car (l),
2346 ly_symbol2scm ("is-grob?"))))
2347 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2348 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2349 parser->parser_error (@1, _ ("bad grob property path"));
2356 // If defined, at least three members
2360 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2362 parser->parser_error (@1, _ ("bad grob property path"));
2366 | grob_prop_spec property_path
2368 if (!SCM_UNBNDP ($1)) {
2369 $$ = scm_append_x (scm_list_2 ($1, $2));
2370 if (scm_is_null (scm_cddr ($$))) {
2371 parser->parser_error (@$, _ ("bad grob property path"));
2379 // Exactly two elements or undefined
2383 SCM l = scm_reverse_x ($1, SCM_EOL);
2384 switch (scm_ilength (l)) {
2386 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2390 parser->parser_error (@1, _ ("bad context property path"));
2397 simple_music_property_def:
2398 OVERRIDE grob_prop_path '=' scalar {
2399 if (SCM_UNBNDP ($2))
2402 $$ = scm_list_5 (scm_car ($2),
2403 ly_symbol2scm ("OverrideProperty"),
2409 | REVERT simple_revert_context revert_arg {
2410 $$ = scm_list_4 ($2,
2411 ly_symbol2scm ("RevertProperty"),
2415 | SET context_prop_spec '=' scalar {
2416 if (SCM_UNBNDP ($2))
2419 $$ = scm_list_4 (scm_car ($2),
2420 ly_symbol2scm ("PropertySet"),
2424 | UNSET context_prop_spec {
2425 if (SCM_UNBNDP ($2))
2428 $$ = scm_list_3 (scm_car ($2),
2429 ly_symbol2scm ("PropertyUnset"),
2435 // This is all quite awkward for the sake of substantial backward
2436 // compatibility while at the same time allowing a more "natural" form
2437 // of specification not separating grob specification from grob
2438 // property path. The purpose of this definition of
2439 // simple_revert_context is to allow the symbol list which specifies
2440 // grob and property to revert to be optionally be split into two
2441 // parts after the grob (which may be preceded by a context
2442 // specification, a case which we distinguish by checking whether the
2443 // first symbol is a valid grob symbol instead).
2445 // See revert_arg above for the main work horse of this arrangement.
2446 // simple_revert_context just caters for the context and delegates the
2447 // rest of the job to revert_arg.
2449 simple_revert_context:
2452 $1 = scm_reverse_x ($1, SCM_EOL);
2453 if (scm_is_null ($1)
2455 (scm_object_property (scm_car ($1),
2456 ly_symbol2scm ("is-grob?")))) {
2457 $$ = ly_symbol2scm ("Bottom");
2458 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2461 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2468 simple_music_property_def {
2469 if (SCM_UNBNDP ($1))
2470 $$ = MAKE_SYNTAX ("void-music", @1);
2472 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2483 simple_string: STRING {
2488 if (scm_is_string ($1)) {
2491 parser->parser_error (@1, (_ ("simple string expected")));
2492 $$ = scm_string (SCM_EOL);
2499 $$ = scm_string_to_symbol ($1);
2503 // This is a bit of overkill but makes the same
2504 // routine responsible for all symbol interpretations.
2505 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2507 if (SCM_UNBNDP ($$))
2509 parser->parser_error (@1, (_ ("symbol expected")));
2510 // Generate a unique symbol in case it is used
2511 // for an assignment or similar
2512 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2522 // The following is a rather defensive variant of admitting
2523 // negative numbers: the grammar would permit number_factor or
2524 // even number_expression. However, function arguments allow
2525 // only this simple kind of negative number, so to have things
2526 // like \tweak and \override behave reasonably similar, it
2527 // makes sense to rule out things like -- which are rather an
2528 // accent in function argument contexts.
2531 $$ = scm_difference ($2, SCM_UNDEFINED);
2537 simple_element post_events {
2538 // Let the rhythmic music iterator sort this mess out.
2539 if (scm_is_pair ($2)) {
2540 unsmob_music ($$)->set_property ("articulations",
2541 scm_reverse_x ($2, SCM_EOL));
2544 | CHORD_REPETITION optional_notemode_duration post_events {
2546 i.set_location (@1, @3);
2547 $$ = MAKE_SYNTAX ("repetition-chord", i,
2548 $2, scm_reverse_x ($3, SCM_EOL));
2550 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2552 i.set_location (@1, @3);
2553 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2554 scm_reverse_x ($3, SCM_EOL));
2557 | note_chord_element
2562 chord_body optional_notemode_duration post_events
2564 Music *m = unsmob_music ($1);
2565 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2566 SCM es = m->get_property ("elements");
2567 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2569 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2570 unsmob_music (scm_car (s))->set_property ("duration", dur);
2571 es = ly_append2 (es, postevs);
2573 m-> set_property ("elements", es);
2575 $$ = m->self_scm ();
2580 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2582 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2586 chord_body_elements:
2587 /* empty */ { $$ = SCM_EOL; }
2588 | chord_body_elements chord_body_element {
2589 if (!SCM_UNBNDP ($2))
2590 $$ = scm_cons ($2, $1);
2595 pitch exclamations questions octave_check post_events
2597 bool q = to_boolean ($3);
2598 bool ex = to_boolean ($2);
2602 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2603 n->set_property ("pitch", $1);
2605 n->set_property ("cautionary", SCM_BOOL_T);
2607 n->set_property ("force-accidental", SCM_BOOL_T);
2609 if (scm_is_pair (post)) {
2610 SCM arts = scm_reverse_x (post, SCM_EOL);
2611 n->set_property ("articulations", arts);
2613 if (scm_is_number (check))
2615 int q = scm_to_int (check);
2616 n->set_property ("absolute-octave", scm_from_int (q-1));
2619 $$ = n->unprotect ();
2621 | DRUM_PITCH post_events {
2622 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2623 n->set_property ("drum-type", $1);
2625 if (scm_is_pair ($2)) {
2626 SCM arts = scm_reverse_x ($2, SCM_EOL);
2627 n->set_property ("articulations", arts);
2629 $$ = n->unprotect ();
2631 | music_function_chord_body
2633 Music *m = unsmob_music ($1);
2635 while (m && m->is_mus_type ("music-wrapper-music")) {
2636 $$ = m->get_property ("element");
2637 m = unsmob_music ($$);
2640 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2641 parser->parser_error (@$, _ ("not a rhythmic event"));
2647 music_function_chord_body:
2653 event_function_event:
2654 EVENT_FUNCTION function_arglist {
2655 $$ = MAKE_SYNTAX ("music-function", @$,
2664 | post_events post_event {
2666 if (Music *m = unsmob_music ($2))
2668 if (m->is_mus_type ("post-event-wrapper"))
2670 for (SCM p = m->get_property ("elements");
2674 $$ = scm_cons (scm_car (p), $$);
2678 $$ = scm_cons ($2, $$);
2684 post_event_nofinger:
2685 direction_less_event {
2688 | script_dir music_function_call {
2690 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2691 parser->parser_error (@2, _ ("post-event expected"));
2692 $$ = SCM_UNSPECIFIED;
2693 } else if (!SCM_UNBNDP ($1))
2695 unsmob_music ($$)->set_property ("direction", $1);
2699 if (!parser->lexer_->is_lyric_state ())
2700 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2701 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2704 if (!parser->lexer_->is_lyric_state ())
2705 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2706 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2708 | script_dir direction_reqd_event {
2709 if (!SCM_UNBNDP ($1))
2711 Music *m = unsmob_music ($2);
2712 m->set_property ("direction", $1);
2716 | script_dir direction_less_event {
2717 if (!SCM_UNBNDP ($1))
2719 Music *m = unsmob_music ($2);
2720 m->set_property ("direction", $1);
2727 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2732 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2743 string_number_event:
2745 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2746 s->set_property ("string-number", $1);
2747 $$ = s->unprotect ();
2751 direction_less_event:
2753 | EVENT_IDENTIFIER {
2757 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2758 a->set_property ("tremolo-type", $1);
2759 $$ = a->unprotect ();
2761 | event_function_event
2764 direction_reqd_event:
2768 | script_abbreviation {
2769 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2770 if (scm_is_string (s)) {
2771 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2772 a->set_property ("articulation-type", s);
2773 $$ = a->unprotect ();
2775 Music *original = unsmob_music (s);
2776 if (original && original->is_mus_type ("post-event")) {
2777 Music *a = original->clone ();
2778 a->set_spot (parser->lexer_->override_input (@$));
2779 $$ = a->unprotect ();
2781 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2782 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2789 /**/ { $$ = SCM_EOL; }
2790 | '=' quotes { $$ = $2; }
2804 $$ = scm_from_int (1);
2807 $$ = scm_oneplus ($1);
2813 $$ = scm_from_int (-1);
2816 $$ = scm_oneminus ($1);
2821 NOTENAME_PITCH quotes {
2822 if (!scm_is_eq (SCM_INUM0, $2))
2824 Pitch p = *unsmob_pitch ($1);
2825 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2826 $$ = p.smobbed_copy ();
2836 TONICNAME_PITCH quotes {
2837 if (!scm_is_eq (SCM_INUM0, $2))
2839 Pitch p = *unsmob_pitch ($1);
2840 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2841 $$ = p.smobbed_copy ();
2848 | PITCH_IDENTIFIER quotes {
2849 if (!scm_is_eq (SCM_INUM0, $2))
2851 Pitch p = *unsmob_pitch ($1);
2852 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2853 $$ = p.smobbed_copy ();
2860 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2861 t->set_property ("text", $1);
2862 $$ = t->unprotect ();
2865 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2866 t->set_property ("text",
2867 make_simple_markup ($1));
2868 $$ = t->unprotect ();
2872 Music *m = unsmob_music ($1);
2873 if (m && m->is_mus_type ("post-event"))
2875 else if (Text_interface::is_markup ($1)) {
2876 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2877 t->set_property ("text", $1);
2878 $$ = t->unprotect ();
2880 parser->parser_error (@1, _ ("not an articulation"));
2886 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2887 t->set_property ("digit", $1);
2888 $$ = t->unprotect ();
2892 script_abbreviation:
2894 $$ = scm_from_locale_string ("Hat");
2897 $$ = scm_from_locale_string ("Plus");
2900 $$ = scm_from_locale_string ("Dash");
2903 $$ = scm_from_locale_string ("Bang");
2906 $$ = scm_from_locale_string ("Larger");
2909 $$ = scm_from_locale_string ("Dot");
2912 $$ = scm_from_locale_string ("Underscore");
2917 '_' { $$ = scm_from_int (DOWN); }
2918 | '^' { $$ = scm_from_int (UP); }
2919 | '-' { $$ = SCM_UNDEFINED; }
2923 multiplied_duration {
2928 maybe_notemode_duration:
2932 | multiplied_duration {
2934 parser->default_duration_ = *unsmob_duration ($$);
2939 optional_notemode_duration:
2940 maybe_notemode_duration
2942 if (SCM_UNBNDP ($$))
2943 $$ = parser->default_duration_.smobbed_copy ();
2949 $$ = make_duration ($1, scm_to_int ($2));
2950 if (SCM_UNBNDP ($$))
2952 parser->parser_error (@1, _ ("not a duration"));
2953 $$ = Duration ().smobbed_copy ();
2956 | DURATION_IDENTIFIER dots {
2957 Duration *d = unsmob_duration ($1);
2958 Duration k (d->duration_log (),
2959 d->dot_count () + scm_to_int ($2));
2960 k = k.compressed (d->factor ());
2961 scm_remember_upto_here_1 ($1);
2962 $$ = k.smobbed_copy ();
2966 multiplied_duration:
2970 | multiplied_duration '*' UNSIGNED {
2971 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2973 | multiplied_duration '*' FRACTION {
2974 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2976 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2985 $$ = scm_oneplus ($1);
2994 if (SCM_UNBNDP (make_duration ($2)))
2995 parser->parser_error (@2, _ ("not a duration"));
3001 UNSIGNED { $$ = $1; }
3002 | STRING { $$ = $1; }
3003 | full_markup { $$ = $1; }
3006 // as an integer, it needs to be non-negative, and otherwise
3007 // it needs to be suitable as a markup.
3008 if (scm_is_integer ($1)
3009 ? scm_is_true (scm_negative_p ($1))
3010 : !Text_interface::is_markup ($1))
3012 parser->parser_error (@1, _ ("bass number expected"));
3018 figured_bass_alteration:
3019 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3020 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3021 | '!' { $$ = scm_from_int (0); }
3026 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3027 $$ = bfr->unprotect ();
3030 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3031 $$ = bfr->self_scm ();
3033 if (scm_is_number ($1))
3034 bfr->set_property ("figure", $1);
3035 else if (Text_interface::is_markup ($1))
3036 bfr->set_property ("text", $1);
3042 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3044 | bass_figure figured_bass_alteration {
3045 Music *m = unsmob_music ($1);
3046 if (scm_to_double ($2)) {
3047 SCM salter = m->get_property ("alteration");
3048 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3049 m->set_property ("alteration",
3050 scm_sum (alter, $2));
3052 m->set_property ("alteration", scm_from_int (0));
3055 | bass_figure figured_bass_modification {
3056 Music *m = unsmob_music ($1);
3057 m->set_property ($2, SCM_BOOL_T);
3062 figured_bass_modification:
3064 $$ = ly_symbol2scm ("augmented");
3067 $$ = ly_symbol2scm ("no-continuation");
3070 $$ = ly_symbol2scm ("diminished");
3073 $$ = ly_symbol2scm ("augmented-slash");
3083 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3091 | figure_list br_bass_figure {
3092 $$ = scm_cons ($2, $1);
3097 FIGURE_OPEN figure_list FIGURE_CLOSE {
3098 $$ = scm_reverse_x ($2, SCM_EOL);
3104 /**/ { $$ = SCM_BOOL_F; }
3105 | REST { $$ = SCM_BOOL_T; }
3109 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3110 if (!parser->lexer_->is_note_state ())
3111 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3112 if (!SCM_UNBNDP ($2)
3114 || scm_is_number ($4)
3117 || scm_is_pair ($7))
3120 if (scm_is_true ($6))
3121 n = MY_MAKE_MUSIC ("RestEvent", @$);
3123 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3125 n->set_property ("pitch", $1);
3126 if (SCM_UNBNDP ($5))
3127 n->set_property ("duration",
3128 parser->default_duration_.smobbed_copy ());
3130 n->set_property ("duration", $5);
3132 if (scm_is_number ($4))
3134 int q = scm_to_int ($4);
3135 n->set_property ("absolute-octave", scm_from_int (q-1));
3138 if (to_boolean ($3))
3139 n->set_property ("cautionary", SCM_BOOL_T);
3140 if (to_boolean ($2) || to_boolean ($3))
3141 n->set_property ("force-accidental", SCM_BOOL_T);
3142 if (scm_is_pair ($7))
3143 n->set_property ("articulations",
3144 scm_reverse_x ($7, SCM_EOL));
3145 $$ = n->unprotect ();
3148 | simple_chord_elements post_events {
3149 if (scm_is_pair ($2)) {
3150 if (unsmob_pitch ($1))
3151 $1 = make_chord_elements (@1,
3153 parser->default_duration_.smobbed_copy (),
3156 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3158 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
3159 } else if (!unsmob_pitch ($1))
3160 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
3161 // A mere pitch drops through.
3166 DRUM_PITCH optional_notemode_duration {
3167 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3168 n->set_property ("duration", $2);
3169 n->set_property ("drum-type", $1);
3171 $$ = n->unprotect ();
3173 | RESTNAME optional_notemode_duration {
3175 if (ly_scm2string ($1) == "s") {
3177 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3180 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3183 ev->set_property ("duration", $2);
3184 $$ = ev->unprotect ();
3188 // Can return a single pitch rather than a list.
3189 simple_chord_elements:
3191 if (!parser->lexer_->is_chord_state ())
3192 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3195 | figure_spec optional_notemode_duration {
3196 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3198 unsmob_music (scm_car (s))->set_property ("duration", $2);
3206 if (!parser->lexer_->is_lyric_state ())
3207 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3211 if (!parser->lexer_->is_lyric_state ())
3212 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3218 lyric_element_music:
3219 lyric_element optional_notemode_duration post_events {
3220 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3221 if (scm_is_pair ($3))
3222 unsmob_music ($$)->set_property
3223 ("articulations", scm_reverse_x ($3, SCM_EOL));
3227 // Can return a single pitch rather than a list.
3229 steno_tonic_pitch maybe_notemode_duration {
3230 if (SCM_UNBNDP ($2))
3233 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3235 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3236 SCM its = scm_reverse_x ($4, SCM_EOL);
3237 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3245 | chord_items chord_item {
3246 $$ = scm_cons ($2, $$);
3252 $$ = ly_symbol2scm ("chord-colon");
3255 $$ = ly_symbol2scm ("chord-caret");
3257 | CHORD_SLASH steno_tonic_pitch {
3258 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3260 | CHORD_BASS steno_tonic_pitch {
3261 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3270 $$ = scm_reverse_x ($1, SCM_EOL);
3278 step_number { $$ = scm_cons ($1, SCM_EOL); }
3279 | step_numbers '.' step_number {
3280 $$ = scm_cons ($3, $$);
3286 $$ = make_chord_step ($1, 0);
3289 $$ = make_chord_step ($1, SHARP_ALTERATION);
3291 | UNSIGNED CHORD_MINUS {
3292 $$ = make_chord_step ($1, FLAT_ALTERATION);
3300 | unsigned_number '-' unsigned_number {
3301 $$ = scm_cons ($1, $3);
3308 TODO: should deprecate in favor of Scheme?
3312 number_expression '+' number_term {
3313 $$ = scm_sum ($1, $3);
3315 | number_expression '-' number_term {
3316 $$ = scm_difference ($1, $3);
3325 | number_factor '*' number_factor {
3326 $$ = scm_product ($1, $3);
3328 | number_factor '/' number_factor {
3329 $$ = scm_divide ($1, $3);
3334 '-' number_factor { /* %prec UNARY_MINUS */
3335 $$ = scm_difference ($2, SCM_UNDEFINED);
3343 | REAL NUMBER_IDENTIFIER
3345 $$ = scm_product ($1, $2);
3352 | UNSIGNED NUMBER_IDENTIFIER {
3353 $$ = scm_product ($1, $2);
3361 if (!scm_is_integer ($1)
3362 || scm_is_true (scm_negative_p ($1)))
3364 parser->parser_error (@1, _("not an unsigned integer"));
3370 if (!scm_is_integer ($1)
3371 || scm_is_true (scm_negative_p ($1)))
3373 parser->parser_error (@1, _("not an unsigned integer"));
3380 { $$ = SCM_UNDEFINED; }
3383 if (SCM_UNBNDP ($1))
3391 // This precedence rule is rather weird. It triggers when '!' is
3392 // encountered after a pitch, and is used for deciding whether to save
3393 // this instead for a figure modification. This should not actually
3394 // occur in practice as pitches and figures are generated in different
3395 // modes. Using a greedy (%right) precedence makes sure that we don't
3396 // get stuck in a wrong interpretation.
3397 { $$ = SCM_UNDEFINED; } %prec ':'
3400 if (SCM_UNBNDP ($1))
3409 { parser->lexer_->push_markup_state (); }
3412 parser->lexer_->pop_state ();
3418 { parser->lexer_->push_markup_state (); }
3421 parser->lexer_->pop_state ();
3427 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3429 | markup_head_1_list simple_markup
3431 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3432 @2, $1, scm_list_1 ($2)));
3442 if (Text_interface::is_markup ($1))
3443 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3444 else if (Text_interface::is_markup_list ($1))
3445 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3447 parser->parser_error (@1, _ ("not a markup"));
3448 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3455 markup_composed_list {
3458 | markup_uncomposed_list
3461 markup_uncomposed_list:
3462 markup_braced_list {
3465 | markup_command_list {
3466 $$ = scm_list_1 ($1);
3468 | markup_scm MARKUPLIST_IDENTIFIER
3473 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3474 parser->lexer_->push_note_state (nn);
3475 } '{' score_body '}' {
3476 unsmob_score ($4)->origin ()->set_spot (@$);
3477 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3478 parser->lexer_->pop_state ();
3482 markup_composed_list:
3483 markup_head_1_list markup_uncomposed_list {
3484 $$ = MAKE_SYNTAX ("composed-markup-list",
3490 '{' markup_braced_list_body '}' {
3491 $$ = scm_reverse_x ($2, SCM_EOL);
3495 markup_braced_list_body:
3496 /* empty */ { $$ = SCM_EOL; }
3497 | markup_braced_list_body markup {
3498 $$ = scm_cons ($2, $1);
3500 | markup_braced_list_body markup_list {
3501 $$ = scm_reverse_x ($2, $1);
3505 markup_command_list:
3506 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3507 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3511 markup_command_basic_arguments:
3512 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3513 $$ = scm_cons ($3, $2);
3515 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3516 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3518 | EXPECT_NO_MORE_ARGS {
3523 markup_command_list_arguments:
3524 markup_command_basic_arguments { $$ = $1; }
3525 | EXPECT_MARKUP markup_command_list_arguments markup {
3526 $$ = scm_cons ($3, $2);
3531 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3532 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3537 markup_head_1_item {
3538 $$ = scm_list_1 ($1);
3540 | markup_head_1_list markup_head_1_item {
3541 $$ = scm_cons ($2, $1);
3547 $$ = make_simple_markup ($1);
3550 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3551 parser->lexer_->push_note_state (nn);
3552 } '{' score_body '}' {
3553 unsmob_score ($4)->origin ()->set_spot (@$);
3554 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3555 parser->lexer_->pop_state ();
3557 | MARKUP_FUNCTION markup_command_basic_arguments {
3558 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3560 | markup_scm MARKUP_IDENTIFIER
3567 markup_head_1_list simple_markup
3569 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3570 @2, $1, scm_list_1 ($2)));
3580 Lily_parser::set_yydebug (bool x)
3586 Lily_parser::do_yyparse ()
3588 SCM retval = SCM_UNDEFINED;
3589 yyparse (this, &retval);
3599 It is a little strange to have this function in this file, but
3600 otherwise, we have to import music classes into the lexer.
3604 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3606 if (unsmob_book (sid)) {
3607 Book *book = unsmob_book (sid)->clone ();
3608 *destination = book->self_scm ();
3611 return BOOK_IDENTIFIER;
3612 } else if (scm_is_number (sid)) {
3614 return NUMBER_IDENTIFIER;
3615 } else if (unsmob_context_def (sid)) {
3616 Context_def *def= unsmob_context_def (sid)->clone ();
3618 *destination = def->self_scm ();
3621 return CONTEXT_DEF_IDENTIFIER;
3622 } else if (unsmob_context_mod (sid)) {
3623 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3625 return CONTEXT_MOD_IDENTIFIER;
3626 } else if (Music *mus = unsmob_music (sid)) {
3627 mus = mus->clone ();
3628 *destination = mus->self_scm ();
3629 bool is_event = mus->is_mus_type ("post-event");
3631 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3632 } else if (unsmob_pitch (sid)) {
3633 *destination = unsmob_pitch (sid)->smobbed_copy ();
3634 return PITCH_IDENTIFIER;
3635 } else if (unsmob_duration (sid)) {
3636 *destination = unsmob_duration (sid)->smobbed_copy ();
3637 return DURATION_IDENTIFIER;
3638 } else if (unsmob_output_def (sid)) {
3639 Output_def *p = unsmob_output_def (sid);
3642 *destination = p->self_scm ();
3644 return OUTPUT_DEF_IDENTIFIER;
3645 } else if (unsmob_score (sid)) {
3646 *destination = unsmob_score (sid)->clone ()->unprotect ();
3647 return SCM_IDENTIFIER;
3654 get_next_unique_context_id ()
3656 return scm_from_locale_string ("$uniqueContextId");
3661 get_next_unique_lyrics_context_id ()
3663 static int new_context_count;
3665 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3666 return scm_from_locale_string (s);
3669 // check_scheme_arg checks one argument with a given predicate for use
3670 // in an argument list and throws a syntax error if it is unusable.
3671 // The argument is prepended to the argument list in any case. After
3672 // throwing a syntax error, the argument list is terminated with #f as
3673 // its last cdr in order to mark it as uncallable while not losing
3674 // track of its total length.
3676 // There are a few special considerations: if optional argument disp
3677 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3678 // instead of arg in a prospective error message. This is useful if
3679 // arg is not the actual argument but rather a transformation of it.
3681 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3682 // and an error message using disp is produced unconditionally.
3684 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3685 SCM arg, SCM args, SCM pred, SCM disp)
3687 if (SCM_UNBNDP (arg))
3688 args = scm_cons (disp, args);
3690 args = scm_cons (arg, args);
3691 if (scm_is_true (scm_call_1 (pred, arg)))
3694 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3695 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3696 SCM_UNBNDP (disp) ? arg : disp);
3697 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3701 SCM loc_on_music (Input loc, SCM arg)
3703 if (Music *m = unsmob_music (arg))
3707 return m->unprotect ();
3713 try_string_variants (SCM pred, SCM str)
3715 // a matching predicate is always ok
3716 if (scm_is_true (scm_call_1 (pred, str)))
3718 // a symbol may be interpreted as a list of symbols if it helps
3719 if (scm_is_symbol (str)) {
3720 str = scm_list_1 (str);
3721 if (scm_is_true (scm_call_1 (pred, str)))
3723 return SCM_UNDEFINED;
3726 // If this cannot be a string representation of a symbol list,
3729 if (!is_regular_identifier (str, true))
3730 return SCM_UNDEFINED;
3732 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3733 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3734 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3736 // Let's attempt the symbol list interpretation first.
3738 if (scm_is_true (scm_call_1 (pred, str)))
3741 // If there is just one symbol in the list, we might interpret
3742 // it as a single symbol
3744 if (scm_is_null (scm_cdr (str)))
3746 str = scm_car (str);
3747 if (scm_is_true (scm_call_1 (pred, str)))
3751 return SCM_UNDEFINED;
3755 is_regular_identifier (SCM id, bool multiple)
3757 if (!scm_is_string (id))
3760 string str = ly_scm2string (id);
3762 bool middle = false;
3764 for (string::iterator it=str.begin(); it != str.end (); it++)
3767 if ((c >= 'a' && c <= 'z')
3768 || (c >= 'A' && c <= 'Z')
3771 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3780 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3782 if (unsmob_music (simple))
3784 if (parser->lexer_->is_note_state ()) {
3785 if (scm_is_symbol (simple)) {
3786 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3787 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3788 n->set_property ("drum-type", simple);
3789 return n->unprotect ();
3791 if (unsmob_pitch (simple)) {
3792 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3793 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3794 n->set_property ("pitch", simple);
3795 return n->unprotect ();
3798 } else if (parser->lexer_->is_lyric_state ()) {
3799 if (Text_interface::is_markup (simple))
3800 return MAKE_SYNTAX ("lyric-event", loc, simple,
3801 parser->default_duration_.smobbed_copy ());
3802 } else if (parser->lexer_->is_chord_state ()) {
3803 if (unsmob_pitch (simple))
3807 make_chord_elements (loc, simple,
3808 parser->default_duration_.smobbed_copy (),
3815 make_music_with_input (SCM name, Input where)
3817 Music *m = make_music_by_name (name);
3818 m->set_spot (where);
3823 make_simple_markup (SCM a)
3829 make_duration (SCM d, int dots)
3831 int t = scm_to_int (d);
3832 if (t > 0 && (t & (t-1)) == 0)
3833 return Duration (intlog2 (t), dots).smobbed_copy ();
3835 return SCM_UNDEFINED;
3839 make_chord_step (SCM step_scm, Rational alter)
3841 int step = scm_to_int (step_scm);
3844 alter += FLAT_ALTERATION;
3848 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3849 return m.smobbed_copy ();
3854 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3856 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3857 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3858 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3860 unsmob_music (scm_car (s))->set_spot (loc);
3866 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3868 Lily_lexer *lex = parser->lexer_;
3872 int tok = lex->pop_extra_token ();
3875 lex->prepare_for_next_token ();
3876 return lex->yylex ();