2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 Jan Nieuwenhuizen <janneke@gnu.org>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
24 #define YYERROR_VERBOSE 1
25 #define YYPARSE_PARAM my_lily_parser
26 #define YYLEX_PARAM my_lily_parser
27 #define PARSER ((Lily_parser *) my_lily_parser)
29 #define yyerror PARSER->parser_error
31 /* We use custom location type: Input objects */
33 #define YYLLOC_DEFAULT(Current,Rhs,N) \
34 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
39 /* We use SCMs to do strings, because it saves us the trouble of
40 deleting them. Let's hope that a stack overflow doesnt trigger a move
41 of the parse stack onto the heap. */
47 /* The above precedences tackle the shift/reduce problem
50 \repeat .. \alternative
52 \repeat { \repeat .. \alternative }
56 \repeat { \repeat } \alternative
62 /* ADDLYRICS needs to have lower precedence than argument scanning,
63 * or we won't be able to tell music apart from closed_music without
64 * lookahead in the context of function calls.
69 /* \default is only applied after exhausting function arguments */
71 %nonassoc FUNCTION_ARGLIST
73 /* expressions with units are permitted into argument lists */
75 %right PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
76 UNSIGNED REAL DURATION_IDENTIFIER
78 /* The above are the symbols that can start optional function arguments
79 that are recognized in the grammar rather than by predicate
82 %nonassoc NUMBER_IDENTIFIER
84 /* Number-unit expressions, where permitted, are concatenated into
98 %{ // -*-Fundamental-*-
103 * The rules for who is protecting what are very shady. Uniformise
106 * There are too many lexical modes?
117 #include "context-def.hh"
118 #include "context-mod.hh"
119 #include "dimensions.hh"
120 #include "file-path.hh"
122 #include "international.hh"
123 #include "lily-guile.hh"
124 #include "lily-lexer.hh"
125 #include "lily-parser.hh"
129 #include "output-def.hh"
130 #include "paper-book.hh"
131 #include "scm-hash.hh"
133 #include "text-interface.hh"
136 #define MYBACKUP(Token, Value, Location) \
138 if (yychar == YYEMPTY) \
141 PARSER->lexer_->push_extra_token (Token, Value); \
142 PARSER->lexer_->push_extra_token (BACKUP); \
144 PARSER->parser_error \
145 (Location, _("Too much lookahead")); \
154 Output_def *outputdef;
164 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
167 - Don't use lily module, create a new module instead.
168 - delay application of the function
170 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
171 scm_apply_0 (proc, args)
172 /* Syntactic Sugar. */
173 #define MAKE_SYNTAX(name, location, ...) \
174 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location), ##__VA_ARGS__, SCM_UNDEFINED));
175 #define START_MAKE_SYNTAX(name, ...) \
176 scm_list_n (ly_lily_module_constant (name), ##__VA_ARGS__, SCM_UNDEFINED)
177 #define FINISH_MAKE_SYNTAX(start, location, ...) \
178 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (PARSER->self_scm (), make_input (location), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
180 SCM get_next_unique_context_id ();
181 SCM get_next_unique_lyrics_context_id ();
188 #define _(x) gettext (x)
192 static Music *make_music_with_input (SCM name, Input where);
193 SCM check_scheme_arg (Lily_parser *parser, Input loc, SCM fallback,
194 SCM arg, SCM args, SCM pred);
195 SCM loc_on_music (Input loc, SCM arg);
196 SCM get_first_context_id (SCM type, Music *m);
197 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
198 SCM make_chord_step (int step, Rational alter);
199 SCM make_simple_markup (SCM a);
200 SCM try_unpack_lyrics (SCM pred, SCM arg);
201 bool is_duration (int t);
202 bool is_regular_identifier (SCM id);
203 bool ly_input_procedure_p (SCM x);
204 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
205 void set_music_properties (Music *p, SCM a);
209 /* The third option is an alias that will be used to display the
210 syntax error. Bison CVS now correctly handles backslash escapes.
212 FIXME: Bison needs to translate some of these, eg, STRING.
216 /* Keyword tokens with plain escaped name. */
217 %token ACCEPTS "\\accepts"
218 %token ADDLYRICS "\\addlyrics"
219 %token ALIAS "\\alias"
220 %token ALTERNATIVE "\\alternative"
222 %token BOOKPART "\\bookpart"
223 %token CHANGE "\\change"
224 %token CHORDMODE "\\chordmode"
225 %token CHORDS "\\chords"
226 %token CONSISTS "\\consists"
227 %token CONTEXT "\\context"
228 %token DEFAULT "\\default"
229 %token DEFAULTCHILD "\\defaultchild"
230 %token DENIES "\\denies"
231 %token DESCRIPTION "\\description"
232 %token DRUMMODE "\\drummode"
233 %token DRUMS "\\drums"
234 %token FIGUREMODE "\\figuremode"
235 %token FIGURES "\\figures"
236 %token GROBDESCRIPTIONS "\\grobdescriptions"
237 %token HEADER "\\header"
238 %token INVALID "\\version-error"
239 %token LAYOUT "\\layout"
240 %token LYRICMODE "\\lyricmode"
241 %token LYRICS "\\lyrics"
242 %token LYRICSTO "\\lyricsto"
243 %token MARKUP "\\markup"
244 %token MARKUPLIST "\\markuplist"
247 %token NOTEMODE "\\notemode"
248 %token OVERRIDE "\\override"
249 %token PAPER "\\paper"
250 %token REMOVE "\\remove"
251 %token REPEAT "\\repeat"
253 %token REVERT "\\revert"
254 %token SCORE "\\score"
255 %token SEQUENTIAL "\\sequential"
257 %token SIMULTANEOUS "\\simultaneous"
258 %token TEMPO "\\tempo"
260 %token UNSET "\\unset"
263 /* Keyword token exceptions. */
264 %token NEWCONTEXT "\\new"
267 /* Other string tokens. */
269 %token CHORD_BASS "/+"
270 %token CHORD_CARET "^"
271 %token CHORD_COLON ":"
272 %token CHORD_MINUS "-"
273 %token CHORD_SLASH "/"
274 %token ANGLE_OPEN "<"
275 %token ANGLE_CLOSE ">"
276 %token DOUBLE_ANGLE_OPEN "<<"
277 %token DOUBLE_ANGLE_CLOSE ">>"
278 %token E_BACKSLASH "\\"
279 %token E_ANGLE_CLOSE "\\>"
280 %token E_CHAR "\\C[haracter]"
282 %token E_EXCLAMATION "\\!"
283 %token E_BRACKET_OPEN "\\["
285 %token E_BRACKET_CLOSE "\\]"
286 %token E_ANGLE_OPEN "\\<"
292 If we give names, Bison complains.
294 %token FIGURE_CLOSE /* "\\>" */
295 %token FIGURE_OPEN /* "\\<" */
296 %token FIGURE_SPACE "_"
299 %token CHORDMODIFIERS
301 %token MULTI_MEASURE_REST
304 %token <i> E_UNSIGNED
305 %token <scm> UNSIGNED
307 /* Artificial tokens, for more generic function syntax */
308 %token <i> EXPECT_MARKUP "markup?"
309 %token <i> EXPECT_PITCH "ly:pitch?"
310 %token <i> EXPECT_DURATION "ly:duration?"
311 %token <scm> EXPECT_SCM "scheme?"
312 %token <scm> BACKUP "(backed-up?)"
313 %token <i> EXPECT_MARKUP_LIST "markup-list?"
314 %token <scm> EXPECT_OPTIONAL "optional?"
315 /* After the last argument. */
316 %token <i> EXPECT_NO_MORE_ARGS;
318 /* An artificial token for parsing embedded Lilypond */
319 %token <i> EMBEDDED_LILY "#{"
321 %token <scm> BOOK_IDENTIFIER
322 %token <scm> CHORDMODIFIER_PITCH
323 %token <scm> CHORD_MODIFIER
324 %token <scm> CHORD_REPETITION
325 %token <scm> CONTEXT_DEF_IDENTIFIER
326 %token <scm> CONTEXT_MOD_IDENTIFIER
327 %token <scm> DRUM_PITCH
328 %token <scm> PITCH_IDENTIFIER
329 %token <scm> DURATION_IDENTIFIER
330 %token <scm> EVENT_IDENTIFIER
331 %token <scm> EVENT_FUNCTION
332 %token <scm> FRACTION
333 %token <scm> LYRICS_STRING
334 %token <scm> LYRIC_MARKUP_IDENTIFIER
335 %token <scm> MARKUP_FUNCTION
336 %token <scm> MARKUP_LIST_FUNCTION
337 %token <scm> MARKUP_IDENTIFIER
338 %token <scm> MARKUPLIST_IDENTIFIER
339 %token <scm> MUSIC_FUNCTION
340 %token <scm> MUSIC_IDENTIFIER
341 %token <scm> NOTENAME_PITCH
342 %token <scm> NUMBER_IDENTIFIER
343 %token <scm> OUTPUT_DEF_IDENTIFIER
345 %token <scm> RESTNAME
346 %token <scm> SCM_FUNCTION
347 %token <scm> SCM_IDENTIFIER
348 %token <scm> SCM_TOKEN
349 %token <scm> SCORE_IDENTIFIER
351 %token <scm> STRING_IDENTIFIER
352 %token <scm> TONICNAME_PITCH
355 %type <book> book_block
356 %type <book> book_body
357 %type <book> bookpart_block
358 %type <book> bookpart_body
360 %type <i> bare_unsigned
361 %type <scm> figured_bass_alteration
363 %type <i> exclamations
364 %type <i> optional_rest
369 %type <i> tremolo_type
372 %type <scm> composite_music
373 %type <scm> grouped_music_list
374 %type <scm> braced_music_list
375 %type <scm> closed_music
377 %type <scm> music_bare
378 %type <scm> complex_music
379 %type <scm> complex_music_prefix
380 %type <scm> mode_changed_music
381 %type <scm> repeated_music
382 %type <scm> sequential_music
383 %type <scm> simple_music
384 %type <scm> simultaneous_music
385 %type <scm> chord_body
386 %type <scm> chord_body_element
387 %type <scm> command_element
388 %type <scm> command_event
389 %type <scm> context_modification
390 %type <scm> context_change
391 %type <scm> direction_less_event
392 %type <scm> direction_reqd_event
393 %type <scm> embedded_lilypond
394 %type <scm> event_chord
395 %type <scm> fingering
396 %type <scm> gen_text_def
397 %type <scm> music_property_def
398 %type <scm> note_chord_element
399 %type <scm> post_event
400 %type <scm> post_event_nofinger
401 %type <scm> re_rhythmed_music
402 %type <scm> simple_element
403 %type <scm> simple_music_property_def
404 %type <scm> start_symbol
405 %type <scm> string_number_event
406 %type <scm> tempo_event
408 %type <outputdef> output_def_body
409 %type <outputdef> output_def_head
410 %type <outputdef> output_def_head_with_mode_switch
411 %type <outputdef> output_def
412 %type <outputdef> paper_block
414 %type <scm> music_function_call
415 %type <scm> music_list
416 %type <scm> assignment_id
417 %type <scm> bare_number
418 %type <scm> bare_number_closed
419 %type <scm> unsigned_number
420 %type <scm> bass_figure
421 %type <scm> figured_bass_modification
422 %type <scm> br_bass_figure
423 %type <scm> bass_number
424 %type <scm> chord_body_elements
425 %type <scm> chord_item
426 %type <scm> chord_items
427 %type <scm> chord_separator
428 %type <scm> context_def_mod
429 %type <scm> context_def_spec_block
430 %type <scm> context_def_spec_body
431 %type <scm> context_mod
432 %type <scm> context_mod_list
433 %type <scm> context_prop_spec
434 %type <scm> direction_less_char
435 %type <scm> duration_length
436 %type <scm> embedded_scm
437 %type <scm> embedded_scm_arg
438 %type <scm> embedded_scm_arg_closed
439 %type <scm> embedded_scm_bare
440 %type <scm> embedded_scm_bare_arg
441 %type <scm> embedded_scm_closed
442 %type <scm> embedded_scm_chord_body
443 %type <scm> embedded_scm_event
444 %type <scm> event_function_event
445 %type <scm> figure_list
446 %type <scm> figure_spec
448 %type <scm> full_markup
449 %type <scm> full_markup_list
450 %type <scm> function_arglist
451 %type <scm> function_arglist_optional
452 %type <scm> function_arglist_backup
453 %type <scm> function_arglist_nonbackup
454 %type <scm> function_arglist_skip
455 %type <scm> function_arglist_bare
456 %type <scm> function_arglist_closed
457 %type <scm> function_arglist_closed_optional
458 %type <scm> function_arglist_common
459 %type <scm> function_arglist_closed_common
460 %type <scm> function_arglist_keep
461 %type <scm> function_arglist_closed_keep
462 %type <scm> identifier_init
464 %type <scm> lilypond_header
465 %type <scm> lilypond_header_body
466 %type <scm> lyric_element
467 %type <scm> lyric_markup
469 %type <scm> markup_braced_list
470 %type <scm> markup_braced_list_body
471 %type <scm> markup_composed_list
472 %type <scm> markup_command_list
473 %type <scm> markup_command_list_arguments
474 %type <scm> markup_command_basic_arguments
475 %type <scm> markup_head_1_item
476 %type <scm> markup_head_1_list
477 %type <scm> markup_list
478 %type <scm> markup_top
479 %type <scm> mode_changing_head
480 %type <scm> mode_changing_head_with_context
481 %type <scm> multiplied_duration
482 %type <scm> music_function_event
483 %type <scm> music_function_event_arglist
484 %type <scm> music_function_chord_body
485 %type <scm> music_function_chord_body_arglist
486 %type <scm> new_chord
487 %type <scm> new_lyrics
488 %type <scm> number_expression
489 %type <scm> number_factor
490 %type <scm> number_term
491 %type <scm> octave_check
492 %type <scm> optional_context_mod
493 %type <scm> optional_id
494 %type <scm> optional_notemode_duration
496 %type <scm> pitch_also_in_chords
497 %type <scm> post_events
498 %type <scm> property_operation
499 %type <scm> property_path property_path_revved
501 %type <scm> scalar_bare
502 %type <scm> scalar_closed
503 %type <scm> scm_function_call
504 %type <scm> scm_function_call_closed
505 %type <scm> script_abbreviation
506 %type <scm> simple_chord_elements
507 %type <scm> simple_markup
508 %type <scm> simple_string
509 %type <scm> steno_duration
510 %type <scm> steno_pitch
511 %type <scm> steno_tonic_pitch
512 %type <scm> step_number
513 %type <scm> step_numbers
515 %type <scm> tempo_range
517 %type <score> score_block
518 %type <score> score_body
523 /* We don't assign precedence to / and *, because we might need varied
524 prec levels in different prods */
533 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
534 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
535 } embedded_lilypond {
536 PARSER->lexer_->pop_state ();
537 PARSER->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
541 lilypond: /* empty */ { }
542 | lilypond toplevel_expression {
544 | lilypond assignment {
547 PARSER->error_level_ = 1;
550 PARSER->error_level_ = 1;
557 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
561 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
562 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
567 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
568 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
569 bookpart->unprotect ();
574 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
575 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
579 Music *music = unsmob_music ($1);
580 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
581 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
584 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
585 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
588 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
589 scm_call_2 (proc, PARSER->self_scm (), $1);
593 Output_def * od = $1;
595 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
596 id = ly_symbol2scm ("$defaultpaper");
597 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
598 id = ly_symbol2scm ("$defaultmidi");
599 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
600 id = ly_symbol2scm ("$defaultlayout");
602 PARSER->lexer_->set_identifier (id, od->self_scm ());
612 embedded_scm_bare_arg:
618 | context_modification
621 $$ = $1->self_scm ();
624 | context_def_spec_block
627 $$ = $1->self_scm ();
632 $$ = $1->self_scm ();
637 $$ = $1->self_scm ();
642 /* The generic version may end in music, or not */
650 embedded_scm_bare_arg
656 SCM_FUNCTION function_arglist {
657 $$ = MAKE_SYNTAX ("music-function", @$,
665 $$ = MAKE_SYNTAX ("void-music", @$);
668 | music music music_list {
669 $$ = MAKE_SYNTAX ("sequential-music", @$,
670 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
673 PARSER->error_level_ = 1;
675 | INVALID embedded_lilypond {
676 PARSER->error_level_ = 1;
681 lilypond_header_body:
683 $$ = get_header (PARSER);
684 PARSER->lexer_->add_scope ($$);
686 | lilypond_header_body assignment {
692 HEADER '{' lilypond_header_body '}' {
693 $$ = PARSER->lexer_->remove_scope ();
702 | LYRICS_STRING { $$ = $1; }
706 assignment_id '=' identifier_init {
707 PARSER->lexer_->set_identifier ($1, $3);
709 | assignment_id property_path '=' identifier_init {
710 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
711 PARSER->lexer_->set_identifier (path, $4);
714 TODO: devise standard for protection in parser.
716 The parser stack lives on the C-stack, which means that
717 all objects can be unprotected as soon as they're here.
727 $$ = $1->self_scm ();
731 $$ = $1->self_scm ();
735 $$ = $1->self_scm ();
739 $$ = $1->self_scm ();
742 | context_def_spec_block {
746 /* Hack: Create event-chord around standalone events.
747 Prevents the identifier from being interpreted as a post-event. */
748 Music *mus = unsmob_music ($1);
749 bool is_event = mus &&
750 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
755 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
757 | post_event_nofinger {
760 | number_expression {
775 | context_modification {
780 context_def_spec_block:
781 CONTEXT '{' context_def_spec_body '}'
787 context_def_spec_body:
789 $$ = Context_def::make_scm ();
790 unsmob_context_def ($$)->origin ()->set_spot (@$);
792 | CONTEXT_DEF_IDENTIFIER {
794 unsmob_context_def ($$)->origin ()->set_spot (@$);
796 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
797 Context_def*td = unsmob_context_def ($$);
799 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
800 SCM tag = scm_caar (p);
802 /* TODO: should make new tag "grob-definition" ? */
803 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
804 tag, scm_cons (scm_cdar (p), SCM_EOL)));
807 | context_def_spec_body context_mod {
808 unsmob_context_def ($$)->add_context_mod ($2);
810 | context_def_spec_body context_modification {
811 Context_def *td = unsmob_context_def ($$);
812 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
813 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
814 td->add_context_mod (scm_car (m));
822 BOOK '{' book_body '}' {
825 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
830 * Use 'handlers' like for toplevel-* stuff?
831 * grok \layout and \midi? */
835 init_papers (PARSER);
836 $$->origin ()->set_spot (@$);
837 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
838 $$->paper_->unprotect ();
839 push_paper (PARSER, $$->paper_);
840 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
841 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
842 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
843 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
846 $$ = unsmob_book ($1);
848 $$->origin ()->set_spot (@$);
849 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
851 | book_body paper_block {
854 set_paper (PARSER, $2);
856 | book_body bookpart_block {
858 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
859 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
860 bookpart->unprotect ();
862 | book_body score_block {
864 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
865 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
868 | book_body composite_music {
869 Music *music = unsmob_music ($2);
870 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
871 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
873 | book_body full_markup {
874 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
875 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
877 | book_body full_markup_list {
878 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
879 scm_call_2 (proc, $$->self_scm (), $2);
881 | book_body lilypond_header {
884 | book_body embedded_scm { }
887 $$->scores_ = SCM_EOL;
888 $$->bookparts_ = SCM_EOL;
893 BOOKPART '{' bookpart_body '}' {
895 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
902 $$->origin ()->set_spot (@$);
903 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
906 $$ = unsmob_book ($1);
908 $$->origin ()->set_spot (@$);
909 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
911 | bookpart_body paper_block {
915 | bookpart_body score_block {
917 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
918 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
921 | bookpart_body composite_music {
922 Music *music = unsmob_music ($2);
923 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
924 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
926 | bookpart_body full_markup {
927 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
928 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
930 | bookpart_body full_markup_list {
931 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
932 scm_call_2 (proc, $$->self_scm (), $2);
934 | bookpart_body lilypond_header {
937 | bookpart_body embedded_scm { }
938 | bookpart_body error {
940 $$->scores_ = SCM_EOL;
945 SCORE '{' score_body '}' {
953 SCM scorify = ly_lily_module_constant ("scorify-music");
954 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
956 // pass ownernship to C++ again.
957 $$ = unsmob_score (score);
959 $$->origin ()->set_spot (@$);
962 $$ = unsmob_score ($1);
964 $$->origin ()->set_spot (@$);
966 | score_body lilypond_header {
969 | score_body output_def {
970 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
972 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
977 $$->add_output_def ($2);
982 $$->error_found_ = true;
994 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
996 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
998 $$ = get_paper (PARSER);
1005 output_def_body '}' {
1008 PARSER->lexer_->remove_scope ();
1009 PARSER->lexer_->pop_state ();
1015 $$ = get_paper (PARSER);
1016 $$->input_origin_ = @$;
1017 PARSER->lexer_->add_scope ($$->scope_);
1020 Output_def *p = get_midi (PARSER);
1022 PARSER->lexer_->add_scope (p->scope_);
1025 Output_def *p = get_layout (PARSER);
1027 PARSER->lexer_->add_scope (p->scope_);
1032 output_def_head_with_mode_switch:
1034 PARSER->lexer_->push_initial_state ();
1040 output_def_head_with_mode_switch '{' {
1042 $$->input_origin_.set_spot (@$);
1044 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1047 Output_def *o = unsmob_output_def ($3);
1048 o->input_origin_.set_spot (@$);
1051 PARSER->lexer_->remove_scope ();
1052 PARSER->lexer_->add_scope (o->scope_);
1054 | output_def_body assignment {
1057 | output_def_body context_def_spec_block {
1058 assign_context_def ($$, $2);
1060 | output_def_body error {
1066 TEMPO steno_duration '=' tempo_range {
1067 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1069 | TEMPO scalar_closed steno_duration '=' tempo_range {
1070 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1073 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1078 The representation of a list is reversed to have efficient append. */
1084 | music_list music {
1085 $$ = scm_cons ($2, $1);
1087 | music_list embedded_scm {
1090 | music_list error {
1091 Music *m = MY_MAKE_MUSIC("Music", @$);
1093 m->set_property ("error-found", SCM_BOOL_T);
1094 $$ = scm_cons (m->self_scm (), $1);
1095 m->unprotect (); /* UGH */
1102 $$ = scm_reverse_x ($2, SCM_EOL);
1108 | composite_music %prec COMPOSITE
1113 REPEAT simple_string unsigned_number music
1115 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1117 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1119 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1124 SEQUENTIAL braced_music_list {
1125 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1127 | braced_music_list {
1128 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1133 SIMULTANEOUS braced_music_list {
1134 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1136 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1137 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1143 | music_property_def
1147 context_modification:
1148 WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1150 PARSER->lexer_->pop_state ();
1153 | WITH CONTEXT_MOD_IDENTIFIER
1157 | CONTEXT_MOD_IDENTIFIER
1163 optional_context_mod:
1167 | context_modification
1175 $$ = Context_mod ().smobbed_copy ();
1177 | context_mod_list context_mod {
1178 unsmob_context_mod ($1)->add_context_mod ($2);
1180 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1181 Context_mod *md = unsmob_context_mod ($2);
1183 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1192 /* Music that can be parsed without lookahead */
1195 | complex_music_prefix closed_music
1197 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1204 | grouped_music_list
1208 simultaneous_music { $$ = $1; }
1209 | sequential_music { $$ = $1; }
1212 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1213 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1214 and this rule returns the reversed list of arguments. */
1216 function_arglist_skip:
1217 function_arglist_common
1218 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1220 $$ = scm_cons ($1, $3);
1221 } %prec FUNCTION_ARGLIST
1222 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1224 $$ = scm_cons ($1, $3);
1225 } %prec FUNCTION_ARGLIST
1226 | EXPECT_SCM EXPECT_DURATION function_arglist_skip
1228 $$ = scm_cons ($1, $3);
1229 } %prec FUNCTION_ARGLIST
1233 function_arglist_nonbackup:
1234 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1235 $$ = scm_cons ($4, $3);
1237 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1238 $$ = scm_cons ($4, $3);
1240 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1242 $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
1244 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1246 $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
1248 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1250 $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
1255 function_arglist_keep:
1256 function_arglist_common
1257 | function_arglist_backup
1260 function_arglist_closed_keep:
1261 function_arglist_closed_common
1262 | function_arglist_backup
1265 function_arglist_backup:
1266 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1268 if (scm_is_true (scm_call_1 ($2, $4)))
1270 $$ = scm_cons ($4, $3);
1272 $$ = try_unpack_lyrics ($2, $4);
1273 if (!SCM_UNBNDP ($$))
1274 $$ = scm_cons ($$, $3);
1276 $$ = scm_cons (loc_on_music (@3, $1), $3);
1277 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1281 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1283 if (scm_is_true (scm_call_1 ($2, $4)))
1285 $$ = scm_cons ($4, $3);
1287 $$ = scm_cons (loc_on_music (@3, $1), $3);
1288 MYBACKUP (UNSIGNED, $4, @4);
1291 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1293 if (scm_is_true (scm_call_1 ($2, $4)))
1295 $$ = scm_cons ($4, $3);
1297 $$ = scm_cons (loc_on_music (@3, $1), $3);
1298 MYBACKUP (REAL, $4, @4);
1301 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1303 if (scm_is_true (scm_call_1 ($2, $4)))
1305 $$ = scm_cons ($4, $3);
1307 $$ = scm_cons (loc_on_music (@3, $1), $3);
1308 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1311 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1313 if (scm_is_true (scm_call_1 ($2, $4)))
1315 $$ = scm_cons ($4, $3);
1317 $$ = scm_cons (loc_on_music (@3, $1), $3);
1318 MYBACKUP (FRACTION, $4, @4);
1321 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1323 $$ = scm_cons ($4, $3);
1325 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1327 $$ = scm_cons ($4, $3);
1329 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1331 $$ = scm_cons ($1, $3);
1332 MYBACKUP(0, SCM_UNDEFINED, @3);
1337 function_arglist_common
1338 | function_arglist_nonbackup
1341 function_arglist_common:
1342 function_arglist_bare
1343 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1345 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1348 | EXPECT_SCM function_arglist_closed_optional bare_number
1350 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1353 | EXPECT_SCM function_arglist_closed_optional fraction
1355 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1360 function_arglist_closed:
1361 function_arglist_closed_common
1362 | function_arglist_nonbackup
1365 function_arglist_closed_common:
1366 function_arglist_bare
1367 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1369 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1372 | EXPECT_SCM function_arglist_closed_optional bare_number_closed
1374 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1377 | EXPECT_SCM function_arglist_closed_optional FRACTION
1379 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1384 function_arglist_optional:
1385 function_arglist_keep %prec FUNCTION_ARGLIST
1386 | function_arglist_backup BACKUP
1387 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1389 $$ = scm_cons ($1, $3);
1391 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1393 $$ = scm_cons ($1, $3);
1397 function_arglist_closed_optional:
1398 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1399 | function_arglist_backup BACKUP
1400 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1402 $$ = scm_cons ($1, $3);
1404 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1406 $$ = scm_cons ($1, $3);
1410 embedded_scm_closed:
1412 | scm_function_call_closed
1415 embedded_scm_arg_closed:
1416 embedded_scm_bare_arg
1417 | scm_function_call_closed
1421 scm_function_call_closed:
1422 SCM_FUNCTION function_arglist_closed {
1423 $$ = MAKE_SYNTAX ("music-function", @$,
1425 } %prec FUNCTION_ARGLIST
1428 function_arglist_bare:
1429 EXPECT_NO_MORE_ARGS {
1432 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1433 $$ = scm_cons ($3, $2);
1435 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1436 $$ = scm_cons ($3, $2);
1438 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1439 $$ = scm_cons ($1, $3);
1441 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1442 $$ = scm_cons ($1, $3);
1444 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1445 $$ = scm_cons ($1, $3);
1449 music_function_call:
1450 MUSIC_FUNCTION function_arglist {
1451 $$ = MAKE_SYNTAX ("music-function", @$,
1458 /**/ { $$ = SCM_EOL; }
1459 | '=' simple_string {
1466 | repeated_music { $$ = $1; }
1467 | re_rhythmed_music { $$ = $1; }
1468 | complex_music_prefix music
1470 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1474 complex_music_prefix:
1475 CONTEXT simple_string optional_id optional_context_mod {
1476 Context_mod *ctxmod = unsmob_context_mod ($4);
1479 mods = ctxmod->get_mods ();
1480 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1482 | NEWCONTEXT simple_string optional_id optional_context_mod {
1483 Context_mod *ctxmod = unsmob_context_mod ($4);
1486 mods = ctxmod->get_mods ();
1487 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1492 mode_changing_head grouped_music_list {
1493 if ($1 == ly_symbol2scm ("chords"))
1495 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1501 PARSER->lexer_->pop_state ();
1503 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1504 Context_mod *ctxmod = unsmob_context_mod ($2);
1507 mods = ctxmod->get_mods ();
1508 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1509 if ($1 == ly_symbol2scm ("ChordNames"))
1511 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1513 PARSER->lexer_->pop_state ();
1519 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1520 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1522 $$ = ly_symbol2scm ("notes");
1526 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1527 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1529 $$ = ly_symbol2scm ("drums");
1532 PARSER->lexer_->push_figuredbass_state ();
1534 $$ = ly_symbol2scm ("figures");
1537 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1538 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1539 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1540 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1541 $$ = ly_symbol2scm ("chords");
1545 { PARSER->lexer_->push_lyric_state ();
1546 $$ = ly_symbol2scm ("lyrics");
1550 mode_changing_head_with_context:
1552 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1553 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1555 $$ = ly_symbol2scm ("DrumStaff");
1558 PARSER->lexer_->push_figuredbass_state ();
1560 $$ = ly_symbol2scm ("FiguredBass");
1563 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1564 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1565 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1566 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1567 $$ = ly_symbol2scm ("ChordNames");
1570 { PARSER->lexer_->push_lyric_state ();
1571 $$ = ly_symbol2scm ("Lyrics");
1576 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1579 /* Can also use music at the expensive of two S/Rs similar to
1580 \repeat \alternative */
1581 PARSER->lexer_->pop_state ();
1583 $$ = scm_cons ($3, SCM_EOL);
1585 | new_lyrics ADDLYRICS {
1586 PARSER->lexer_->push_lyric_state ();
1588 PARSER->lexer_->pop_state ();
1589 $$ = scm_cons ($4, $1);
1594 composite_music new_lyrics {
1595 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1597 | LYRICSTO simple_string {
1598 PARSER->lexer_->push_lyric_state ();
1600 PARSER->lexer_->pop_state ();
1601 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1606 CHANGE STRING '=' STRING {
1607 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1612 property_path_revved:
1613 embedded_scm_closed {
1614 $$ = scm_cons ($1, SCM_EOL);
1616 | property_path_revved embedded_scm_closed {
1617 $$ = scm_cons ($2, $1);
1622 property_path_revved {
1623 $$ = scm_reverse_x ($1, SCM_EOL);
1629 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1630 scm_string_to_symbol ($1), $3);
1632 | UNSET simple_string {
1633 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1634 scm_string_to_symbol ($2));
1636 | OVERRIDE simple_string property_path '=' scalar {
1637 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1638 scm_string_to_symbol ($2), $5),
1641 | REVERT simple_string embedded_scm {
1642 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1643 scm_string_to_symbol ($2), $3);
1648 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1649 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1651 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1652 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1653 | DENIES { $$ = ly_symbol2scm ("denies"); }
1655 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1656 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1657 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1658 | NAME { $$ = ly_symbol2scm ("context-name"); }
1662 property_operation { $$ = $1; }
1663 | context_def_mod STRING {
1664 $$ = scm_list_2 ($1, $2);
1666 | context_def_mod embedded_scm {
1667 if (ly_symbol2scm ("consists") != $1)
1670 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1674 $$ = scm_list_2 ($1, $2);
1681 if (!is_regular_identifier ($1))
1683 @$.error (_("Grob name should be alphanumeric"));
1686 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1687 scm_string_to_symbol ($1));
1689 | simple_string '.' simple_string {
1690 $$ = scm_list_2 (scm_string_to_symbol ($1),
1691 scm_string_to_symbol ($3));
1695 simple_music_property_def:
1696 OVERRIDE context_prop_spec property_path '=' scalar {
1697 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1698 ly_symbol2scm ("OverrideProperty"),
1703 | REVERT context_prop_spec embedded_scm {
1704 $$ = scm_list_4 (scm_car ($2),
1705 ly_symbol2scm ("RevertProperty"),
1709 | SET context_prop_spec '=' scalar {
1710 $$ = scm_list_4 (scm_car ($2),
1711 ly_symbol2scm ("PropertySet"),
1715 | UNSET context_prop_spec {
1716 $$ = scm_list_3 (scm_car ($2),
1717 ly_symbol2scm ("PropertyUnset"),
1723 simple_music_property_def {
1724 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (PARSER->self_scm (), make_input (@$), $1));
1732 | STRING_IDENTIFIER {
1735 | string '+' string {
1736 $$ = scm_string_append (scm_list_2 ($1, $3));
1740 simple_string: STRING {
1746 | STRING_IDENTIFIER {
1761 | embedded_scm_bare {
1780 scm_function_call_closed
1785 /* TODO: Create a special case that avoids the creation of
1786 EventChords around simple_elements that have no post_events?
1788 simple_chord_elements post_events {
1789 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1792 /* why is this giving wrong start location? -ns
1794 i.set_location (@1, @2);
1795 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1797 | CHORD_REPETITION optional_notemode_duration post_events {
1799 i.set_location (@1, @3);
1800 $$ = MAKE_SYNTAX ("repetition-chord", i,
1801 PARSER->lexer_->chord_repetition_.last_chord_,
1802 PARSER->lexer_->chord_repetition_.repetition_function_,
1803 $2, scm_reverse_x ($3, SCM_EOL));
1805 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1807 i.set_location (@1, @3);
1808 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1809 scm_reverse_x ($3, SCM_EOL));
1812 /* note chord elements are memorized into
1813 PARSER->lexer_->chord_repetition_ so that the chord repetition
1814 mechanism copy them when a chord repetition symbol is found
1816 | note_chord_element {
1817 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
1823 chord_body optional_notemode_duration post_events
1825 Music *m = unsmob_music ($1);
1826 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1827 SCM es = m->get_property ("elements");
1828 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1830 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1831 unsmob_music (scm_car (s))->set_property ("duration", dur);
1832 es = ly_append2 (es, postevs);
1834 m-> set_property ("elements", es);
1836 $$ = m->self_scm ();
1841 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1843 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1847 chord_body_elements:
1848 /* empty */ { $$ = SCM_EOL; }
1849 | chord_body_elements chord_body_element {
1850 $$ = scm_cons ($2, $1);
1855 pitch exclamations questions octave_check post_events
1862 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1863 n->set_property ("pitch", $1);
1865 n->set_property ("cautionary", SCM_BOOL_T);
1866 if (ex % 2 || q % 2)
1867 n->set_property ("force-accidental", SCM_BOOL_T);
1869 if (scm_is_pair (post)) {
1870 SCM arts = scm_reverse_x (post, SCM_EOL);
1871 n->set_property ("articulations", arts);
1873 if (scm_is_number (check))
1875 int q = scm_to_int (check);
1876 n->set_property ("absolute-octave", scm_from_int (q-1));
1879 $$ = n->unprotect ();
1881 | DRUM_PITCH post_events {
1882 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1883 n->set_property ("drum-type", $1);
1885 if (scm_is_pair ($2)) {
1886 SCM arts = scm_reverse_x ($2, SCM_EOL);
1887 n->set_property ("articulations", arts);
1889 $$ = n->unprotect ();
1891 | music_function_chord_body
1894 /* We can't accept a music argument, not even a closed one,
1895 * immediately before chord_body_elements, otherwise a function \fun
1896 * with a signature of two music arguments can't be sorted out
1897 * properly in a construct like
1898 * <\fun { c } \fun { c } c>
1899 * The second call could be interpreted either as a chord constituent
1900 * or a music expression.
1903 music_function_chord_body_arglist:
1904 function_arglist_bare
1905 | EXPECT_SCM music_function_chord_body_arglist embedded_scm_chord_body
1907 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1912 embedded_scm_chord_body:
1913 embedded_scm_bare_arg
1914 | SCM_FUNCTION music_function_chord_body_arglist {
1915 $$ = MAKE_SYNTAX ("music-function", @$,
1918 | chord_body_element
1921 music_function_chord_body:
1922 MUSIC_FUNCTION music_function_chord_body_arglist {
1923 $$ = MAKE_SYNTAX ("music-function", @$,
1928 /* We could accept a closed music argument before the post events
1929 * indicated by a trailing argument list. For symmetry with chord
1930 * bodies and in order to avoid too tricky and complex behavior, we
1931 * refrain from doing so.
1933 music_function_event_arglist:
1934 function_arglist_bare
1935 | EXPECT_SCM music_function_event_arglist embedded_scm_event
1937 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1943 embedded_scm_bare_arg
1944 | SCM_FUNCTION music_function_event_arglist {
1945 $$ = MAKE_SYNTAX ("music-function", @$,
1951 music_function_event:
1952 MUSIC_FUNCTION music_function_event_arglist {
1953 $$ = MAKE_SYNTAX ("music-function", @$,
1958 event_function_event:
1959 EVENT_FUNCTION music_function_event_arglist {
1960 $$ = MAKE_SYNTAX ("music-function", @$,
1970 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1971 m->set_property ("span-direction", scm_from_int (START));
1972 $$ = m->unprotect();
1975 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1976 m->set_property ("span-direction", scm_from_int (STOP));
1977 $$ = m->unprotect ();
1980 $$ = MAKE_SYNTAX ("voice-separator", @$);
1983 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1985 Music *m = unsmob_music (pipe);
1990 $$ = m->unprotect ();
1993 $$ = MAKE_SYNTAX ("bar-check", @$);
2000 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2012 | post_events post_event {
2013 unsmob_music ($2)->set_spot (@2);
2014 $$ = scm_cons ($2, $$);
2018 post_event_nofinger:
2019 direction_less_event {
2022 | script_dir music_function_event {
2026 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2030 if (!PARSER->lexer_->is_lyric_state ())
2031 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2032 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2035 if (!PARSER->lexer_->is_lyric_state ())
2036 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2037 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2039 | script_dir direction_reqd_event {
2042 Music *m = unsmob_music ($2);
2043 m->set_property ("direction", scm_from_int ($1));
2047 | script_dir direction_less_event {
2050 Music *m = unsmob_music ($2);
2051 m->set_property ("direction", scm_from_int ($1));
2055 | string_number_event
2060 | script_dir fingering {
2063 Music *m = unsmob_music ($2);
2064 m->set_property ("direction", scm_from_int ($1));
2070 string_number_event:
2072 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2073 s->set_property ("string-number", scm_from_int ($1));
2074 $$ = s->unprotect ();
2078 direction_less_char:
2080 $$ = ly_symbol2scm ("bracketOpenSymbol");
2083 $$ = ly_symbol2scm ("bracketCloseSymbol");
2086 $$ = ly_symbol2scm ("tildeSymbol");
2089 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2092 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2095 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2098 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2101 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2104 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2107 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2111 direction_less_event:
2112 direction_less_char {
2113 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
2115 if (unsmob_music (predefd))
2117 m = unsmob_music (predefd)->clone ();
2122 m = MY_MAKE_MUSIC ("Music", @$);
2124 $$ = m->unprotect ();
2126 | EVENT_IDENTIFIER {
2130 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2131 a->set_property ("tremolo-type", scm_from_int ($1));
2132 $$ = a->unprotect ();
2134 | event_function_event
2137 direction_reqd_event:
2141 | script_abbreviation {
2142 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2143 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2144 if (scm_is_string (s))
2145 a->set_property ("articulation-type", s);
2146 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
2147 $$ = a->unprotect ();
2152 /**/ { $$ = SCM_EOL; }
2153 | '=' { $$ = scm_from_int (0); }
2154 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2155 | '=' sup_quotes { $$ = scm_from_int ($2); }
2180 | NOTENAME_PITCH sup_quotes {
2181 Pitch p = *unsmob_pitch ($1);
2182 p = p.transposed (Pitch ($2,0,0));
2183 $$ = p.smobbed_copy ();
2185 | NOTENAME_PITCH sub_quotes {
2186 Pitch p =* unsmob_pitch ($1);
2187 p = p.transposed (Pitch (-$2,0,0));
2188 $$ = p.smobbed_copy ();
2200 | TONICNAME_PITCH sup_quotes {
2201 Pitch p = *unsmob_pitch ($1);
2202 p = p.transposed (Pitch ($2,0,0));
2203 $$ = p.smobbed_copy ();
2205 | TONICNAME_PITCH sub_quotes {
2206 Pitch p = *unsmob_pitch ($1);
2208 p = p.transposed (Pitch (-$2,0,0));
2209 $$ = p.smobbed_copy ();
2220 pitch_also_in_chords:
2227 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2228 t->set_property ("text", $1);
2229 $$ = t->unprotect ();
2232 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2233 t->set_property ("text",
2234 make_simple_markup ($1));
2235 $$ = t->unprotect ();
2241 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2242 t->set_property ("digit", $1);
2243 $$ = t->unprotect ();
2247 script_abbreviation:
2249 $$ = scm_from_locale_string ("Hat");
2252 $$ = scm_from_locale_string ("Plus");
2255 $$ = scm_from_locale_string ("Dash");
2258 $$ = scm_from_locale_string ("Bar");
2261 $$ = scm_from_locale_string ("Larger");
2264 $$ = scm_from_locale_string ("Dot");
2267 $$ = scm_from_locale_string ("Underscore");
2274 | '-' { $$ = CENTER; }
2278 multiplied_duration {
2283 optional_notemode_duration:
2285 Duration dd = PARSER->default_duration_;
2286 $$ = dd.smobbed_copy ();
2288 | multiplied_duration {
2290 PARSER->default_duration_ = *unsmob_duration ($$);
2295 bare_unsigned dots {
2297 if (!is_duration ($1))
2298 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
2302 $$ = Duration (len, $2).smobbed_copy ();
2304 | DURATION_IDENTIFIER dots {
2305 Duration *d = unsmob_duration ($1);
2306 Duration k (d->duration_log (), d->dot_count () + $2);
2307 k = k.compressed (d->factor ());
2313 multiplied_duration:
2317 | multiplied_duration '*' bare_unsigned {
2318 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2320 | multiplied_duration '*' FRACTION {
2321 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2323 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2328 FRACTION { $$ = $1; }
2329 | UNSIGNED '/' UNSIGNED {
2330 $$ = scm_cons ($1, $3);
2347 | ':' bare_unsigned {
2348 if (!is_duration ($2))
2349 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2355 UNSIGNED { $$ = $1; }
2356 | STRING { $$ = $1; }
2357 | full_markup { $$ = $1; }
2360 figured_bass_alteration:
2361 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2362 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2363 | '!' { $$ = scm_from_int (0); }
2368 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2369 $$ = bfr->unprotect ();
2372 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2373 $$ = bfr->self_scm ();
2375 if (scm_is_number ($1))
2376 bfr->set_property ("figure", $1);
2377 else if (Text_interface::is_markup ($1))
2378 bfr->set_property ("text", $1);
2384 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2386 | bass_figure figured_bass_alteration {
2387 Music *m = unsmob_music ($1);
2388 if (scm_to_double ($2)) {
2389 SCM salter = m->get_property ("alteration");
2390 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2391 m->set_property ("alteration",
2392 scm_sum (alter, $2));
2394 m->set_property ("alteration", scm_from_int (0));
2397 | bass_figure figured_bass_modification {
2398 Music *m = unsmob_music ($1);
2399 if ($2 == ly_symbol2scm ("plus"))
2401 m->set_property ("augmented", SCM_BOOL_T);
2403 else if ($2 == ly_symbol2scm ("slash"))
2405 m->set_property ("diminished", SCM_BOOL_T);
2407 else if ($2 == ly_symbol2scm ("exclamation"))
2409 m->set_property ("no-continuation", SCM_BOOL_T);
2411 else if ($2 == ly_symbol2scm ("backslash"))
2413 m->set_property ("augmented-slash", SCM_BOOL_T);
2419 figured_bass_modification:
2421 $$ = ly_symbol2scm ("plus");
2424 $$ = ly_symbol2scm ("exclamation");
2427 $$ = ly_symbol2scm ("slash");
2430 $$ = ly_symbol2scm ("backslash");
2440 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2448 | figure_list br_bass_figure {
2449 $$ = scm_cons ($2, $1);
2454 FIGURE_OPEN figure_list FIGURE_CLOSE {
2455 $$ = scm_reverse_x ($2, SCM_EOL);
2466 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2467 if (!PARSER->lexer_->is_note_state ())
2468 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2472 n = MY_MAKE_MUSIC ("RestEvent", @$);
2474 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2476 n->set_property ("pitch", $1);
2477 n->set_property ("duration", $5);
2479 if (scm_is_number ($4))
2481 int q = scm_to_int ($4);
2482 n->set_property ("absolute-octave", scm_from_int (q-1));
2486 n->set_property ("cautionary", SCM_BOOL_T);
2487 if ($2 % 2 || $3 % 2)
2488 n->set_property ("force-accidental", SCM_BOOL_T);
2490 $$ = n->unprotect ();
2492 | DRUM_PITCH optional_notemode_duration {
2493 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2494 n->set_property ("duration", $2);
2495 n->set_property ("drum-type", $1);
2497 $$ = n->unprotect ();
2499 | RESTNAME optional_notemode_duration {
2501 if (ly_scm2string ($1) == "s") {
2503 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2506 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2509 ev->set_property ("duration", $2);
2510 $$ = ev->unprotect ();
2512 | lyric_element optional_notemode_duration {
2513 if (!PARSER->lexer_->is_lyric_state ())
2514 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2516 Music *levent = MY_MAKE_MUSIC ("LyricEvent", @$);
2517 levent->set_property ("text", $1);
2518 levent->set_property ("duration",$2);
2519 $$= levent->unprotect ();
2523 simple_chord_elements:
2525 $$ = scm_list_1 ($1);
2528 if (!PARSER->lexer_->is_chord_state ())
2529 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2532 | figure_spec optional_notemode_duration {
2533 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2535 unsmob_music (scm_car (s))->set_property ("duration", $2);
2551 steno_tonic_pitch optional_notemode_duration {
2552 $$ = make_chord_elements ($1, $2, SCM_EOL);
2554 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2555 SCM its = scm_reverse_x ($4, SCM_EOL);
2556 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2564 | chord_items chord_item {
2565 $$ = scm_cons ($2, $$);
2571 $$ = ly_symbol2scm ("chord-colon");
2574 $$ = ly_symbol2scm ("chord-caret");
2576 | CHORD_SLASH steno_tonic_pitch {
2577 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2579 | CHORD_BASS steno_tonic_pitch {
2580 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2589 $$ = scm_reverse_x ($1, SCM_EOL);
2597 step_number { $$ = scm_cons ($1, SCM_EOL); }
2598 | step_numbers '.' step_number {
2599 $$ = scm_cons ($3, $$);
2605 $$ = make_chord_step ($1, 0);
2607 | bare_unsigned '+' {
2608 $$ = make_chord_step ($1, SHARP_ALTERATION);
2610 | bare_unsigned CHORD_MINUS {
2611 $$ = make_chord_step ($1, FLAT_ALTERATION);
2617 $$ = scm_from_int ($1);
2619 | bare_unsigned '~' bare_unsigned {
2620 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2627 TODO: should deprecate in favor of Scheme?
2631 number_expression '+' number_term {
2632 $$ = scm_sum ($1, $3);
2634 | number_expression '-' number_term {
2635 $$ = scm_difference ($1, $3);
2644 | number_factor '*' number_factor {
2645 $$ = scm_product ($1, $3);
2647 | number_factor '/' number_factor {
2648 $$ = scm_divide ($1, $3);
2653 '-' number_factor { /* %prec UNARY_MINUS */
2654 $$ = scm_difference ($2, SCM_UNDEFINED);
2662 | UNSIGNED NUMBER_IDENTIFIER {
2663 $$ = scm_product ($1, $2)
2665 | REAL NUMBER_IDENTIFIER {
2666 $$ = scm_product ($1, $2)
2678 $$ = scm_to_int ($1);
2689 | exclamations '!' { $$ ++; }
2694 | questions '?' { $$ ++; }
2698 This should be done more dynamically if possible.
2702 LYRIC_MARKUP_IDENTIFIER {
2706 { PARSER->lexer_->push_markup_state (); }
2709 PARSER->lexer_->pop_state ();
2714 MARKUPLIST_IDENTIFIER {
2718 { PARSER->lexer_->push_markup_state (); }
2721 PARSER->lexer_->pop_state ();
2730 { PARSER->lexer_->push_markup_state (); }
2733 PARSER->lexer_->pop_state ();
2739 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2741 | markup_head_1_list simple_markup {
2742 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2750 MARKUPLIST_IDENTIFIER {
2753 | markup_composed_list {
2756 | markup_braced_list {
2759 | markup_command_list {
2760 $$ = scm_list_1 ($1);
2764 markup_composed_list:
2765 markup_head_1_list markup_braced_list {
2766 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2772 '{' markup_braced_list_body '}' {
2773 $$ = scm_reverse_x ($2, SCM_EOL);
2777 markup_braced_list_body:
2778 /* empty */ { $$ = SCM_EOL; }
2779 | markup_braced_list_body markup {
2780 $$ = scm_cons ($2, $1);
2782 | markup_braced_list_body markup_list {
2783 $$ = scm_reverse_x ($2, $1);
2787 markup_command_list:
2788 MARKUP_LIST_FUNCTION markup_command_list_arguments {
2789 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
2793 markup_command_basic_arguments:
2794 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
2795 $$ = scm_cons ($3, $2);
2797 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
2798 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED, $3, $2, $1);
2800 | EXPECT_NO_MORE_ARGS {
2805 markup_command_list_arguments:
2806 markup_command_basic_arguments { $$ = $1; }
2807 | EXPECT_MARKUP markup_command_list_arguments markup {
2808 $$ = scm_cons ($3, $2);
2813 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
2814 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
2819 markup_head_1_item {
2820 $$ = scm_list_1 ($1);
2822 | markup_head_1_list markup_head_1_item {
2823 $$ = scm_cons ($2, $1);
2829 $$ = make_simple_markup ($1);
2831 | MARKUP_IDENTIFIER {
2834 | LYRIC_MARKUP_IDENTIFIER {
2837 | STRING_IDENTIFIER {
2841 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2842 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2843 } '{' score_body '}' {
2845 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2847 PARSER->lexer_->pop_state ();
2849 | MARKUP_FUNCTION markup_command_basic_arguments {
2850 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
2855 markup_head_1_list simple_markup {
2856 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2857 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2867 Lily_parser::set_yydebug (bool x)
2873 Lily_parser::do_yyparse ()
2875 yyparse ((void*)this);
2884 It is a little strange to have this function in this file, but
2885 otherwise, we have to import music classes into the lexer.
2889 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2891 if (scm_is_string (sid)) {
2893 return STRING_IDENTIFIER;
2894 } else if (unsmob_book (sid)) {
2895 Book *book = unsmob_book (sid)->clone ();
2896 *destination = book->self_scm ();
2899 return BOOK_IDENTIFIER;
2900 } else if (scm_is_number (sid)) {
2902 return NUMBER_IDENTIFIER;
2903 } else if (unsmob_context_def (sid)) {
2904 Context_def *def= unsmob_context_def (sid)->clone ();
2906 *destination = def->self_scm ();
2909 return CONTEXT_DEF_IDENTIFIER;
2910 } else if (unsmob_context_mod (sid)) {
2911 *destination = unsmob_context_mod (sid)->smobbed_copy ();
2913 return CONTEXT_MOD_IDENTIFIER;
2914 } else if (unsmob_score (sid)) {
2915 Score *score = new Score (*unsmob_score (sid));
2916 *destination = score->self_scm ();
2918 score->unprotect ();
2919 return SCORE_IDENTIFIER;
2920 } else if (Music *mus = unsmob_music (sid)) {
2921 mus = mus->clone ();
2922 *destination = mus->self_scm ();
2923 unsmob_music (*destination)->
2924 set_property ("origin", make_input (last_input_));
2926 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2930 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2931 } else if (unsmob_pitch (sid)) {
2932 *destination = unsmob_pitch (sid)->smobbed_copy ();
2933 return PITCH_IDENTIFIER;
2934 } else if (unsmob_duration (sid)) {
2935 *destination = unsmob_duration (sid)->smobbed_copy ();
2936 return DURATION_IDENTIFIER;
2937 } else if (unsmob_output_def (sid)) {
2938 Output_def *p = unsmob_output_def (sid);
2941 *destination = p->self_scm ();
2943 return OUTPUT_DEF_IDENTIFIER;
2944 } else if (Text_interface::is_markup (sid)) {
2946 if (is_lyric_state ())
2947 return LYRIC_MARKUP_IDENTIFIER;
2948 return MARKUP_IDENTIFIER;
2949 } else if (Text_interface::is_markup_list (sid)) {
2951 return MARKUPLIST_IDENTIFIER;
2958 get_next_unique_context_id ()
2960 return scm_from_locale_string ("$uniqueContextId");
2965 get_next_unique_lyrics_context_id ()
2967 static int new_context_count;
2969 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2970 return scm_from_locale_string (s);
2973 SCM check_scheme_arg (Lily_parser *my_lily_parser, Input loc, SCM fallback,
2974 SCM arg, SCM args, SCM pred)
2976 SCM unwrap = SCM_UNDEFINED;
2977 if (scm_is_true (scm_call_1 (pred, arg)))
2978 return scm_cons (arg, args);
2979 unwrap = try_unpack_lyrics (pred, arg);
2980 if (!SCM_UNBNDP (unwrap))
2981 return scm_cons (unwrap, args);
2982 if (SCM_UNBNDP (fallback)) {
2983 args = scm_cons (SCM_BOOL_F, args);
2984 fallback = SCM_BOOL_F;
2986 args = scm_cons (loc_on_music (loc, fallback), args);
2987 fallback = SCM_CDR (scm_last_pair (args));
2989 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
2990 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
2991 scm_set_cdr_x (scm_last_pair (args), fallback);
2995 SCM loc_on_music (Input loc, SCM arg)
2997 if (Music *m = unsmob_music (arg))
3001 return m->unprotect ();
3007 is_regular_identifier (SCM id)
3009 string str = ly_scm2string (id);
3010 char const *s = str.c_str ();
3019 v = v && isalnum (*s);
3026 make_music_with_input (SCM name, Input where)
3028 Music *m = make_music_by_name (name);
3029 m->set_spot (where);
3034 get_first_context_id (SCM type, Music *m)
3036 SCM id = m->get_property ("context-id");
3037 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
3038 && scm_is_string (m->get_property ("context-id"))
3039 && scm_c_string_length (id) > 0)
3047 make_simple_markup (SCM a)
3055 return t && t == 1 << intlog2 (t);
3059 set_music_properties (Music *p, SCM a)
3061 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3062 p->set_property (scm_caar (k), scm_cdar (k));
3067 make_chord_step (int step, Rational alter)
3070 alter += FLAT_ALTERATION;
3074 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3075 return m.smobbed_copy ();
3080 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
3082 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3083 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
3087 try_unpack_lyrics (SCM pred, SCM arg)
3089 if (Music *m = unsmob_music (arg))
3090 if (m->is_mus_type ("lyric-event")) {
3091 SCM text = m->get_property ("text");
3092 if (scm_is_true (scm_call_1 (pred, text)))
3095 return SCM_UNDEFINED;
3098 /* Todo: actually also use apply iso. call too ... */
3100 ly_input_procedure_p (SCM x)
3102 return ly_is_procedure (x)
3103 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
3107 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
3109 Lily_parser *pars = (Lily_parser*) v;
3110 Lily_lexer *lex = pars->lexer_;
3112 lex->lexval_ = (void*) s;
3114 lex->prepare_for_next_token ();
3115 return lex->yylex ();