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 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
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 '}' {
1013 parser->lexer_->remove_scope ();
1014 parser->lexer_->pop_state ();
1020 Output_def *p = get_paper (parser);
1021 p->input_origin_ = @$;
1022 parser->lexer_->add_scope (p->scope_);
1023 $$ = p->unprotect ();
1026 Output_def *p = get_midi (parser);
1027 $$ = p->unprotect ();
1028 parser->lexer_->add_scope (p->scope_);
1031 Output_def *p = get_layout (parser);
1033 parser->lexer_->add_scope (p->scope_);
1034 $$ = p->unprotect ();
1038 output_def_head_with_mode_switch:
1040 parser->lexer_->push_initial_state ();
1045 // We need this weird nonterminal because both music as well as a
1046 // context definition can start with \context and the difference is
1047 // only apparent after looking at the next token. If it is '{', there
1048 // is still time to escape from notes mode.
1050 music_or_context_def:
1052 | context_def_spec_block
1056 output_def_head_with_mode_switch '{' {
1058 unsmob_output_def ($$)->input_origin_.set_spot (@$);
1060 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1061 Output_def *o = unsmob_output_def ($3);
1062 o->input_origin_.set_spot (@$);
1063 $$ = o->self_scm ();
1064 parser->lexer_->remove_scope ();
1065 parser->lexer_->add_scope (o->scope_);
1067 | output_def_body assignment {
1070 | output_def_body embedded_scm {
1075 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1076 parser->lexer_->push_note_state (nn);
1077 } music_or_context_def
1079 parser->lexer_->pop_state ();
1080 if (unsmob_context_def ($3))
1081 assign_context_def (unsmob_output_def ($1), $3);
1084 SCM proc = parser->lexer_->lookup_identifier
1085 ("output-def-music-handler");
1086 scm_call_3 (proc, parser->self_scm (),
1090 | output_def_body error {
1096 TEMPO steno_duration '=' tempo_range {
1097 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1099 | TEMPO scalar steno_duration '=' tempo_range {
1100 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1103 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1108 The representation of a list is reversed to have efficient append. */
1114 | music_list music_embedded {
1115 if (unsmob_music ($2))
1116 $$ = scm_cons ($2, $1);
1118 | music_list error {
1119 Music *m = MY_MAKE_MUSIC("Music", @$);
1121 m->set_property ("error-found", SCM_BOOL_T);
1122 $$ = scm_cons (m->self_scm (), $1);
1123 m->unprotect (); /* UGH */
1130 $$ = scm_reverse_x ($2, SCM_EOL);
1135 | lyric_element_music
1138 $$ = make_music_from_simple (parser, @1, $1);
1139 if (!unsmob_music ($$))
1141 parser->parser_error (@1, _ ("music expected"));
1142 $$ = MAKE_SYNTAX ("void-music", @$);
1150 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1151 parser->parser_error (@1, _ ("unexpected post-event"));
1152 $$ = SCM_UNSPECIFIED;
1155 | music_embedded_backup
1159 | music_embedded_backup BACKUP lyric_element_music
1163 | multiplied_duration post_events
1165 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1167 parser->default_duration_ = *unsmob_duration ($1);
1168 n->set_property ("duration", $1);
1170 if (scm_is_pair ($2))
1171 n->set_property ("articulations",
1172 scm_reverse_x ($2, SCM_EOL));
1173 $$ = n->unprotect ();
1177 music_embedded_backup:
1180 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1182 else if (Music *m = unsmob_music ($1)) {
1183 if (m->is_mus_type ("post-event")) {
1184 parser->parser_error
1185 (@1, _ ("unexpected post-event"));
1186 $$ = SCM_UNSPECIFIED;
1189 } else if (parser->lexer_->is_lyric_state ()
1190 && Text_interface::is_markup ($1))
1191 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1193 @$.warning (_ ("Ignoring non-music expression"));
1199 // music_assign does not need to contain lyrics: there are no
1200 // assignments in lyricmode.
1203 | composite_music %prec COMPOSITE
1207 REPEAT simple_string unsigned_number music
1209 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1211 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1213 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1218 SEQUENTIAL braced_music_list {
1219 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1221 | braced_music_list {
1222 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1227 SIMULTANEOUS braced_music_list {
1228 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1230 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1231 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1237 | music_property_def
1241 context_modification:
1244 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1245 parser->lexer_->push_note_state (nn);
1246 } '{' context_mod_list '}'
1248 parser->lexer_->pop_state ();
1251 | WITH CONTEXT_MOD_IDENTIFIER
1255 | CONTEXT_MOD_IDENTIFIER
1259 | WITH context_modification_arg
1261 if (unsmob_music ($2)) {
1262 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1263 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1265 if (unsmob_context_mod ($2))
1268 parser->parser_error (@2, _ ("not a context mod"));
1269 $$ = Context_mod ().smobbed_copy ();
1274 context_modification_arg:
1279 optional_context_mod:
1283 | context_modification
1291 $$ = Context_mod ().smobbed_copy ();
1293 | context_mod_list context_mod {
1294 if (!SCM_UNBNDP ($2))
1295 unsmob_context_mod ($1)->add_context_mod ($2);
1297 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1298 Context_mod *md = unsmob_context_mod ($2);
1300 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1302 | context_mod_list context_mod_embedded {
1303 unsmob_context_mod ($1)->add_context_mods
1304 (unsmob_context_mod ($2)->get_mods ());
1316 | grouped_music_list
1320 simultaneous_music { $$ = $1; }
1321 | sequential_music { $$ = $1; }
1324 /* Function argument lists are arguably the most complex part in the
1325 * parser. They are pretty tricky to understand because of the way
1326 * they are processed, and because of optional arguments that can be
1327 * omitted. When there are several optional arguments in a row,
1328 * omitting one automatically omits all following arguments. Optional
1329 * arguments can only be omitted when either
1331 * a) the omission is explicitly started with \default
1332 * b) the omission is implicitly started by an argument not matching
1333 * its predicate, and there is a mandatory argument later that can
1334 * "catch" the argument that does not fit.
1336 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1337 * (corresponding to mandatory arguments and having a predicate
1338 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1339 * the semantic value of the EXPECT_OPTIONAL token is the default to
1340 * use when the optional argument is omitted, and EXPECT_SCM again has
1341 * the argument predicate as semantic value) in reverse order to the
1342 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1343 * processed inside-out while actual tokens are consumed.
1345 * This means that the argument list tokens determine the actions
1346 * taken as they arrive. The structure of the argument list is known
1347 * to the parser and stored in its parse stack when the first argument
1348 * is being parsed. What the parser does not know is which predicates
1349 * will match and whether or not \default will be appearing in the
1350 * argument list, and where.
1352 * Sequences of 0 or more optional arguments are scanned using either
1353 * function_arglist_backup or function_arglist_nonbackup. The first
1354 * is used when optional arguments are followed by at least one
1355 * mandatory argument: in that case optional arguments may be skipped
1356 * by either a false predicate (in which case the expression will be
1357 * pushed back as one or more tokens, preceded by a BACKUP token) or
1358 * by using \default.
1360 * If optional arguments are at the end of the argument list, they are
1361 * instead scanned using function_arglist_nonbackup: here the only
1362 * manner to enter into skipping of optional arguments is the use of
1365 * The argument list of a normal function call is parsed using
1366 * function_arglist. The part of an argument list before a mandatory
1367 * argument is parsed using function_arglist_optional.
1369 * The difference is that leading optional arguments are scanned using
1370 * function_arglist_nonbackup and function_arglist_backup,
1373 * Most other details are obvious in the rules themselves.
1379 | SYMBOL_LIST '.' symbol_list_rev
1381 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1387 | symbol_list_rev '.' symbol_list_part
1389 $$ = scm_append_x (scm_list_2 ($3, $1));
1393 // symbol_list_part delivers elements in reverse copy.
1398 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1399 $$ = try_string_variants (sym_l_p, $1);
1400 if (SCM_UNBNDP ($$)) {
1401 parser->parser_error (@1, _("not a symbol"));
1404 $$ = scm_reverse ($$);
1409 symbol_list_element:
1415 function_arglist_nonbackup:
1416 function_arglist_common
1417 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1419 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1421 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1423 SCM n = scm_difference ($5, SCM_UNDEFINED);
1424 if (scm_is_true (scm_call_1 ($2, n)))
1425 $$ = scm_cons (n, $3);
1427 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1428 t->set_property ("digit", $5);
1429 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1434 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1436 $$ = check_scheme_arg (parser, @4,
1437 scm_difference ($5, SCM_UNDEFINED),
1440 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1442 $$ = check_scheme_arg (parser, @4,
1443 scm_difference ($5, SCM_UNDEFINED),
1446 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1448 if (scm_is_true (scm_call_1 ($2, $4)))
1449 $$ = scm_cons ($4, $3);
1451 $$ = check_scheme_arg (parser, @4,
1452 make_music_from_simple
1456 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1458 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1460 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1462 if (scm_is_true (scm_call_1 ($2, $3)))
1463 $$ = scm_cons ($3, $1);
1465 $$ = check_scheme_arg (parser, @3,
1466 make_music_from_simple
1470 | function_arglist_nonbackup_reparse REPARSE duration_length
1472 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1474 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1476 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1478 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1480 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1482 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1484 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1486 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1488 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1492 function_arglist_nonbackup_reparse:
1493 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1496 SCM res = try_string_variants ($2, $4);
1497 if (!SCM_UNBNDP (res))
1498 if (scm_is_pair (res))
1499 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1501 MYREPARSE (@4, $2, SCM_ARG, res);
1502 else if (scm_is_true
1504 ($2, make_music_from_simple
1506 MYREPARSE (@4, $2, STRING, $4);
1508 MYREPARSE (@4, $2, SCM_ARG, $4);
1510 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1515 ($2, make_music_from_simple
1517 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1519 MYREPARSE (@4, $2, SCM_ARG, $4);
1521 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1526 ($2, make_music_from_simple
1528 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1530 MYREPARSE (@4, $2, SCM_ARG, $4);
1532 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1535 SCM res = try_string_variants ($2, $4);
1536 if (!SCM_UNBNDP (res))
1537 if (scm_is_pair (res))
1538 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1540 MYREPARSE (@4, $2, SCM_ARG, res);
1541 else if (scm_is_true
1543 ($2, make_music_from_simple
1545 MYREPARSE (@4, $2, STRING, $4);
1547 MYREPARSE (@4, $2, SCM_ARG, $4);
1549 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1552 if (scm_is_true (scm_call_1 ($2, $4)))
1553 MYREPARSE (@4, $2, SCM_ARG, $4);
1554 else if (scm_is_true
1556 ($2, make_music_from_simple
1558 MYREPARSE (@4, $2, STRING, $4);
1560 MYREPARSE (@4, $2, SCM_ARG, $4);
1562 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1565 if (scm_is_true (scm_call_1 ($2, $4)))
1566 MYREPARSE (@4, $2, REAL, $4);
1568 SCM d = make_duration ($4);
1569 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1570 MYREPARSE (@4, $2, REAL, $4); // trigger error
1572 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1575 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1577 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1582 // function_arglist_backup can't occur at the end of an argument
1584 function_arglist_backup:
1585 function_arglist_common
1586 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1588 if (scm_is_true (scm_call_1 ($2, $4)))
1589 $$ = scm_cons ($4, $3);
1591 $$ = make_music_from_simple (parser, @4, $4);
1592 if (scm_is_true (scm_call_1 ($2, $$)))
1593 $$ = scm_cons ($$, $3);
1596 $$ = scm_cons (loc_on_music (@3, $1), $3);
1597 MYBACKUP (SCM_ARG, $4, @4);
1601 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1603 if (scm_is_true (scm_call_1 ($2, $4)))
1605 $$ = scm_cons ($4, $3);
1607 $$ = scm_cons (loc_on_music (@3, $1), $3);
1608 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1611 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1615 ($2, make_music_from_simple
1619 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1620 } else if (scm_is_true (scm_call_1 ($2, $4)))
1621 $$ = scm_cons ($4, $3);
1623 $$ = scm_cons (loc_on_music (@3, $1), $3);
1624 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1627 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1631 ($2, make_music_from_simple
1635 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1636 } else if (scm_is_true (scm_call_1 ($2, $4)))
1637 $$ = scm_cons ($4, $3);
1639 $$ = scm_cons (loc_on_music (@3, $1), $3);
1640 MYBACKUP (TONICNAME_PITCH, $4, @4);
1643 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1645 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 (LYRIC_ELEMENT, $4, @4);
1652 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1654 if (scm_is_true (scm_call_1 ($2, $4)))
1656 MYREPARSE (@4, $2, REAL, $4);
1659 SCM d = make_duration ($4);
1660 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1662 $$ = scm_cons (loc_on_music (@3, $1), $3);
1663 MYBACKUP (UNSIGNED, $4, @4);
1665 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1670 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1672 if (scm_is_true (scm_call_1 ($2, $4)))
1675 MYREPARSE (@4, $2, REAL, $4);
1677 $$ = scm_cons (loc_on_music (@3, $1), $3);
1678 MYBACKUP (REAL, $4, @4);
1681 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1683 if (scm_is_true (scm_call_1 ($2, $4)))
1685 $$ = scm_cons ($4, $3);
1687 $$ = scm_cons (loc_on_music (@3, $1), $3);
1688 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1691 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1693 SCM n = scm_difference ($5, SCM_UNDEFINED);
1694 if (scm_is_true (scm_call_1 ($2, n))) {
1696 MYREPARSE (@5, $2, REAL, n);
1698 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1699 t->set_property ("digit", $5);
1700 $$ = t->unprotect ();
1701 if (scm_is_true (scm_call_1 ($2, $$)))
1702 $$ = scm_cons ($$, $3);
1704 $$ = scm_cons (loc_on_music (@3, $1), $3);
1705 MYBACKUP (UNSIGNED, $5, @5);
1706 parser->lexer_->push_extra_token (@4, '-');
1711 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
1713 SCM n = scm_difference ($5, SCM_UNDEFINED);
1714 if (scm_is_true (scm_call_1 ($2, n))) {
1715 MYREPARSE (@5, $2, REAL, n);
1718 $$ = scm_cons (loc_on_music (@3, $1), $3);
1719 MYBACKUP (REAL, n, @5);
1722 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
1724 SCM n = scm_difference ($5, SCM_UNDEFINED);
1725 if (scm_is_true (scm_call_1 ($2, n))) {
1726 $$ = scm_cons (n, $3);
1728 $$ = scm_cons (loc_on_music (@3, $1), $3);
1729 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1732 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
1734 if (scm_is_true (scm_call_1 ($2, $4)))
1736 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1739 $$ = scm_cons (loc_on_music (@3, $1), $3);
1740 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1743 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
1745 SCM res = try_string_variants ($2, $4);
1746 if (!SCM_UNBNDP (res))
1747 if (scm_is_pair (res)) {
1749 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1752 $$ = scm_cons (res, $3);
1754 $$ = scm_cons (loc_on_music (@3, $1), $3);
1755 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1758 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
1760 SCM res = try_string_variants ($2, $4);
1761 if (!SCM_UNBNDP (res))
1762 if (scm_is_pair (res)) {
1764 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1767 $$ = scm_cons (res, $3);
1769 $$ = scm_cons (loc_on_music (@3, $1), $3);
1770 MYBACKUP (STRING, $4, @4);
1773 | function_arglist_backup REPARSE pitch_or_music
1775 if (scm_is_true (scm_call_1 ($2, $3)))
1776 $$ = scm_cons ($3, $1);
1778 $$ = check_scheme_arg (parser, @3,
1779 make_music_from_simple
1783 | function_arglist_backup REPARSE bare_number_common
1785 $$ = check_scheme_arg (parser, @3,
1788 | function_arglist_backup REPARSE duration_length
1790 $$ = check_scheme_arg (parser, @3,
1793 | function_arglist_backup REPARSE symbol_list_arg
1795 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1800 function_arglist_nonbackup
1801 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
1803 $$ = scm_cons (loc_on_music (@4, $1), $3);
1807 function_arglist_skip_nonbackup:
1808 function_arglist_nonbackup
1809 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
1811 $$ = scm_cons (loc_on_music (@3, $1), $3);
1815 function_arglist_common:
1816 EXPECT_NO_MORE_ARGS {
1819 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1821 if (scm_is_true (scm_call_1 ($1, $3)))
1822 $$ = scm_cons ($3, $2);
1824 $$ = check_scheme_arg (parser, @3,
1825 make_music_from_simple
1829 | EXPECT_SCM function_arglist_optional bare_number_common
1831 $$ = check_scheme_arg (parser, @3,
1834 | EXPECT_SCM function_arglist_optional post_event_nofinger
1836 $$ = check_scheme_arg (parser, @3,
1839 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
1841 SCM n = scm_difference ($4, SCM_UNDEFINED);
1842 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1844 | function_arglist_common_reparse REPARSE SCM_ARG
1846 $$ = check_scheme_arg (parser, @3,
1849 | function_arglist_common_reparse REPARSE lyric_element_music
1851 $$ = check_scheme_arg (parser, @3,
1854 | function_arglist_common_reparse REPARSE pitch_or_music
1856 if (scm_is_true (scm_call_1 ($2, $3)))
1857 $$ = scm_cons ($3, $1);
1859 $$ = check_scheme_arg (parser, @3,
1860 make_music_from_simple
1864 | function_arglist_common_reparse REPARSE bare_number_common
1866 $$ = check_scheme_arg (parser, @3,
1869 | function_arglist_common_reparse REPARSE duration_length
1871 $$ = check_scheme_arg (parser, @3,
1874 | function_arglist_common_reparse REPARSE symbol_list_arg
1876 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1880 function_arglist_common_reparse:
1881 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1884 SCM res = try_string_variants ($1, $3);
1885 if (!SCM_UNBNDP (res))
1886 if (scm_is_pair (res))
1887 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1889 MYREPARSE (@3, $1, SCM_ARG, res);
1890 else if (scm_is_true
1892 ($1, make_music_from_simple (parser, @3, $3))))
1893 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1895 // This is going to flag a syntax error, we
1896 // know the predicate to be false.
1897 MYREPARSE (@3, $1, SCM_ARG, $3);
1899 | EXPECT_SCM function_arglist_optional pitch
1904 ($1, make_music_from_simple
1906 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
1908 MYREPARSE (@3, $1, SCM_ARG, $3);
1910 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
1915 ($1, make_music_from_simple
1917 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
1919 MYREPARSE (@3, $1, SCM_ARG, $3);
1921 | EXPECT_SCM function_arglist_optional STRING
1924 SCM res = try_string_variants ($1, $3);
1925 if (!SCM_UNBNDP (res))
1926 if (scm_is_pair (res))
1927 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1929 MYREPARSE (@3, $1, SCM_ARG, res);
1930 else if (scm_is_true
1932 ($1, make_music_from_simple (parser, @3, $3))))
1933 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1935 // This is going to flag a syntax error, we
1936 // know the predicate to be false.
1937 MYREPARSE (@3, $1, SCM_ARG, $3);
1939 | EXPECT_SCM function_arglist_optional full_markup
1942 if (scm_is_true (scm_call_1 ($1, $3)))
1943 MYREPARSE (@3, $1, SCM_ARG, $3);
1944 else if (scm_is_true
1946 ($1, make_music_from_simple (parser, @3, $3))))
1947 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1949 // This is going to flag a syntax error, we
1950 // know the predicate to be false.
1951 MYREPARSE (@3, $1, SCM_ARG, $3);
1953 | EXPECT_SCM function_arglist_optional UNSIGNED
1956 if (scm_is_true (scm_call_1 ($1, $3)))
1957 MYREPARSE (@3, $1, REAL, $3);
1959 SCM d = make_duration ($3);
1960 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
1961 MYREPARSE (@3, $1, REAL, $3);
1963 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
1966 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
1969 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
1971 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
1974 SCM n = scm_difference ($4, SCM_UNDEFINED);
1975 if (scm_is_true (scm_call_1 ($1, n)))
1976 MYREPARSE (@4, $1, REAL, n);
1978 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1979 t->set_property ("digit", $4);
1980 SCM m = t->unprotect ();
1981 if (scm_is_true (scm_call_1 ($1, m)))
1982 MYREPARSE (@4, $1, SCM_ARG, m);
1984 MYREPARSE (@4, $1, SCM_ARG, $4);
1988 | EXPECT_SCM function_arglist_optional '-' REAL
1991 SCM n = scm_difference ($4, SCM_UNDEFINED);
1992 MYREPARSE (@4, $1, REAL, n);
1996 function_arglist_optional:
1997 function_arglist_backup
1998 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2000 $$ = scm_cons (loc_on_music (@4, $1), $3);
2002 | function_arglist_skip_backup BACKUP
2005 function_arglist_skip_backup:
2006 function_arglist_backup
2007 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2009 $$ = scm_cons (loc_on_music (@3, $1), $3);
2013 music_function_call:
2014 MUSIC_FUNCTION function_arglist {
2015 $$ = MAKE_SYNTAX ("music-function", @$,
2022 /**/ { $$ = SCM_EOL; }
2023 | '=' simple_string {
2030 | repeated_music { $$ = $1; }
2031 | re_rhythmed_music { $$ = $1; }
2032 | complex_music_prefix music
2034 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
2038 complex_music_prefix:
2039 CONTEXT symbol optional_id optional_context_mod {
2040 Context_mod *ctxmod = unsmob_context_mod ($4);
2043 mods = ctxmod->get_mods ();
2044 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
2046 | NEWCONTEXT symbol optional_id optional_context_mod {
2047 Context_mod *ctxmod = unsmob_context_mod ($4);
2050 mods = ctxmod->get_mods ();
2051 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
2056 mode_changing_head grouped_music_list {
2057 if ($1 == ly_symbol2scm ("chords"))
2059 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
2065 parser->lexer_->pop_state ();
2067 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2068 Context_mod *ctxmod = unsmob_context_mod ($2);
2071 mods = ctxmod->get_mods ();
2072 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2073 if ($1 == ly_symbol2scm ("ChordNames"))
2075 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2077 parser->lexer_->pop_state ();
2083 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2084 parser->lexer_->push_note_state (nn);
2086 $$ = ly_symbol2scm ("notes");
2090 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2091 parser->lexer_->push_note_state (nn);
2093 $$ = ly_symbol2scm ("drums");
2096 parser->lexer_->push_figuredbass_state ();
2098 $$ = ly_symbol2scm ("figures");
2101 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2102 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2103 nn = parser->lexer_->lookup_identifier ("pitchnames");
2104 parser->lexer_->push_chord_state (nn);
2105 $$ = ly_symbol2scm ("chords");
2109 { parser->lexer_->push_lyric_state ();
2110 $$ = ly_symbol2scm ("lyrics");
2114 mode_changing_head_with_context:
2116 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2117 parser->lexer_->push_note_state (nn);
2119 $$ = ly_symbol2scm ("DrumStaff");
2122 parser->lexer_->push_figuredbass_state ();
2124 $$ = ly_symbol2scm ("FiguredBass");
2127 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2128 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2129 nn = parser->lexer_->lookup_identifier ("pitchnames");
2130 parser->lexer_->push_chord_state (nn);
2131 $$ = ly_symbol2scm ("ChordNames");
2134 { parser->lexer_->push_lyric_state ();
2135 $$ = ly_symbol2scm ("Lyrics");
2140 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2143 /* Can also use music at the expensive of two S/Rs similar to
2144 \repeat \alternative */
2145 parser->lexer_->pop_state ();
2147 $$ = scm_cons ($3, SCM_EOL);
2149 | new_lyrics ADDLYRICS {
2150 parser->lexer_->push_lyric_state ();
2152 parser->lexer_->pop_state ();
2153 $$ = scm_cons ($4, $1);
2158 composite_music new_lyrics {
2159 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2161 | LYRICSTO simple_string {
2162 parser->lexer_->push_lyric_state ();
2164 parser->lexer_->pop_state ();
2165 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2170 CHANGE symbol '=' simple_string {
2171 $$ = MAKE_SYNTAX ("context-change", @$, $2, $4);
2178 $$ = scm_reverse_x ($1, SCM_EOL);
2180 | symbol_list_rev property_path {
2181 $$ = scm_reverse_x ($1, $2);
2187 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2190 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2192 | OVERRIDE property_path '=' scalar {
2193 if (scm_ilength ($2) < 2) {
2194 parser->parser_error (@2, _("bad grob property path"));
2197 $$ = scm_cons (ly_symbol2scm ("push"),
2198 scm_cons2 (scm_car ($2),
2203 | REVERT revert_arg {
2204 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2208 // This is all quite awkward for the sake of substantial backward
2209 // compatibility while at the same time allowing a more "natural" form
2210 // of specification not separating grob specification from grob
2211 // property path. The purpose of this definition of revert_arg is to
2212 // allow the symbol list which specifies grob and property to revert
2213 // to be optionally be split into two parts after the grob (which in
2214 // this case is just the first element of the list). symbol_list_part
2215 // is only one path component, but it can be parsed without lookahead,
2216 // so we can follow it with a synthetic BACKUP token when needed. If
2217 // the first symbol_list_part already contains multiple elements (only
2218 // possible if a Scheme expression provides them), we just parse for
2219 // additional elements introduced by '.', which is what the
2220 // SYMBOL_LIST backup in connection with the immediately following
2221 // rule using symbol_list_arg does.
2223 // As long as we don't have our coffers filled with both grob and at
2224 // least one grob property specification, the rest of the required
2225 // symbol list chain may be provided either with or without a leading
2226 // dot. This is for both allowing the traditional
2227 // \revert Accidental #'color
2228 // as well as well as the "naive" form
2229 // \revert Accidental.color
2232 revert_arg_backup BACKUP symbol_list_arg
2241 if (scm_is_null ($1)
2242 || scm_is_null (scm_cdr ($1)))
2243 MYBACKUP (SCM_ARG, $1, @1);
2245 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2249 // revert_arg_part delivers results in reverse
2252 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2254 $$ = scm_append_x (scm_list_2 ($5, $3));
2256 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2258 $$ = scm_append_x (scm_list_2 ($4, $3));
2263 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2264 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2266 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2267 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2268 | DENIES { $$ = ly_symbol2scm ("denies"); }
2270 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2271 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2272 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2273 | NAME { $$ = ly_symbol2scm ("context-name"); }
2277 property_operation { $$ = $1; }
2278 | context_def_mod STRING {
2279 $$ = scm_list_2 ($1, $2);
2281 | context_def_mod embedded_scm
2283 if (!scm_is_string ($2)
2284 && ly_symbol2scm ("consists") != $1
2285 && ly_symbol2scm ("remove") != $1)
2288 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2292 $$ = scm_list_2 ($1, $2);
2297 // If defined, at least two members.
2301 SCM l = scm_reverse_x ($1, SCM_EOL);
2304 (scm_object_property (scm_car (l),
2305 ly_symbol2scm ("is-grob?"))))
2306 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2307 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2308 parser->parser_error (@1, _ ("bad grob property path"));
2315 // If defined, at least three members
2319 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2321 parser->parser_error (@1, _ ("bad grob property path"));
2325 | grob_prop_spec property_path
2327 if (!SCM_UNBNDP ($1)) {
2328 $$ = scm_append_x (scm_list_2 ($1, $2));
2329 if (scm_is_null (scm_cddr ($$))) {
2330 parser->parser_error (@$, _ ("bad grob property path"));
2338 // Exactly two elements or undefined
2342 SCM l = scm_reverse_x ($1, SCM_EOL);
2343 switch (scm_ilength (l)) {
2345 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2349 parser->parser_error (@1, _ ("bad context property path"));
2356 simple_music_property_def:
2357 OVERRIDE grob_prop_path '=' scalar {
2358 if (SCM_UNBNDP ($2))
2361 $$ = scm_list_5 (scm_car ($2),
2362 ly_symbol2scm ("OverrideProperty"),
2368 | REVERT simple_revert_context revert_arg {
2369 $$ = scm_list_4 ($2,
2370 ly_symbol2scm ("RevertProperty"),
2374 | SET context_prop_spec '=' scalar {
2375 if (SCM_UNBNDP ($2))
2378 $$ = scm_list_4 (scm_car ($2),
2379 ly_symbol2scm ("PropertySet"),
2383 | UNSET context_prop_spec {
2384 if (SCM_UNBNDP ($2))
2387 $$ = scm_list_3 (scm_car ($2),
2388 ly_symbol2scm ("PropertyUnset"),
2394 // This is all quite awkward for the sake of substantial backward
2395 // compatibility while at the same time allowing a more "natural" form
2396 // of specification not separating grob specification from grob
2397 // property path. The purpose of this definition of
2398 // simple_revert_context is to allow the symbol list which specifies
2399 // grob and property to revert to be optionally be split into two
2400 // parts after the grob (which may be preceded by a context
2401 // specification, a case which we distinguish by checking whether the
2402 // first symbol is a valid grob symbol instead).
2404 // See revert_arg above for the main work horse of this arrangement.
2405 // simple_revert_context just caters for the context and delegates the
2406 // rest of the job to revert_arg.
2408 simple_revert_context:
2411 $1 = scm_reverse_x ($1, SCM_EOL);
2412 if (scm_is_null ($1)
2414 (scm_object_property (scm_car ($1),
2415 ly_symbol2scm ("is-grob?")))) {
2416 $$ = ly_symbol2scm ("Bottom");
2417 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2420 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2427 simple_music_property_def {
2428 if (SCM_UNBNDP ($1))
2429 $$ = MAKE_SYNTAX ("void-music", @1);
2431 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2442 simple_string: STRING {
2447 if (scm_is_string ($1)) {
2450 parser->parser_error (@1, (_ ("simple string expected")));
2451 $$ = scm_string (SCM_EOL);
2458 $$ = scm_string_to_symbol ($1);
2462 // This is a bit of overkill but makes the same
2463 // routine responsible for all symbol interpretations.
2464 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2466 if (SCM_UNBNDP ($$))
2468 parser->parser_error (@1, (_ ("symbol expected")));
2469 // Generate a unique symbol in case it is used
2470 // for an assignment or similar
2471 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2481 // The following is a rather defensive variant of admitting
2482 // negative numbers: the grammar would permit number_factor or
2483 // even number_expression. However, function arguments allow
2484 // only this simple kind of negative number, so to have things
2485 // like \tweak and \override behave reasonably similar, it
2486 // makes sense to rule out things like -- which are rather an
2487 // accent in function argument contexts.
2490 $$ = scm_difference ($2, SCM_UNDEFINED);
2496 simple_element post_events {
2497 // Let the rhythmic music iterator sort this mess out.
2498 if (scm_is_pair ($2)) {
2499 unsmob_music ($$)->set_property ("articulations",
2500 scm_reverse_x ($2, SCM_EOL));
2503 | CHORD_REPETITION optional_notemode_duration post_events {
2505 i.set_location (@1, @3);
2506 $$ = MAKE_SYNTAX ("repetition-chord", i,
2507 $2, scm_reverse_x ($3, SCM_EOL));
2509 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2511 i.set_location (@1, @3);
2512 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2513 scm_reverse_x ($3, SCM_EOL));
2516 | note_chord_element
2521 chord_body optional_notemode_duration post_events
2523 Music *m = unsmob_music ($1);
2524 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2525 SCM es = m->get_property ("elements");
2526 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2528 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2529 unsmob_music (scm_car (s))->set_property ("duration", dur);
2530 es = ly_append2 (es, postevs);
2532 m-> set_property ("elements", es);
2534 $$ = m->self_scm ();
2539 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2541 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2545 chord_body_elements:
2546 /* empty */ { $$ = SCM_EOL; }
2547 | chord_body_elements chord_body_element {
2548 if (!SCM_UNBNDP ($2))
2549 $$ = scm_cons ($2, $1);
2554 pitch exclamations questions octave_check post_events
2556 bool q = to_boolean ($3);
2557 bool ex = to_boolean ($2);
2561 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2562 n->set_property ("pitch", $1);
2564 n->set_property ("cautionary", SCM_BOOL_T);
2566 n->set_property ("force-accidental", SCM_BOOL_T);
2568 if (scm_is_pair (post)) {
2569 SCM arts = scm_reverse_x (post, SCM_EOL);
2570 n->set_property ("articulations", arts);
2572 if (scm_is_number (check))
2574 int q = scm_to_int (check);
2575 n->set_property ("absolute-octave", scm_from_int (q-1));
2578 $$ = n->unprotect ();
2580 | DRUM_PITCH post_events {
2581 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2582 n->set_property ("drum-type", $1);
2584 if (scm_is_pair ($2)) {
2585 SCM arts = scm_reverse_x ($2, SCM_EOL);
2586 n->set_property ("articulations", arts);
2588 $$ = n->unprotect ();
2590 | music_function_chord_body
2592 Music *m = unsmob_music ($1);
2594 while (m && m->is_mus_type ("music-wrapper-music")) {
2595 $$ = m->get_property ("element");
2596 m = unsmob_music ($$);
2599 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2600 parser->parser_error (@$, _ ("not a rhythmic event"));
2606 music_function_chord_body:
2611 event_function_event:
2612 EVENT_FUNCTION function_arglist {
2613 $$ = MAKE_SYNTAX ("music-function", @$,
2622 | post_events post_event {
2624 if (Music *m = unsmob_music ($2))
2626 if (m->is_mus_type ("post-event-wrapper"))
2628 for (SCM p = m->get_property ("elements");
2632 $$ = scm_cons (scm_car (p), $$);
2636 $$ = scm_cons ($2, $$);
2642 post_event_nofinger:
2643 direction_less_event {
2646 | script_dir music_function_call {
2648 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2649 parser->parser_error (@2, _ ("post-event expected"));
2650 $$ = SCM_UNSPECIFIED;
2651 } else if (!SCM_UNBNDP ($1))
2653 unsmob_music ($$)->set_property ("direction", $1);
2657 if (!parser->lexer_->is_lyric_state ())
2658 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2659 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2662 if (!parser->lexer_->is_lyric_state ())
2663 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2664 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2666 | script_dir direction_reqd_event {
2667 if (!SCM_UNBNDP ($1))
2669 Music *m = unsmob_music ($2);
2670 m->set_property ("direction", $1);
2674 | script_dir direction_less_event {
2675 if (!SCM_UNBNDP ($1))
2677 Music *m = unsmob_music ($2);
2678 m->set_property ("direction", $1);
2685 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2690 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2701 string_number_event:
2703 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2704 s->set_property ("string-number", $1);
2705 $$ = s->unprotect ();
2709 direction_less_event:
2711 | EVENT_IDENTIFIER {
2715 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2716 a->set_property ("tremolo-type", $1);
2717 $$ = a->unprotect ();
2719 | event_function_event
2722 direction_reqd_event:
2726 | script_abbreviation {
2727 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2728 if (scm_is_string (s)) {
2729 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2730 a->set_property ("articulation-type", s);
2731 $$ = a->unprotect ();
2733 Music *original = unsmob_music (s);
2734 if (original && original->is_mus_type ("post-event")) {
2735 Music *a = original->clone ();
2736 a->set_spot (parser->lexer_->override_input (@$));
2737 $$ = a->unprotect ();
2739 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
2740 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
2747 /**/ { $$ = SCM_EOL; }
2748 | '=' quotes { $$ = $2; }
2762 $$ = scm_from_int (1);
2765 $$ = scm_oneplus ($1);
2771 $$ = scm_from_int (-1);
2774 $$ = scm_oneminus ($1);
2779 NOTENAME_PITCH quotes {
2780 if (!scm_is_eq (SCM_INUM0, $2))
2782 Pitch p = *unsmob_pitch ($1);
2783 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2784 $$ = p.smobbed_copy ();
2794 TONICNAME_PITCH quotes {
2795 if (!scm_is_eq (SCM_INUM0, $2))
2797 Pitch p = *unsmob_pitch ($1);
2798 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2799 $$ = p.smobbed_copy ();
2806 | PITCH_IDENTIFIER quotes {
2807 if (!scm_is_eq (SCM_INUM0, $2))
2809 Pitch p = *unsmob_pitch ($1);
2810 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2811 $$ = p.smobbed_copy ();
2818 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2819 t->set_property ("text", $1);
2820 $$ = t->unprotect ();
2823 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2824 t->set_property ("text",
2825 make_simple_markup ($1));
2826 $$ = t->unprotect ();
2830 Music *m = unsmob_music ($1);
2831 if (m && m->is_mus_type ("post-event"))
2833 else if (Text_interface::is_markup ($1)) {
2834 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2835 t->set_property ("text", $1);
2836 $$ = t->unprotect ();
2838 parser->parser_error (@1, _ ("not an articulation"));
2844 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2845 t->set_property ("digit", $1);
2846 $$ = t->unprotect ();
2850 script_abbreviation:
2852 $$ = scm_from_locale_string ("Hat");
2855 $$ = scm_from_locale_string ("Plus");
2858 $$ = scm_from_locale_string ("Dash");
2861 $$ = scm_from_locale_string ("Bang");
2864 $$ = scm_from_locale_string ("Larger");
2867 $$ = scm_from_locale_string ("Dot");
2870 $$ = scm_from_locale_string ("Underscore");
2875 '_' { $$ = scm_from_int (DOWN); }
2876 | '^' { $$ = scm_from_int (UP); }
2877 | '-' { $$ = SCM_UNDEFINED; }
2881 multiplied_duration {
2886 maybe_notemode_duration:
2890 | multiplied_duration {
2892 parser->default_duration_ = *unsmob_duration ($$);
2897 optional_notemode_duration:
2898 maybe_notemode_duration
2900 if (SCM_UNBNDP ($$))
2901 $$ = parser->default_duration_.smobbed_copy ();
2907 $$ = make_duration ($1, scm_to_int ($2));
2908 if (SCM_UNBNDP ($$))
2910 parser->parser_error (@1, _ ("not a duration"));
2911 $$ = Duration ().smobbed_copy ();
2914 | DURATION_IDENTIFIER dots {
2915 Duration *d = unsmob_duration ($1);
2916 Duration k (d->duration_log (),
2917 d->dot_count () + scm_to_int ($2));
2918 k = k.compressed (d->factor ());
2919 scm_remember_upto_here_1 ($1);
2920 $$ = k.smobbed_copy ();
2924 multiplied_duration:
2928 | multiplied_duration '*' UNSIGNED {
2929 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2931 | multiplied_duration '*' FRACTION {
2932 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2934 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2943 $$ = scm_oneplus ($1);
2952 if (SCM_UNBNDP (make_duration ($2)))
2953 parser->parser_error (@2, _ ("not a duration"));
2959 UNSIGNED { $$ = $1; }
2960 | STRING { $$ = $1; }
2961 | full_markup { $$ = $1; }
2964 // as an integer, it needs to be non-negative, and otherwise
2965 // it needs to be suitable as a markup.
2966 if (scm_is_integer ($1)
2967 ? scm_is_true (scm_negative_p ($1))
2968 : !Text_interface::is_markup ($1))
2970 parser->parser_error (@1, _ ("bass number expected"));
2976 figured_bass_alteration:
2977 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2978 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2979 | '!' { $$ = scm_from_int (0); }
2984 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2985 $$ = bfr->unprotect ();
2988 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2989 $$ = bfr->self_scm ();
2991 if (scm_is_number ($1))
2992 bfr->set_property ("figure", $1);
2993 else if (Text_interface::is_markup ($1))
2994 bfr->set_property ("text", $1);
3000 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3002 | bass_figure figured_bass_alteration {
3003 Music *m = unsmob_music ($1);
3004 if (scm_to_double ($2)) {
3005 SCM salter = m->get_property ("alteration");
3006 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3007 m->set_property ("alteration",
3008 scm_sum (alter, $2));
3010 m->set_property ("alteration", scm_from_int (0));
3013 | bass_figure figured_bass_modification {
3014 Music *m = unsmob_music ($1);
3015 m->set_property ($2, SCM_BOOL_T);
3020 figured_bass_modification:
3022 $$ = ly_symbol2scm ("augmented");
3025 $$ = ly_symbol2scm ("no-continuation");
3028 $$ = ly_symbol2scm ("diminished");
3031 $$ = ly_symbol2scm ("augmented-slash");
3041 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3049 | figure_list br_bass_figure {
3050 $$ = scm_cons ($2, $1);
3055 FIGURE_OPEN figure_list FIGURE_CLOSE {
3056 $$ = scm_reverse_x ($2, SCM_EOL);
3062 /**/ { $$ = SCM_BOOL_F; }
3063 | REST { $$ = SCM_BOOL_T; }
3067 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3068 if (!parser->lexer_->is_note_state ())
3069 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3070 if (!SCM_UNBNDP ($2)
3072 || scm_is_number ($4)
3075 || scm_is_pair ($7))
3078 if (scm_is_true ($6))
3079 n = MY_MAKE_MUSIC ("RestEvent", @$);
3081 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3083 n->set_property ("pitch", $1);
3084 if (SCM_UNBNDP ($5))
3085 n->set_property ("duration",
3086 parser->default_duration_.smobbed_copy ());
3088 n->set_property ("duration", $5);
3090 if (scm_is_number ($4))
3092 int q = scm_to_int ($4);
3093 n->set_property ("absolute-octave", scm_from_int (q-1));
3096 if (to_boolean ($3))
3097 n->set_property ("cautionary", SCM_BOOL_T);
3098 if (to_boolean ($2) || to_boolean ($3))
3099 n->set_property ("force-accidental", SCM_BOOL_T);
3100 if (scm_is_pair ($7))
3101 n->set_property ("articulations",
3102 scm_reverse_x ($7, SCM_EOL));
3103 $$ = n->unprotect ();
3106 | simple_chord_elements post_events {
3107 if (scm_is_pair ($2)) {
3108 if (unsmob_pitch ($1))
3109 $1 = make_chord_elements (@1,
3111 parser->default_duration_.smobbed_copy (),
3114 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3116 $$ = MAKE_SYNTAX ("event-chord", @1, elts);
3117 } else if (!unsmob_pitch ($1))
3118 $$ = MAKE_SYNTAX ("event-chord", @1, $1);
3119 // A mere pitch drops through.
3124 DRUM_PITCH optional_notemode_duration {
3125 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3126 n->set_property ("duration", $2);
3127 n->set_property ("drum-type", $1);
3129 $$ = n->unprotect ();
3131 | RESTNAME optional_notemode_duration {
3133 if (ly_scm2string ($1) == "s") {
3135 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3138 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3141 ev->set_property ("duration", $2);
3142 $$ = ev->unprotect ();
3146 // Can return a single pitch rather than a list.
3147 simple_chord_elements:
3149 if (!parser->lexer_->is_chord_state ())
3150 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3153 | figure_spec optional_notemode_duration {
3154 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3156 unsmob_music (scm_car (s))->set_property ("duration", $2);
3164 if (!parser->lexer_->is_lyric_state ())
3165 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3169 if (!parser->lexer_->is_lyric_state ())
3170 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3176 lyric_element_music:
3177 lyric_element optional_notemode_duration post_events {
3178 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3179 if (scm_is_pair ($3))
3180 unsmob_music ($$)->set_property
3181 ("articulations", scm_reverse_x ($3, SCM_EOL));
3185 // Can return a single pitch rather than a list.
3187 steno_tonic_pitch maybe_notemode_duration {
3188 if (SCM_UNBNDP ($2))
3191 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3193 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3194 SCM its = scm_reverse_x ($4, SCM_EOL);
3195 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3203 | chord_items chord_item {
3204 $$ = scm_cons ($2, $$);
3210 $$ = ly_symbol2scm ("chord-colon");
3213 $$ = ly_symbol2scm ("chord-caret");
3215 | CHORD_SLASH steno_tonic_pitch {
3216 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3218 | CHORD_BASS steno_tonic_pitch {
3219 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3228 $$ = scm_reverse_x ($1, SCM_EOL);
3236 step_number { $$ = scm_cons ($1, SCM_EOL); }
3237 | step_numbers '.' step_number {
3238 $$ = scm_cons ($3, $$);
3244 $$ = make_chord_step ($1, 0);
3247 $$ = make_chord_step ($1, SHARP_ALTERATION);
3249 | UNSIGNED CHORD_MINUS {
3250 $$ = make_chord_step ($1, FLAT_ALTERATION);
3258 | unsigned_number '-' unsigned_number {
3259 $$ = scm_cons ($1, $3);
3266 TODO: should deprecate in favor of Scheme?
3270 number_expression '+' number_term {
3271 $$ = scm_sum ($1, $3);
3273 | number_expression '-' number_term {
3274 $$ = scm_difference ($1, $3);
3283 | number_factor '*' number_factor {
3284 $$ = scm_product ($1, $3);
3286 | number_factor '/' number_factor {
3287 $$ = scm_divide ($1, $3);
3292 '-' number_factor { /* %prec UNARY_MINUS */
3293 $$ = scm_difference ($2, SCM_UNDEFINED);
3301 | REAL NUMBER_IDENTIFIER
3303 $$ = scm_product ($1, $2);
3310 | UNSIGNED NUMBER_IDENTIFIER {
3311 $$ = scm_product ($1, $2);
3319 if (!scm_is_integer ($1)
3320 || scm_is_true (scm_negative_p ($1)))
3322 parser->parser_error (@1, _("not an unsigned integer"));
3328 if (!scm_is_integer ($1)
3329 || scm_is_true (scm_negative_p ($1)))
3331 parser->parser_error (@1, _("not an unsigned integer"));
3338 { $$ = SCM_UNDEFINED; }
3341 if (SCM_UNBNDP ($1))
3349 // This precedence rule is rather weird. It triggers when '!' is
3350 // encountered after a pitch, and is used for deciding whether to save
3351 // this instead for a figure modification. This should not actually
3352 // occur in practice as pitches and figures are generated in different
3353 // modes. Using a greedy (%right) precedence makes sure that we don't
3354 // get stuck in a wrong interpretation.
3355 { $$ = SCM_UNDEFINED; } %prec ':'
3358 if (SCM_UNBNDP ($1))
3367 { parser->lexer_->push_markup_state (); }
3370 parser->lexer_->pop_state ();
3376 { parser->lexer_->push_markup_state (); }
3379 parser->lexer_->pop_state ();
3385 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3387 | markup_head_1_list simple_markup
3389 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3390 @2, $1, scm_list_1 ($2)));
3400 if (Text_interface::is_markup ($1))
3401 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3402 else if (Text_interface::is_markup_list ($1))
3403 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3405 parser->parser_error (@1, _ ("not a markup"));
3406 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3413 markup_composed_list {
3416 | markup_uncomposed_list
3419 markup_uncomposed_list:
3420 markup_braced_list {
3423 | markup_command_list {
3424 $$ = scm_list_1 ($1);
3426 | markup_scm MARKUPLIST_IDENTIFIER
3431 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3432 parser->lexer_->push_note_state (nn);
3433 } '{' score_body '}' {
3434 unsmob_score ($4)->origin ()->set_spot (@$);
3435 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $4));
3436 parser->lexer_->pop_state ();
3440 markup_composed_list:
3441 markup_head_1_list markup_uncomposed_list {
3442 $$ = MAKE_SYNTAX ("composed-markup-list",
3448 '{' markup_braced_list_body '}' {
3449 $$ = scm_reverse_x ($2, SCM_EOL);
3453 markup_braced_list_body:
3454 /* empty */ { $$ = SCM_EOL; }
3455 | markup_braced_list_body markup {
3456 $$ = scm_cons ($2, $1);
3458 | markup_braced_list_body markup_list {
3459 $$ = scm_reverse_x ($2, $1);
3463 markup_command_list:
3464 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3465 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3469 markup_command_basic_arguments:
3470 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3471 $$ = scm_cons ($3, $2);
3473 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3474 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3476 | EXPECT_NO_MORE_ARGS {
3481 markup_command_list_arguments:
3482 markup_command_basic_arguments { $$ = $1; }
3483 | EXPECT_MARKUP markup_command_list_arguments markup {
3484 $$ = scm_cons ($3, $2);
3489 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3490 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3495 markup_head_1_item {
3496 $$ = scm_list_1 ($1);
3498 | markup_head_1_list markup_head_1_item {
3499 $$ = scm_cons ($2, $1);
3505 $$ = make_simple_markup ($1);
3508 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3509 parser->lexer_->push_note_state (nn);
3510 } '{' score_body '}' {
3511 unsmob_score ($4)->origin ()->set_spot (@$);
3512 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3513 parser->lexer_->pop_state ();
3515 | MARKUP_FUNCTION markup_command_basic_arguments {
3516 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3518 | markup_scm MARKUP_IDENTIFIER
3525 markup_head_1_list simple_markup
3527 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3528 @2, $1, scm_list_1 ($2)));
3538 Lily_parser::set_yydebug (bool x)
3544 Lily_parser::do_yyparse ()
3546 SCM retval = SCM_UNDEFINED;
3547 yyparse (this, &retval);
3557 It is a little strange to have this function in this file, but
3558 otherwise, we have to import music classes into the lexer.
3562 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3564 if (unsmob_book (sid)) {
3565 Book *book = unsmob_book (sid)->clone ();
3566 *destination = book->self_scm ();
3569 return BOOK_IDENTIFIER;
3570 } else if (scm_is_number (sid)) {
3572 return NUMBER_IDENTIFIER;
3573 } else if (unsmob_context_def (sid)) {
3574 Context_def *def= unsmob_context_def (sid)->clone ();
3576 *destination = def->self_scm ();
3579 return CONTEXT_DEF_IDENTIFIER;
3580 } else if (unsmob_context_mod (sid)) {
3581 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3583 return CONTEXT_MOD_IDENTIFIER;
3584 } else if (Music *mus = unsmob_music (sid)) {
3585 mus = mus->clone ();
3586 *destination = mus->self_scm ();
3587 bool is_event = mus->is_mus_type ("post-event");
3589 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3590 } else if (unsmob_pitch (sid)) {
3591 *destination = unsmob_pitch (sid)->smobbed_copy ();
3592 return PITCH_IDENTIFIER;
3593 } else if (unsmob_duration (sid)) {
3594 *destination = unsmob_duration (sid)->smobbed_copy ();
3595 return DURATION_IDENTIFIER;
3596 } else if (unsmob_output_def (sid)) {
3597 Output_def *p = unsmob_output_def (sid);
3600 *destination = p->self_scm ();
3602 return OUTPUT_DEF_IDENTIFIER;
3603 } else if (unsmob_score (sid)) {
3604 *destination = unsmob_score (sid)->clone ()->unprotect ();
3605 return SCM_IDENTIFIER;
3612 get_next_unique_context_id ()
3614 return scm_from_locale_string ("$uniqueContextId");
3619 get_next_unique_lyrics_context_id ()
3621 static int new_context_count;
3623 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3624 return scm_from_locale_string (s);
3627 // check_scheme_arg checks one argument with a given predicate for use
3628 // in an argument list and throws a syntax error if it is unusable.
3629 // The argument is prepended to the argument list in any case. After
3630 // throwing a syntax error, the argument list is terminated with #f as
3631 // its last cdr in order to mark it as uncallable while not losing
3632 // track of its total length.
3634 // There are a few special considerations: if optional argument disp
3635 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3636 // instead of arg in a prospective error message. This is useful if
3637 // arg is not the actual argument but rather a transformation of it.
3639 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3640 // and an error message using disp is produced unconditionally.
3642 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3643 SCM arg, SCM args, SCM pred, SCM disp)
3645 if (SCM_UNBNDP (arg))
3646 args = scm_cons (disp, args);
3648 args = scm_cons (arg, args);
3649 if (scm_is_true (scm_call_1 (pred, arg)))
3652 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3653 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3654 SCM_UNBNDP (disp) ? arg : disp);
3655 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3659 SCM loc_on_music (Input loc, SCM arg)
3661 if (Music *m = unsmob_music (arg))
3665 return m->unprotect ();
3671 try_string_variants (SCM pred, SCM str)
3673 // a matching predicate is always ok
3674 if (scm_is_true (scm_call_1 (pred, str)))
3676 // a symbol may be interpreted as a list of symbols if it helps
3677 if (scm_is_symbol (str)) {
3678 str = scm_list_1 (str);
3679 if (scm_is_true (scm_call_1 (pred, str)))
3681 return SCM_UNDEFINED;
3684 // If this cannot be a string representation of a symbol list,
3687 if (!is_regular_identifier (str, true))
3688 return SCM_UNDEFINED;
3690 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3691 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3692 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3694 // Let's attempt the symbol list interpretation first.
3696 if (scm_is_true (scm_call_1 (pred, str)))
3699 // If there is just one symbol in the list, we might interpret
3700 // it as a single symbol
3702 if (scm_is_null (scm_cdr (str)))
3704 str = scm_car (str);
3705 if (scm_is_true (scm_call_1 (pred, str)))
3709 return SCM_UNDEFINED;
3713 is_regular_identifier (SCM id, bool multiple)
3715 if (!scm_is_string (id))
3718 string str = ly_scm2string (id);
3720 bool middle = false;
3722 for (string::iterator it=str.begin(); it != str.end (); it++)
3725 if ((c >= 'a' && c <= 'z')
3726 || (c >= 'A' && c <= 'Z')
3729 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3738 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3740 if (unsmob_music (simple))
3742 if (parser->lexer_->is_note_state ()) {
3743 if (scm_is_symbol (simple)) {
3744 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3745 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3746 n->set_property ("drum-type", simple);
3747 return n->unprotect ();
3749 if (unsmob_pitch (simple)) {
3750 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3751 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3752 n->set_property ("pitch", simple);
3753 return n->unprotect ();
3756 } else if (parser->lexer_->is_lyric_state ()) {
3757 if (Text_interface::is_markup (simple))
3758 return MAKE_SYNTAX ("lyric-event", loc, simple,
3759 parser->default_duration_.smobbed_copy ());
3760 } else if (parser->lexer_->is_chord_state ()) {
3761 if (unsmob_pitch (simple))
3765 make_chord_elements (loc, simple,
3766 parser->default_duration_.smobbed_copy (),
3773 make_music_with_input (SCM name, Input where)
3775 Music *m = make_music_by_name (name);
3776 m->set_spot (where);
3781 make_simple_markup (SCM a)
3787 make_duration (SCM d, int dots)
3789 int t = scm_to_int (d);
3790 if (t > 0 && (t & (t-1)) == 0)
3791 return Duration (intlog2 (t), dots).smobbed_copy ();
3793 return SCM_UNDEFINED;
3797 make_chord_step (SCM step_scm, Rational alter)
3799 int step = scm_to_int (step_scm);
3802 alter += FLAT_ALTERATION;
3806 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3807 return m.smobbed_copy ();
3812 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3814 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3815 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3816 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3818 unsmob_music (scm_car (s))->set_spot (loc);
3824 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3826 Lily_lexer *lex = parser->lexer_;
3830 int tok = lex->pop_extra_token ();
3833 lex->prepare_for_next_token ();
3834 return lex->yylex ();