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"
244 %token MARKUP "\\markup"
245 %token MARKUPLIST "\\markuplist"
248 %token NOTEMODE "\\notemode"
249 %token OVERRIDE "\\override"
250 %token PAPER "\\paper"
251 %token REMOVE "\\remove"
252 %token REPEAT "\\repeat"
254 %token REVERT "\\revert"
255 %token SCORE "\\score"
256 %token SEQUENTIAL "\\sequential"
258 %token SIMULTANEOUS "\\simultaneous"
259 %token TEMPO "\\tempo"
260 %token TIMES "\\times"
262 %token UNSET "\\unset"
265 /* Keyword token exceptions. */
266 %token TIME_T "\\time"
267 %token NEWCONTEXT "\\new"
270 /* Other string tokens. */
272 %token CHORD_BASS "/+"
273 %token CHORD_CARET "^"
274 %token CHORD_COLON ":"
275 %token CHORD_MINUS "-"
276 %token CHORD_SLASH "/"
277 %token ANGLE_OPEN "<"
278 %token ANGLE_CLOSE ">"
279 %token DOUBLE_ANGLE_OPEN "<<"
280 %token DOUBLE_ANGLE_CLOSE ">>"
281 %token E_BACKSLASH "\\"
282 %token E_ANGLE_CLOSE "\\>"
283 %token E_CHAR "\\C[haracter]"
285 %token E_EXCLAMATION "\\!"
286 %token E_BRACKET_OPEN "\\["
288 %token E_BRACKET_CLOSE "\\]"
289 %token E_ANGLE_OPEN "\\<"
295 If we give names, Bison complains.
297 %token FIGURE_CLOSE /* "\\>" */
298 %token FIGURE_OPEN /* "\\<" */
299 %token FIGURE_SPACE "_"
302 %token CHORDMODIFIERS
304 %token MULTI_MEASURE_REST
307 %token <i> E_UNSIGNED
308 %token <scm> UNSIGNED
310 /* Artificial tokens, for more generic function syntax */
311 %token <i> EXPECT_MARKUP "markup?"
312 %token <i> EXPECT_PITCH "ly:pitch?"
313 %token <i> EXPECT_DURATION "ly:duration?"
314 %token <scm> EXPECT_SCM "scheme?"
315 %token <scm> BACKUP "(backed-up?)"
316 %token <i> EXPECT_MARKUP_LIST "markup-list?"
317 %token <scm> EXPECT_OPTIONAL "optional?"
318 /* After the last argument. */
319 %token <i> EXPECT_NO_MORE_ARGS;
321 /* An artificial token for parsing embedded Lilypond */
322 %token <i> EMBEDDED_LILY "#{"
324 %token <scm> BOOK_IDENTIFIER
325 %token <scm> CHORDMODIFIER_PITCH
326 %token <scm> CHORD_MODIFIER
327 %token <scm> CHORD_REPETITION
328 %token <scm> CONTEXT_DEF_IDENTIFIER
329 %token <scm> CONTEXT_MOD_IDENTIFIER
330 %token <scm> DRUM_PITCH
331 %token <scm> PITCH_IDENTIFIER
332 %token <scm> DURATION_IDENTIFIER
333 %token <scm> EVENT_IDENTIFIER
334 %token <scm> EVENT_FUNCTION
335 %token <scm> FRACTION
336 %token <scm> LYRICS_STRING
337 %token <scm> LYRIC_MARKUP_IDENTIFIER
338 %token <scm> MARKUP_FUNCTION
339 %token <scm> MARKUP_LIST_FUNCTION
340 %token <scm> MARKUP_IDENTIFIER
341 %token <scm> MARKUPLIST_IDENTIFIER
342 %token <scm> MUSIC_FUNCTION
343 %token <scm> MUSIC_IDENTIFIER
344 %token <scm> NOTENAME_PITCH
345 %token <scm> NUMBER_IDENTIFIER
346 %token <scm> OUTPUT_DEF_IDENTIFIER
348 %token <scm> RESTNAME
349 %token <scm> SCM_FUNCTION
350 %token <scm> SCM_IDENTIFIER
351 %token <scm> SCM_TOKEN
352 %token <scm> SCORE_IDENTIFIER
354 %token <scm> STRING_IDENTIFIER
355 %token <scm> TONICNAME_PITCH
358 %type <book> book_block
359 %type <book> book_body
360 %type <book> bookpart_block
361 %type <book> bookpart_body
363 %type <i> bare_unsigned
364 %type <scm> figured_bass_alteration
366 %type <i> exclamations
367 %type <i> optional_rest
372 %type <i> tremolo_type
375 %type <scm> composite_music
376 %type <scm> grouped_music_list
377 %type <scm> braced_music_list
378 %type <scm> closed_music
380 %type <scm> music_bare
381 %type <scm> complex_music
382 %type <scm> complex_music_prefix
383 %type <scm> mode_changed_music
384 %type <scm> repeated_music
385 %type <scm> sequential_music
386 %type <scm> simple_music
387 %type <scm> simultaneous_music
388 %type <scm> chord_body
389 %type <scm> chord_body_element
390 %type <scm> command_element
391 %type <scm> command_event
392 %type <scm> context_modification
393 %type <scm> context_change
394 %type <scm> direction_less_event
395 %type <scm> direction_reqd_event
396 %type <scm> embedded_lilypond
397 %type <scm> event_chord
398 %type <scm> fingering
399 %type <scm> gen_text_def
400 %type <scm> music_property_def
401 %type <scm> note_chord_element
402 %type <scm> post_event
403 %type <scm> post_event_nofinger
404 %type <scm> re_rhythmed_music
405 %type <scm> simple_element
406 %type <scm> simple_music_property_def
407 %type <scm> start_symbol
408 %type <scm> string_number_event
409 %type <scm> tempo_event
411 %type <outputdef> output_def_body
412 %type <outputdef> output_def_head
413 %type <outputdef> output_def_head_with_mode_switch
414 %type <outputdef> output_def
415 %type <outputdef> paper_block
417 %type <scm> music_function_call
418 %type <scm> music_list
419 %type <scm> assignment_id
420 %type <scm> bare_number
421 %type <scm> bare_number_closed
422 %type <scm> unsigned_number
423 %type <scm> bass_figure
424 %type <scm> figured_bass_modification
425 %type <scm> br_bass_figure
426 %type <scm> bass_number
427 %type <scm> chord_body_elements
428 %type <scm> chord_item
429 %type <scm> chord_items
430 %type <scm> chord_separator
431 %type <scm> context_def_mod
432 %type <scm> context_def_spec_block
433 %type <scm> context_def_spec_body
434 %type <scm> context_mod
435 %type <scm> context_mod_list
436 %type <scm> context_prop_spec
437 %type <scm> direction_less_char
438 %type <scm> duration_length
439 %type <scm> embedded_scm
440 %type <scm> embedded_scm_arg
441 %type <scm> embedded_scm_arg_closed
442 %type <scm> embedded_scm_bare
443 %type <scm> embedded_scm_bare_arg
444 %type <scm> embedded_scm_closed
445 %type <scm> embedded_scm_chord_body
446 %type <scm> embedded_scm_event
447 %type <scm> event_function_event
448 %type <scm> figure_list
449 %type <scm> figure_spec
451 %type <scm> full_markup
452 %type <scm> full_markup_list
453 %type <scm> function_arglist
454 %type <scm> function_arglist_optional
455 %type <scm> function_arglist_backup
456 %type <scm> function_arglist_nonbackup
457 %type <scm> function_arglist_skip
458 %type <scm> function_arglist_bare
459 %type <scm> function_arglist_closed
460 %type <scm> function_arglist_closed_optional
461 %type <scm> function_arglist_common
462 %type <scm> function_arglist_closed_common
463 %type <scm> function_arglist_keep
464 %type <scm> function_arglist_closed_keep
465 %type <scm> identifier_init
467 %type <scm> lilypond_header
468 %type <scm> lilypond_header_body
469 %type <scm> lyric_element
470 %type <scm> lyric_markup
472 %type <scm> markup_braced_list
473 %type <scm> markup_braced_list_body
474 %type <scm> markup_composed_list
475 %type <scm> markup_command_list
476 %type <scm> markup_command_list_arguments
477 %type <scm> markup_command_basic_arguments
478 %type <scm> markup_head_1_item
479 %type <scm> markup_head_1_list
480 %type <scm> markup_list
481 %type <scm> markup_top
482 %type <scm> mode_changing_head
483 %type <scm> mode_changing_head_with_context
484 %type <scm> multiplied_duration
485 %type <scm> music_function_event
486 %type <scm> music_function_event_arglist
487 %type <scm> music_function_chord_body
488 %type <scm> music_function_chord_body_arglist
489 %type <scm> new_chord
490 %type <scm> new_lyrics
491 %type <scm> number_expression
492 %type <scm> number_factor
493 %type <scm> number_term
494 %type <scm> octave_check
495 %type <scm> optional_context_mod
496 %type <scm> optional_id
497 %type <scm> optional_notemode_duration
499 %type <scm> pitch_also_in_chords
500 %type <scm> post_events
501 %type <scm> property_operation
502 %type <scm> property_path property_path_revved
504 %type <scm> scalar_bare
505 %type <scm> scalar_closed
506 %type <scm> scm_function_call
507 %type <scm> scm_function_call_closed
508 %type <scm> script_abbreviation
509 %type <scm> simple_chord_elements
510 %type <scm> simple_markup
511 %type <scm> simple_string
512 %type <scm> steno_duration
513 %type <scm> steno_pitch
514 %type <scm> steno_tonic_pitch
515 %type <scm> step_number
516 %type <scm> step_numbers
518 %type <scm> tempo_range
520 %type <score> score_block
521 %type <score> score_body
526 /* We don't assign precedence to / and *, because we might need varied
527 prec levels in different prods */
536 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
537 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
538 } embedded_lilypond {
539 PARSER->lexer_->pop_state ();
540 PARSER->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
544 lilypond: /* empty */ { }
545 | lilypond toplevel_expression {
547 | lilypond assignment {
550 PARSER->error_level_ = 1;
553 PARSER->error_level_ = 1;
560 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
564 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
565 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
570 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
571 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
572 bookpart->unprotect ();
577 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
578 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
582 Music *music = unsmob_music ($1);
583 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
584 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
587 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
588 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
591 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
592 scm_call_2 (proc, PARSER->self_scm (), $1);
596 Output_def * od = $1;
598 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
599 id = ly_symbol2scm ("$defaultpaper");
600 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
601 id = ly_symbol2scm ("$defaultmidi");
602 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
603 id = ly_symbol2scm ("$defaultlayout");
605 PARSER->lexer_->set_identifier (id, od->self_scm ());
615 embedded_scm_bare_arg:
621 | context_modification
624 $$ = $1->self_scm ();
627 | context_def_spec_block
630 $$ = $1->self_scm ();
635 $$ = $1->self_scm ();
640 $$ = $1->self_scm ();
645 /* The generic version may end in music, or not */
653 embedded_scm_bare_arg
659 SCM_FUNCTION function_arglist {
660 $$ = MAKE_SYNTAX ("music-function", @$,
668 $$ = MAKE_SYNTAX ("void-music", @$);
671 | music music music_list {
672 $$ = MAKE_SYNTAX ("sequential-music", @$,
673 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
676 PARSER->error_level_ = 1;
678 | INVALID embedded_lilypond {
679 PARSER->error_level_ = 1;
684 lilypond_header_body:
686 $$ = get_header (PARSER);
687 PARSER->lexer_->add_scope ($$);
689 | lilypond_header_body assignment {
695 HEADER '{' lilypond_header_body '}' {
696 $$ = PARSER->lexer_->remove_scope ();
705 | LYRICS_STRING { $$ = $1; }
709 assignment_id '=' identifier_init {
710 PARSER->lexer_->set_identifier ($1, $3);
712 | assignment_id property_path '=' identifier_init {
713 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
714 PARSER->lexer_->set_identifier (path, $4);
717 TODO: devise standard for protection in parser.
719 The parser stack lives on the C-stack, which means that
720 all objects can be unprotected as soon as they're here.
730 $$ = $1->self_scm ();
734 $$ = $1->self_scm ();
738 $$ = $1->self_scm ();
742 $$ = $1->self_scm ();
745 | context_def_spec_block {
749 /* Hack: Create event-chord around standalone events.
750 Prevents the identifier from being interpreted as a post-event. */
751 Music *mus = unsmob_music ($1);
752 bool is_event = mus &&
753 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
758 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
760 | post_event_nofinger {
763 | number_expression {
778 | context_modification {
783 context_def_spec_block:
784 CONTEXT '{' context_def_spec_body '}'
790 context_def_spec_body:
792 $$ = Context_def::make_scm ();
793 unsmob_context_def ($$)->origin ()->set_spot (@$);
795 | CONTEXT_DEF_IDENTIFIER {
797 unsmob_context_def ($$)->origin ()->set_spot (@$);
799 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
800 Context_def*td = unsmob_context_def ($$);
802 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
803 SCM tag = scm_caar (p);
805 /* TODO: should make new tag "grob-definition" ? */
806 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
807 tag, scm_cons (scm_cdar (p), SCM_EOL)));
810 | context_def_spec_body context_mod {
811 unsmob_context_def ($$)->add_context_mod ($2);
813 | context_def_spec_body context_modification {
814 Context_def *td = unsmob_context_def ($$);
815 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
816 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
817 td->add_context_mod (scm_car (m));
825 BOOK '{' book_body '}' {
828 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
833 * Use 'handlers' like for toplevel-* stuff?
834 * grok \layout and \midi? */
838 init_papers (PARSER);
839 $$->origin ()->set_spot (@$);
840 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
841 $$->paper_->unprotect ();
842 push_paper (PARSER, $$->paper_);
843 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
844 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
845 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
846 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
849 $$ = unsmob_book ($1);
851 $$->origin ()->set_spot (@$);
852 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
854 | book_body paper_block {
857 set_paper (PARSER, $2);
859 | book_body bookpart_block {
861 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
862 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
863 bookpart->unprotect ();
865 | book_body score_block {
867 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
868 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
871 | book_body composite_music {
872 Music *music = unsmob_music ($2);
873 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
874 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
876 | book_body full_markup {
877 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
878 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
880 | book_body full_markup_list {
881 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
882 scm_call_2 (proc, $$->self_scm (), $2);
884 | book_body lilypond_header {
887 | book_body embedded_scm { }
890 $$->scores_ = SCM_EOL;
891 $$->bookparts_ = SCM_EOL;
896 BOOKPART '{' bookpart_body '}' {
898 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
905 $$->origin ()->set_spot (@$);
906 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
909 $$ = unsmob_book ($1);
911 $$->origin ()->set_spot (@$);
912 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
914 | bookpart_body paper_block {
918 | bookpart_body score_block {
920 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
921 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
924 | bookpart_body composite_music {
925 Music *music = unsmob_music ($2);
926 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
927 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
929 | bookpart_body full_markup {
930 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
931 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
933 | bookpart_body full_markup_list {
934 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
935 scm_call_2 (proc, $$->self_scm (), $2);
937 | bookpart_body lilypond_header {
940 | bookpart_body embedded_scm { }
941 | bookpart_body error {
943 $$->scores_ = SCM_EOL;
948 SCORE '{' score_body '}' {
956 SCM scorify = ly_lily_module_constant ("scorify-music");
957 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
959 // pass ownernship to C++ again.
960 $$ = unsmob_score (score);
962 $$->origin ()->set_spot (@$);
965 $$ = unsmob_score ($1);
967 $$->origin ()->set_spot (@$);
969 | score_body lilypond_header {
972 | score_body output_def {
973 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
975 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
980 $$->add_output_def ($2);
985 $$->error_found_ = true;
997 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
999 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
1001 $$ = get_paper (PARSER);
1008 output_def_body '}' {
1011 PARSER->lexer_->remove_scope ();
1012 PARSER->lexer_->pop_state ();
1018 $$ = get_paper (PARSER);
1019 $$->input_origin_ = @$;
1020 PARSER->lexer_->add_scope ($$->scope_);
1023 Output_def *p = get_midi (PARSER);
1025 PARSER->lexer_->add_scope (p->scope_);
1028 Output_def *p = get_layout (PARSER);
1030 PARSER->lexer_->add_scope (p->scope_);
1035 output_def_head_with_mode_switch:
1037 PARSER->lexer_->push_initial_state ();
1043 output_def_head_with_mode_switch '{' {
1045 $$->input_origin_.set_spot (@$);
1047 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1050 Output_def *o = unsmob_output_def ($3);
1051 o->input_origin_.set_spot (@$);
1054 PARSER->lexer_->remove_scope ();
1055 PARSER->lexer_->add_scope (o->scope_);
1057 | output_def_body assignment {
1060 | output_def_body context_def_spec_block {
1061 assign_context_def ($$, $2);
1063 | output_def_body error {
1069 TEMPO steno_duration '=' tempo_range {
1070 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1072 | TEMPO scalar_closed steno_duration '=' tempo_range {
1073 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1076 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1081 The representation of a list is reversed to have efficient append. */
1087 | music_list music {
1088 $$ = scm_cons ($2, $1);
1090 | music_list embedded_scm {
1093 | music_list error {
1094 Music *m = MY_MAKE_MUSIC("Music", @$);
1096 m->set_property ("error-found", SCM_BOOL_T);
1097 $$ = scm_cons (m->self_scm (), $1);
1098 m->unprotect (); /* UGH */
1105 $$ = scm_reverse_x ($2, SCM_EOL);
1111 | composite_music %prec COMPOSITE
1116 REPEAT simple_string unsigned_number music
1118 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1120 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1122 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1127 SEQUENTIAL braced_music_list {
1128 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1130 | braced_music_list {
1131 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1136 SIMULTANEOUS braced_music_list {
1137 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1139 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1140 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1146 | music_property_def
1150 context_modification:
1151 WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1153 PARSER->lexer_->pop_state ();
1156 | WITH CONTEXT_MOD_IDENTIFIER
1160 | CONTEXT_MOD_IDENTIFIER
1166 optional_context_mod:
1170 | context_modification
1178 $$ = Context_mod ().smobbed_copy ();
1180 | context_mod_list context_mod {
1181 unsmob_context_mod ($1)->add_context_mod ($2);
1183 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1184 Context_mod *md = unsmob_context_mod ($2);
1186 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1195 /* Music that can be parsed without lookahead */
1198 | complex_music_prefix closed_music
1200 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1207 | grouped_music_list
1211 simultaneous_music { $$ = $1; }
1212 | sequential_music { $$ = $1; }
1215 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1216 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1217 and this rule returns the reversed list of arguments. */
1219 function_arglist_skip:
1220 function_arglist_common
1221 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1223 $$ = scm_cons ($1, $3);
1224 } %prec FUNCTION_ARGLIST
1225 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1227 $$ = scm_cons ($1, $3);
1228 } %prec FUNCTION_ARGLIST
1229 | EXPECT_SCM EXPECT_DURATION function_arglist_skip
1231 $$ = scm_cons ($1, $3);
1232 } %prec FUNCTION_ARGLIST
1236 function_arglist_nonbackup:
1237 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1238 $$ = scm_cons ($4, $3);
1240 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1241 $$ = scm_cons ($4, $3);
1243 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1245 $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
1247 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1249 $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
1251 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1253 $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
1258 function_arglist_keep:
1259 function_arglist_common
1260 | function_arglist_backup
1263 function_arglist_closed_keep:
1264 function_arglist_closed_common
1265 | function_arglist_backup
1268 function_arglist_backup:
1269 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1271 if (scm_is_true (scm_call_1 ($2, $4)))
1273 $$ = scm_cons ($4, $3);
1275 $$ = try_unpack_lyrics ($2, $4);
1276 if (!SCM_UNBNDP ($$))
1277 $$ = scm_cons ($$, $3);
1279 $$ = scm_cons (loc_on_music (@3, $1), $3);
1280 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1284 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1286 if (scm_is_true (scm_call_1 ($2, $4)))
1288 $$ = scm_cons ($4, $3);
1290 $$ = scm_cons (loc_on_music (@3, $1), $3);
1291 MYBACKUP (UNSIGNED, $4, @4);
1294 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1296 if (scm_is_true (scm_call_1 ($2, $4)))
1298 $$ = scm_cons ($4, $3);
1300 $$ = scm_cons (loc_on_music (@3, $1), $3);
1301 MYBACKUP (REAL, $4, @4);
1304 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1306 if (scm_is_true (scm_call_1 ($2, $4)))
1308 $$ = scm_cons ($4, $3);
1310 $$ = scm_cons (loc_on_music (@3, $1), $3);
1311 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1314 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1316 if (scm_is_true (scm_call_1 ($2, $4)))
1318 $$ = scm_cons ($4, $3);
1320 $$ = scm_cons (loc_on_music (@3, $1), $3);
1321 MYBACKUP (FRACTION, $4, @4);
1324 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1326 $$ = scm_cons ($4, $3);
1328 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1330 $$ = scm_cons ($4, $3);
1332 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1334 $$ = scm_cons ($1, $3);
1335 MYBACKUP(0, SCM_UNDEFINED, @3);
1340 function_arglist_common
1341 | function_arglist_nonbackup
1344 function_arglist_common:
1345 function_arglist_bare
1346 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1348 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1351 | EXPECT_SCM function_arglist_closed_optional bare_number
1353 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1356 | EXPECT_SCM function_arglist_closed_optional fraction
1358 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1363 function_arglist_closed:
1364 function_arglist_closed_common
1365 | function_arglist_nonbackup
1368 function_arglist_closed_common:
1369 function_arglist_bare
1370 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1372 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1375 | EXPECT_SCM function_arglist_closed_optional bare_number_closed
1377 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1380 | EXPECT_SCM function_arglist_closed_optional FRACTION
1382 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1387 function_arglist_optional:
1388 function_arglist_keep %prec FUNCTION_ARGLIST
1389 | function_arglist_backup BACKUP
1390 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1392 $$ = scm_cons ($1, $3);
1394 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1396 $$ = scm_cons ($1, $3);
1400 function_arglist_closed_optional:
1401 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1402 | function_arglist_backup BACKUP
1403 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1405 $$ = scm_cons ($1, $3);
1407 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1409 $$ = scm_cons ($1, $3);
1413 embedded_scm_closed:
1415 | scm_function_call_closed
1418 embedded_scm_arg_closed:
1419 embedded_scm_bare_arg
1420 | scm_function_call_closed
1424 scm_function_call_closed:
1425 SCM_FUNCTION function_arglist_closed {
1426 $$ = MAKE_SYNTAX ("music-function", @$,
1428 } %prec FUNCTION_ARGLIST
1431 function_arglist_bare:
1432 EXPECT_NO_MORE_ARGS {
1435 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1436 $$ = scm_cons ($3, $2);
1438 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1439 $$ = scm_cons ($3, $2);
1441 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1442 $$ = scm_cons ($1, $3);
1444 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1445 $$ = scm_cons ($1, $3);
1447 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1448 $$ = scm_cons ($1, $3);
1452 music_function_call:
1453 MUSIC_FUNCTION function_arglist {
1454 $$ = MAKE_SYNTAX ("music-function", @$,
1461 /**/ { $$ = SCM_EOL; }
1462 | '=' simple_string {
1469 | repeated_music { $$ = $1; }
1470 | re_rhythmed_music { $$ = $1; }
1471 | complex_music_prefix music
1473 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1477 complex_music_prefix:
1478 CONTEXT simple_string optional_id optional_context_mod {
1479 Context_mod *ctxmod = unsmob_context_mod ($4);
1482 mods = ctxmod->get_mods ();
1483 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1485 | NEWCONTEXT simple_string optional_id optional_context_mod {
1486 Context_mod *ctxmod = unsmob_context_mod ($4);
1489 mods = ctxmod->get_mods ();
1490 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1493 $$ = START_MAKE_SYNTAX ("time-scaled-music", $2);
1498 mode_changing_head grouped_music_list {
1499 if ($1 == ly_symbol2scm ("chords"))
1501 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1507 PARSER->lexer_->pop_state ();
1509 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1510 Context_mod *ctxmod = unsmob_context_mod ($2);
1513 mods = ctxmod->get_mods ();
1514 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1515 if ($1 == ly_symbol2scm ("ChordNames"))
1517 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1519 PARSER->lexer_->pop_state ();
1525 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1526 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1528 $$ = ly_symbol2scm ("notes");
1532 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1533 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1535 $$ = ly_symbol2scm ("drums");
1538 PARSER->lexer_->push_figuredbass_state ();
1540 $$ = ly_symbol2scm ("figures");
1543 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1544 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1545 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1546 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1547 $$ = ly_symbol2scm ("chords");
1551 { PARSER->lexer_->push_lyric_state ();
1552 $$ = ly_symbol2scm ("lyrics");
1556 mode_changing_head_with_context:
1558 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1559 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1561 $$ = ly_symbol2scm ("DrumStaff");
1564 PARSER->lexer_->push_figuredbass_state ();
1566 $$ = ly_symbol2scm ("FiguredBass");
1569 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1570 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1571 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1572 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1573 $$ = ly_symbol2scm ("ChordNames");
1576 { PARSER->lexer_->push_lyric_state ();
1577 $$ = ly_symbol2scm ("Lyrics");
1582 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1585 /* Can also use music at the expensive of two S/Rs similar to
1586 \repeat \alternative */
1587 PARSER->lexer_->pop_state ();
1589 $$ = scm_cons ($3, SCM_EOL);
1591 | new_lyrics ADDLYRICS {
1592 PARSER->lexer_->push_lyric_state ();
1594 PARSER->lexer_->pop_state ();
1595 $$ = scm_cons ($4, $1);
1600 composite_music new_lyrics {
1601 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1603 | LYRICSTO simple_string {
1604 PARSER->lexer_->push_lyric_state ();
1606 PARSER->lexer_->pop_state ();
1607 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1612 CHANGE STRING '=' STRING {
1613 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1618 property_path_revved:
1619 embedded_scm_closed {
1620 $$ = scm_cons ($1, SCM_EOL);
1622 | property_path_revved embedded_scm_closed {
1623 $$ = scm_cons ($2, $1);
1628 property_path_revved {
1629 $$ = scm_reverse_x ($1, SCM_EOL);
1635 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1636 scm_string_to_symbol ($1), $3);
1638 | UNSET simple_string {
1639 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1640 scm_string_to_symbol ($2));
1642 | OVERRIDE simple_string property_path '=' scalar {
1643 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1644 scm_string_to_symbol ($2), $5),
1647 | REVERT simple_string embedded_scm {
1648 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1649 scm_string_to_symbol ($2), $3);
1654 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1655 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1657 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1658 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1659 | DENIES { $$ = ly_symbol2scm ("denies"); }
1661 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1662 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1663 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1664 | NAME { $$ = ly_symbol2scm ("context-name"); }
1668 property_operation { $$ = $1; }
1669 | context_def_mod STRING {
1670 $$ = scm_list_2 ($1, $2);
1672 | context_def_mod embedded_scm {
1673 if (ly_symbol2scm ("consists") != $1)
1676 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1680 $$ = scm_list_2 ($1, $2);
1687 if (!is_regular_identifier ($1))
1689 @$.error (_("Grob name should be alphanumeric"));
1692 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1693 scm_string_to_symbol ($1));
1695 | simple_string '.' simple_string {
1696 $$ = scm_list_2 (scm_string_to_symbol ($1),
1697 scm_string_to_symbol ($3));
1701 simple_music_property_def:
1702 OVERRIDE context_prop_spec property_path '=' scalar {
1703 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1704 ly_symbol2scm ("OverrideProperty"),
1709 | REVERT context_prop_spec embedded_scm {
1710 $$ = scm_list_4 (scm_car ($2),
1711 ly_symbol2scm ("RevertProperty"),
1715 | SET context_prop_spec '=' scalar {
1716 $$ = scm_list_4 (scm_car ($2),
1717 ly_symbol2scm ("PropertySet"),
1721 | UNSET context_prop_spec {
1722 $$ = scm_list_3 (scm_car ($2),
1723 ly_symbol2scm ("PropertyUnset"),
1729 simple_music_property_def {
1730 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (PARSER->self_scm (), make_input (@$), $1));
1738 | STRING_IDENTIFIER {
1741 | string '+' string {
1742 $$ = scm_string_append (scm_list_2 ($1, $3));
1746 simple_string: STRING {
1752 | STRING_IDENTIFIER {
1767 | embedded_scm_bare {
1786 scm_function_call_closed
1791 /* TODO: Create a special case that avoids the creation of
1792 EventChords around simple_elements that have no post_events?
1794 simple_chord_elements post_events {
1795 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1798 /* why is this giving wrong start location? -ns
1800 i.set_location (@1, @2);
1801 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1803 | CHORD_REPETITION optional_notemode_duration post_events {
1805 i.set_location (@1, @3);
1806 $$ = MAKE_SYNTAX ("repetition-chord", i,
1807 PARSER->lexer_->chord_repetition_.last_chord_,
1808 PARSER->lexer_->chord_repetition_.repetition_function_,
1809 $2, scm_reverse_x ($3, SCM_EOL));
1811 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1813 i.set_location (@1, @3);
1814 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1815 scm_reverse_x ($3, SCM_EOL));
1818 /* note chord elements are memorized into
1819 PARSER->lexer_->chord_repetition_ so that the chord repetition
1820 mechanism copy them when a chord repetition symbol is found
1822 | note_chord_element {
1823 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
1829 chord_body optional_notemode_duration post_events
1831 Music *m = unsmob_music ($1);
1832 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1833 SCM es = m->get_property ("elements");
1834 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1836 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1837 unsmob_music (scm_car (s))->set_property ("duration", dur);
1838 es = ly_append2 (es, postevs);
1840 m-> set_property ("elements", es);
1842 $$ = m->self_scm ();
1847 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1849 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1853 chord_body_elements:
1854 /* empty */ { $$ = SCM_EOL; }
1855 | chord_body_elements chord_body_element {
1856 $$ = scm_cons ($2, $1);
1861 pitch exclamations questions octave_check post_events
1868 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1869 n->set_property ("pitch", $1);
1871 n->set_property ("cautionary", SCM_BOOL_T);
1872 if (ex % 2 || q % 2)
1873 n->set_property ("force-accidental", SCM_BOOL_T);
1875 if (scm_is_pair (post)) {
1876 SCM arts = scm_reverse_x (post, SCM_EOL);
1877 n->set_property ("articulations", arts);
1879 if (scm_is_number (check))
1881 int q = scm_to_int (check);
1882 n->set_property ("absolute-octave", scm_from_int (q-1));
1885 $$ = n->unprotect ();
1887 | DRUM_PITCH post_events {
1888 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1889 n->set_property ("drum-type", $1);
1891 if (scm_is_pair ($2)) {
1892 SCM arts = scm_reverse_x ($2, SCM_EOL);
1893 n->set_property ("articulations", arts);
1895 $$ = n->unprotect ();
1897 | music_function_chord_body
1900 /* We can't accept a music argument, not even a closed one,
1901 * immediately before chord_body_elements, otherwise a function \fun
1902 * with a signature of two music arguments can't be sorted out
1903 * properly in a construct like
1904 * <\fun { c } \fun { c } c>
1905 * The second call could be interpreted either as a chord constituent
1906 * or a music expression.
1909 music_function_chord_body_arglist:
1910 function_arglist_bare
1911 | EXPECT_SCM music_function_chord_body_arglist embedded_scm_chord_body
1913 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1918 embedded_scm_chord_body:
1919 embedded_scm_bare_arg
1920 | SCM_FUNCTION music_function_chord_body_arglist {
1921 $$ = MAKE_SYNTAX ("music-function", @$,
1924 | chord_body_element
1927 music_function_chord_body:
1928 MUSIC_FUNCTION music_function_chord_body_arglist {
1929 $$ = MAKE_SYNTAX ("music-function", @$,
1934 /* We could accept a closed music argument before the post events
1935 * indicated by a trailing argument list. For symmetry with chord
1936 * bodies and in order to avoid too tricky and complex behavior, we
1937 * refrain from doing so.
1939 music_function_event_arglist:
1940 function_arglist_bare
1941 | EXPECT_SCM music_function_event_arglist embedded_scm_event
1943 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1949 embedded_scm_bare_arg
1950 | SCM_FUNCTION music_function_event_arglist {
1951 $$ = MAKE_SYNTAX ("music-function", @$,
1957 music_function_event:
1958 MUSIC_FUNCTION music_function_event_arglist {
1959 $$ = MAKE_SYNTAX ("music-function", @$,
1964 event_function_event:
1965 EVENT_FUNCTION music_function_event_arglist {
1966 $$ = MAKE_SYNTAX ("music-function", @$,
1976 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1977 m->set_property ("span-direction", scm_from_int (START));
1978 $$ = m->unprotect();
1981 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1982 m->set_property ("span-direction", scm_from_int (STOP));
1983 $$ = m->unprotect ();
1986 $$ = MAKE_SYNTAX ("voice-separator", @$);
1989 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1991 Music *m = unsmob_music (pipe);
1996 $$ = m->unprotect ();
1999 $$ = MAKE_SYNTAX ("bar-check", @$);
2003 SCM proc = ly_lily_module_constant ("make-time-signature-set");
2005 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
2008 $$ = MAKE_SYNTAX ("make-mark-set", @$, $2);
2014 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2017 Music *m = MY_MAKE_MUSIC ("MarkEvent", @$);
2018 $$ = m->unprotect ();
2030 | post_events post_event {
2031 unsmob_music ($2)->set_spot (@2);
2032 $$ = scm_cons ($2, $$);
2036 post_event_nofinger:
2037 direction_less_event {
2040 | script_dir music_function_event {
2044 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2048 if (!PARSER->lexer_->is_lyric_state ())
2049 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2050 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2053 if (!PARSER->lexer_->is_lyric_state ())
2054 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2055 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2057 | script_dir direction_reqd_event {
2060 Music *m = unsmob_music ($2);
2061 m->set_property ("direction", scm_from_int ($1));
2065 | script_dir direction_less_event {
2068 Music *m = unsmob_music ($2);
2069 m->set_property ("direction", scm_from_int ($1));
2073 | string_number_event
2078 | script_dir fingering {
2081 Music *m = unsmob_music ($2);
2082 m->set_property ("direction", scm_from_int ($1));
2088 string_number_event:
2090 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2091 s->set_property ("string-number", scm_from_int ($1));
2092 $$ = s->unprotect ();
2096 direction_less_char:
2098 $$ = ly_symbol2scm ("bracketOpenSymbol");
2101 $$ = ly_symbol2scm ("bracketCloseSymbol");
2104 $$ = ly_symbol2scm ("tildeSymbol");
2107 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2110 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2113 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2116 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2119 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2122 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2125 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2129 direction_less_event:
2130 direction_less_char {
2131 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
2133 if (unsmob_music (predefd))
2135 m = unsmob_music (predefd)->clone ();
2140 m = MY_MAKE_MUSIC ("Music", @$);
2142 $$ = m->unprotect ();
2144 | EVENT_IDENTIFIER {
2148 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2149 a->set_property ("tremolo-type", scm_from_int ($1));
2150 $$ = a->unprotect ();
2152 | event_function_event
2155 direction_reqd_event:
2159 | script_abbreviation {
2160 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2161 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2162 if (scm_is_string (s))
2163 a->set_property ("articulation-type", s);
2164 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
2165 $$ = a->unprotect ();
2170 /**/ { $$ = SCM_EOL; }
2171 | '=' { $$ = scm_from_int (0); }
2172 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2173 | '=' sup_quotes { $$ = scm_from_int ($2); }
2198 | NOTENAME_PITCH sup_quotes {
2199 Pitch p = *unsmob_pitch ($1);
2200 p = p.transposed (Pitch ($2,0,0));
2201 $$ = p.smobbed_copy ();
2203 | NOTENAME_PITCH sub_quotes {
2204 Pitch p =* unsmob_pitch ($1);
2205 p = p.transposed (Pitch (-$2,0,0));
2206 $$ = p.smobbed_copy ();
2218 | TONICNAME_PITCH sup_quotes {
2219 Pitch p = *unsmob_pitch ($1);
2220 p = p.transposed (Pitch ($2,0,0));
2221 $$ = p.smobbed_copy ();
2223 | TONICNAME_PITCH sub_quotes {
2224 Pitch p = *unsmob_pitch ($1);
2226 p = p.transposed (Pitch (-$2,0,0));
2227 $$ = p.smobbed_copy ();
2238 pitch_also_in_chords:
2245 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2246 t->set_property ("text", $1);
2247 $$ = t->unprotect ();
2250 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2251 t->set_property ("text",
2252 make_simple_markup ($1));
2253 $$ = t->unprotect ();
2259 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2260 t->set_property ("digit", $1);
2261 $$ = t->unprotect ();
2265 script_abbreviation:
2267 $$ = scm_from_locale_string ("Hat");
2270 $$ = scm_from_locale_string ("Plus");
2273 $$ = scm_from_locale_string ("Dash");
2276 $$ = scm_from_locale_string ("Bar");
2279 $$ = scm_from_locale_string ("Larger");
2282 $$ = scm_from_locale_string ("Dot");
2285 $$ = scm_from_locale_string ("Underscore");
2292 | '-' { $$ = CENTER; }
2296 multiplied_duration {
2301 optional_notemode_duration:
2303 Duration dd = PARSER->default_duration_;
2304 $$ = dd.smobbed_copy ();
2306 | multiplied_duration {
2308 PARSER->default_duration_ = *unsmob_duration ($$);
2313 bare_unsigned dots {
2315 if (!is_duration ($1))
2316 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
2320 $$ = Duration (len, $2).smobbed_copy ();
2322 | DURATION_IDENTIFIER dots {
2323 Duration *d = unsmob_duration ($1);
2324 Duration k (d->duration_log (), d->dot_count () + $2);
2325 k = k.compressed (d->factor ());
2331 multiplied_duration:
2335 | multiplied_duration '*' bare_unsigned {
2336 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2338 | multiplied_duration '*' FRACTION {
2339 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2341 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2346 FRACTION { $$ = $1; }
2347 | UNSIGNED '/' UNSIGNED {
2348 $$ = scm_cons ($1, $3);
2365 | ':' bare_unsigned {
2366 if (!is_duration ($2))
2367 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2373 UNSIGNED { $$ = $1; }
2374 | STRING { $$ = $1; }
2375 | full_markup { $$ = $1; }
2378 figured_bass_alteration:
2379 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2380 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2381 | '!' { $$ = scm_from_int (0); }
2386 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2387 $$ = bfr->unprotect ();
2390 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2391 $$ = bfr->self_scm ();
2393 if (scm_is_number ($1))
2394 bfr->set_property ("figure", $1);
2395 else if (Text_interface::is_markup ($1))
2396 bfr->set_property ("text", $1);
2402 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2404 | bass_figure figured_bass_alteration {
2405 Music *m = unsmob_music ($1);
2406 if (scm_to_double ($2)) {
2407 SCM salter = m->get_property ("alteration");
2408 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2409 m->set_property ("alteration",
2410 scm_sum (alter, $2));
2412 m->set_property ("alteration", scm_from_int (0));
2415 | bass_figure figured_bass_modification {
2416 Music *m = unsmob_music ($1);
2417 if ($2 == ly_symbol2scm ("plus"))
2419 m->set_property ("augmented", SCM_BOOL_T);
2421 else if ($2 == ly_symbol2scm ("slash"))
2423 m->set_property ("diminished", SCM_BOOL_T);
2425 else if ($2 == ly_symbol2scm ("exclamation"))
2427 m->set_property ("no-continuation", SCM_BOOL_T);
2429 else if ($2 == ly_symbol2scm ("backslash"))
2431 m->set_property ("augmented-slash", SCM_BOOL_T);
2437 figured_bass_modification:
2439 $$ = ly_symbol2scm ("plus");
2442 $$ = ly_symbol2scm ("exclamation");
2445 $$ = ly_symbol2scm ("slash");
2448 $$ = ly_symbol2scm ("backslash");
2458 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2466 | figure_list br_bass_figure {
2467 $$ = scm_cons ($2, $1);
2472 FIGURE_OPEN figure_list FIGURE_CLOSE {
2473 $$ = scm_reverse_x ($2, SCM_EOL);
2484 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2485 if (!PARSER->lexer_->is_note_state ())
2486 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2490 n = MY_MAKE_MUSIC ("RestEvent", @$);
2492 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2494 n->set_property ("pitch", $1);
2495 n->set_property ("duration", $5);
2497 if (scm_is_number ($4))
2499 int q = scm_to_int ($4);
2500 n->set_property ("absolute-octave", scm_from_int (q-1));
2504 n->set_property ("cautionary", SCM_BOOL_T);
2505 if ($2 % 2 || $3 % 2)
2506 n->set_property ("force-accidental", SCM_BOOL_T);
2508 $$ = n->unprotect ();
2510 | DRUM_PITCH optional_notemode_duration {
2511 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2512 n->set_property ("duration", $2);
2513 n->set_property ("drum-type", $1);
2515 $$ = n->unprotect ();
2517 | RESTNAME optional_notemode_duration {
2519 if (ly_scm2string ($1) == "s") {
2521 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2524 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2527 ev->set_property ("duration", $2);
2528 $$ = ev->unprotect ();
2530 | lyric_element optional_notemode_duration {
2531 if (!PARSER->lexer_->is_lyric_state ())
2532 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2534 Music *levent = MY_MAKE_MUSIC ("LyricEvent", @$);
2535 levent->set_property ("text", $1);
2536 levent->set_property ("duration",$2);
2537 $$= levent->unprotect ();
2541 simple_chord_elements:
2543 $$ = scm_list_1 ($1);
2546 if (!PARSER->lexer_->is_chord_state ())
2547 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2550 | figure_spec optional_notemode_duration {
2551 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2553 unsmob_music (scm_car (s))->set_property ("duration", $2);
2569 steno_tonic_pitch optional_notemode_duration {
2570 $$ = make_chord_elements ($1, $2, SCM_EOL);
2572 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2573 SCM its = scm_reverse_x ($4, SCM_EOL);
2574 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2582 | chord_items chord_item {
2583 $$ = scm_cons ($2, $$);
2589 $$ = ly_symbol2scm ("chord-colon");
2592 $$ = ly_symbol2scm ("chord-caret");
2594 | CHORD_SLASH steno_tonic_pitch {
2595 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2597 | CHORD_BASS steno_tonic_pitch {
2598 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2607 $$ = scm_reverse_x ($1, SCM_EOL);
2615 step_number { $$ = scm_cons ($1, SCM_EOL); }
2616 | step_numbers '.' step_number {
2617 $$ = scm_cons ($3, $$);
2623 $$ = make_chord_step ($1, 0);
2625 | bare_unsigned '+' {
2626 $$ = make_chord_step ($1, SHARP_ALTERATION);
2628 | bare_unsigned CHORD_MINUS {
2629 $$ = make_chord_step ($1, FLAT_ALTERATION);
2635 $$ = scm_from_int ($1);
2637 | bare_unsigned '~' bare_unsigned {
2638 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2645 TODO: should deprecate in favor of Scheme?
2649 number_expression '+' number_term {
2650 $$ = scm_sum ($1, $3);
2652 | number_expression '-' number_term {
2653 $$ = scm_difference ($1, $3);
2662 | number_factor '*' number_factor {
2663 $$ = scm_product ($1, $3);
2665 | number_factor '/' number_factor {
2666 $$ = scm_divide ($1, $3);
2671 '-' number_factor { /* %prec UNARY_MINUS */
2672 $$ = scm_difference ($2, SCM_UNDEFINED);
2680 | UNSIGNED NUMBER_IDENTIFIER {
2681 $$ = scm_product ($1, $2)
2683 | REAL NUMBER_IDENTIFIER {
2684 $$ = scm_product ($1, $2)
2696 $$ = scm_to_int ($1);
2707 | exclamations '!' { $$ ++; }
2712 | questions '?' { $$ ++; }
2716 This should be done more dynamically if possible.
2720 LYRIC_MARKUP_IDENTIFIER {
2724 { PARSER->lexer_->push_markup_state (); }
2727 PARSER->lexer_->pop_state ();
2732 MARKUPLIST_IDENTIFIER {
2736 { PARSER->lexer_->push_markup_state (); }
2739 PARSER->lexer_->pop_state ();
2748 { PARSER->lexer_->push_markup_state (); }
2751 PARSER->lexer_->pop_state ();
2757 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2759 | markup_head_1_list simple_markup {
2760 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2768 MARKUPLIST_IDENTIFIER {
2771 | markup_composed_list {
2774 | markup_braced_list {
2777 | markup_command_list {
2778 $$ = scm_list_1 ($1);
2782 markup_composed_list:
2783 markup_head_1_list markup_braced_list {
2784 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2790 '{' markup_braced_list_body '}' {
2791 $$ = scm_reverse_x ($2, SCM_EOL);
2795 markup_braced_list_body:
2796 /* empty */ { $$ = SCM_EOL; }
2797 | markup_braced_list_body markup {
2798 $$ = scm_cons ($2, $1);
2800 | markup_braced_list_body markup_list {
2801 $$ = scm_reverse_x ($2, $1);
2805 markup_command_list:
2806 MARKUP_LIST_FUNCTION markup_command_list_arguments {
2807 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
2811 markup_command_basic_arguments:
2812 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
2813 $$ = scm_cons ($3, $2);
2815 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
2816 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED, $3, $2, $1);
2818 | EXPECT_NO_MORE_ARGS {
2823 markup_command_list_arguments:
2824 markup_command_basic_arguments { $$ = $1; }
2825 | EXPECT_MARKUP markup_command_list_arguments markup {
2826 $$ = scm_cons ($3, $2);
2831 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
2832 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
2837 markup_head_1_item {
2838 $$ = scm_list_1 ($1);
2840 | markup_head_1_list markup_head_1_item {
2841 $$ = scm_cons ($2, $1);
2847 $$ = make_simple_markup ($1);
2849 | MARKUP_IDENTIFIER {
2852 | LYRIC_MARKUP_IDENTIFIER {
2855 | STRING_IDENTIFIER {
2859 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2860 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2861 } '{' score_body '}' {
2863 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2865 PARSER->lexer_->pop_state ();
2867 | MARKUP_FUNCTION markup_command_basic_arguments {
2868 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
2873 markup_head_1_list simple_markup {
2874 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2875 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2885 Lily_parser::set_yydebug (bool x)
2891 Lily_parser::do_yyparse ()
2893 yyparse ((void*)this);
2902 It is a little strange to have this function in this file, but
2903 otherwise, we have to import music classes into the lexer.
2907 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2909 if (scm_is_string (sid)) {
2911 return STRING_IDENTIFIER;
2912 } else if (unsmob_book (sid)) {
2913 Book *book = unsmob_book (sid)->clone ();
2914 *destination = book->self_scm ();
2917 return BOOK_IDENTIFIER;
2918 } else if (scm_is_number (sid)) {
2920 return NUMBER_IDENTIFIER;
2921 } else if (unsmob_context_def (sid)) {
2922 Context_def *def= unsmob_context_def (sid)->clone ();
2924 *destination = def->self_scm ();
2927 return CONTEXT_DEF_IDENTIFIER;
2928 } else if (unsmob_context_mod (sid)) {
2929 *destination = unsmob_context_mod (sid)->smobbed_copy ();
2931 return CONTEXT_MOD_IDENTIFIER;
2932 } else if (unsmob_score (sid)) {
2933 Score *score = new Score (*unsmob_score (sid));
2934 *destination = score->self_scm ();
2936 score->unprotect ();
2937 return SCORE_IDENTIFIER;
2938 } else if (Music *mus = unsmob_music (sid)) {
2939 mus = mus->clone ();
2940 *destination = mus->self_scm ();
2941 unsmob_music (*destination)->
2942 set_property ("origin", make_input (last_input_));
2944 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2948 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2949 } else if (unsmob_pitch (sid)) {
2950 *destination = unsmob_pitch (sid)->smobbed_copy ();
2951 return PITCH_IDENTIFIER;
2952 } else if (unsmob_duration (sid)) {
2953 *destination = unsmob_duration (sid)->smobbed_copy ();
2954 return DURATION_IDENTIFIER;
2955 } else if (unsmob_output_def (sid)) {
2956 Output_def *p = unsmob_output_def (sid);
2959 *destination = p->self_scm ();
2961 return OUTPUT_DEF_IDENTIFIER;
2962 } else if (Text_interface::is_markup (sid)) {
2964 if (is_lyric_state ())
2965 return LYRIC_MARKUP_IDENTIFIER;
2966 return MARKUP_IDENTIFIER;
2967 } else if (Text_interface::is_markup_list (sid)) {
2969 return MARKUPLIST_IDENTIFIER;
2976 get_next_unique_context_id ()
2978 return scm_from_locale_string ("$uniqueContextId");
2983 get_next_unique_lyrics_context_id ()
2985 static int new_context_count;
2987 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2988 return scm_from_locale_string (s);
2991 SCM check_scheme_arg (Lily_parser *my_lily_parser, Input loc, SCM fallback,
2992 SCM arg, SCM args, SCM pred)
2994 SCM unwrap = SCM_UNDEFINED;
2995 if (scm_is_true (scm_call_1 (pred, arg)))
2996 return scm_cons (arg, args);
2997 unwrap = try_unpack_lyrics (pred, arg);
2998 if (!SCM_UNBNDP (unwrap))
2999 return scm_cons (unwrap, args);
3000 if (SCM_UNBNDP (fallback)) {
3001 args = scm_cons (SCM_BOOL_F, args);
3002 fallback = SCM_BOOL_F;
3004 args = scm_cons (loc_on_music (loc, fallback), args);
3005 fallback = SCM_CDR (scm_last_pair (args));
3007 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3008 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3009 scm_set_cdr_x (scm_last_pair (args), fallback);
3013 SCM loc_on_music (Input loc, SCM arg)
3015 if (Music *m = unsmob_music (arg))
3019 return m->unprotect ();
3025 is_regular_identifier (SCM id)
3027 string str = ly_scm2string (id);
3028 char const *s = str.c_str ();
3037 v = v && isalnum (*s);
3044 make_music_with_input (SCM name, Input where)
3046 Music *m = make_music_by_name (name);
3047 m->set_spot (where);
3052 get_first_context_id (SCM type, Music *m)
3054 SCM id = m->get_property ("context-id");
3055 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
3056 && scm_is_string (m->get_property ("context-id"))
3057 && scm_c_string_length (id) > 0)
3065 make_simple_markup (SCM a)
3073 return t && t == 1 << intlog2 (t);
3077 set_music_properties (Music *p, SCM a)
3079 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3080 p->set_property (scm_caar (k), scm_cdar (k));
3085 make_chord_step (int step, Rational alter)
3088 alter += FLAT_ALTERATION;
3092 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3093 return m.smobbed_copy ();
3098 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
3100 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3101 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
3105 try_unpack_lyrics (SCM pred, SCM arg)
3107 if (Music *m = unsmob_music (arg))
3108 if (m->is_mus_type ("lyric-event")) {
3109 SCM text = m->get_property ("text");
3110 if (scm_is_true (scm_call_1 (pred, text)))
3113 return SCM_UNDEFINED;
3116 /* Todo: actually also use apply iso. call too ... */
3118 ly_input_procedure_p (SCM x)
3120 return ly_is_procedure (x)
3121 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
3125 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
3127 Lily_parser *pars = (Lily_parser*) v;
3128 Lily_lexer *lex = pars->lexer_;
3130 lex->lexval_ = (void*) s;
3132 lex->prepare_for_next_token ();
3133 return lex->yylex ();