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
85 * function arguments, just like fractions and tremoli. Tremoli must
86 * not have higher precedence than UNSIGNED, or Lilypond will not
87 * join ':' with a following optional number.
100 %{ // -*-Fundamental-*-
105 * The rules for who is protecting what are very shady. Uniformise
108 * There are too many lexical modes?
119 #include "context-def.hh"
120 #include "context-mod.hh"
121 #include "dimensions.hh"
122 #include "file-path.hh"
124 #include "international.hh"
125 #include "lily-guile.hh"
126 #include "lily-lexer.hh"
127 #include "lily-parser.hh"
131 #include "output-def.hh"
132 #include "paper-book.hh"
133 #include "scm-hash.hh"
135 #include "text-interface.hh"
138 #define MYBACKUP(Token, Value, Location) \
140 if (yychar == YYEMPTY) \
143 PARSER->lexer_->push_extra_token (Token, Value); \
144 PARSER->lexer_->push_extra_token (BACKUP); \
146 PARSER->parser_error \
147 (Location, _("Too much lookahead")); \
152 #define MYREPARSE(Location, Default, Pred, Token, Value) \
154 if (yychar == YYEMPTY) \
156 PARSER->lexer_->push_extra_token (Token, Value); \
157 if (Default != SCM_UNDEFINED) \
158 PARSER->lexer_->push_extra_token (REPARSE, \
159 scm_cons (Default, Pred)); \
161 PARSER->lexer_->push_extra_token (REPARSE, \
164 PARSER->parser_error \
165 (Location, _("Too much lookahead")); \
174 Output_def *outputdef;
183 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
186 - Don't use lily module, create a new module instead.
187 - delay application of the function
189 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
190 scm_apply_0 (proc, args)
191 /* Syntactic Sugar. */
192 #define MAKE_SYNTAX(name, location, ...) \
193 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location) , ##__VA_ARGS__, SCM_UNDEFINED));
194 #define START_MAKE_SYNTAX(name, ...) \
195 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
196 #define FINISH_MAKE_SYNTAX(start, location, ...) \
197 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)))))
199 SCM get_next_unique_context_id ();
200 SCM get_next_unique_lyrics_context_id ();
207 #define _(x) gettext (x)
211 static Music *make_music_with_input (SCM name, Input where);
212 SCM check_scheme_arg (Lily_parser *parser, Input loc, SCM fallback,
213 SCM arg, SCM args, SCM pred);
214 SCM loc_on_music (Input loc, SCM arg);
215 SCM get_first_context_id (SCM type, Music *m);
216 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
217 SCM make_chord_step (int step, Rational alter);
218 SCM make_simple_markup (SCM a);
219 SCM try_unpack_lyrics (SCM pred, SCM arg);
220 bool is_duration (int t);
221 bool is_regular_identifier (SCM id);
222 bool ly_input_procedure_p (SCM x);
223 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
224 void set_music_properties (Music *p, SCM a);
228 /* The third option is an alias that will be used to display the
229 syntax error. Bison CVS now correctly handles backslash escapes.
231 FIXME: Bison needs to translate some of these, eg, STRING.
235 /* Keyword tokens with plain escaped name. */
236 %token ACCEPTS "\\accepts"
237 %token ADDLYRICS "\\addlyrics"
238 %token ALIAS "\\alias"
239 %token ALTERNATIVE "\\alternative"
241 %token BOOKPART "\\bookpart"
242 %token CHANGE "\\change"
243 %token CHORDMODE "\\chordmode"
244 %token CHORDS "\\chords"
245 %token CONSISTS "\\consists"
246 %token CONTEXT "\\context"
247 %token DEFAULT "\\default"
248 %token DEFAULTCHILD "\\defaultchild"
249 %token DENIES "\\denies"
250 %token DESCRIPTION "\\description"
251 %token DRUMMODE "\\drummode"
252 %token DRUMS "\\drums"
253 %token FIGUREMODE "\\figuremode"
254 %token FIGURES "\\figures"
255 %token GROBDESCRIPTIONS "\\grobdescriptions"
256 %token HEADER "\\header"
257 %token INVALID "\\version-error"
258 %token LAYOUT "\\layout"
259 %token LYRICMODE "\\lyricmode"
260 %token LYRICS "\\lyrics"
261 %token LYRICSTO "\\lyricsto"
262 %token MARKUP "\\markup"
263 %token MARKUPLIST "\\markuplist"
266 %token NOTEMODE "\\notemode"
267 %token OVERRIDE "\\override"
268 %token PAPER "\\paper"
269 %token REMOVE "\\remove"
270 %token REPEAT "\\repeat"
272 %token REVERT "\\revert"
273 %token SCORE "\\score"
274 %token SEQUENTIAL "\\sequential"
276 %token SIMULTANEOUS "\\simultaneous"
277 %token TEMPO "\\tempo"
279 %token UNSET "\\unset"
282 /* Keyword token exceptions. */
283 %token NEWCONTEXT "\\new"
286 /* Other string tokens. */
288 %token CHORD_BASS "/+"
289 %token CHORD_CARET "^"
290 %token CHORD_COLON ":"
291 %token CHORD_MINUS "-"
292 %token CHORD_SLASH "/"
293 %token ANGLE_OPEN "<"
294 %token ANGLE_CLOSE ">"
295 %token DOUBLE_ANGLE_OPEN "<<"
296 %token DOUBLE_ANGLE_CLOSE ">>"
297 %token E_BACKSLASH "\\"
298 %token E_ANGLE_CLOSE "\\>"
299 %token E_CHAR "\\C[haracter]"
301 %token E_EXCLAMATION "\\!"
302 %token E_BRACKET_OPEN "\\["
304 %token E_BRACKET_CLOSE "\\]"
305 %token E_ANGLE_OPEN "\\<"
311 If we give names, Bison complains.
313 %token FIGURE_CLOSE /* "\\>" */
314 %token FIGURE_OPEN /* "\\<" */
315 %token FIGURE_SPACE "_"
318 %token CHORDMODIFIERS
320 %token MULTI_MEASURE_REST
323 %token <i> E_UNSIGNED
324 %token <scm> UNSIGNED
326 /* Artificial tokens, for more generic function syntax */
327 %token <i> EXPECT_MARKUP "markup?"
328 %token <i> EXPECT_PITCH "ly:pitch?"
329 %token <i> EXPECT_DURATION "ly:duration?"
330 %token <scm> EXPECT_SCM "scheme?"
331 %token <scm> BACKUP "(backed-up?)"
332 %token <scm> REPARSE "(reparsed?)"
333 %token <i> EXPECT_MARKUP_LIST "markup-list?"
334 %token <scm> EXPECT_OPTIONAL "optional?"
335 /* After the last argument. */
336 %token <i> EXPECT_NO_MORE_ARGS;
338 /* An artificial token for parsing embedded Lilypond */
339 %token <i> EMBEDDED_LILY "#{"
341 %token <scm> BOOK_IDENTIFIER
342 %token <scm> CHORDMODIFIER_PITCH
343 %token <scm> CHORD_MODIFIER
344 %token <scm> CHORD_REPETITION
345 %token <scm> CONTEXT_DEF_IDENTIFIER
346 %token <scm> CONTEXT_MOD_IDENTIFIER
347 %token <scm> DRUM_PITCH
348 %token <scm> PITCH_IDENTIFIER
349 %token <scm> DURATION_IDENTIFIER
350 %token <scm> EVENT_IDENTIFIER
351 %token <scm> EVENT_FUNCTION
352 %token <scm> FRACTION
353 %token <scm> LYRICS_STRING
354 %token <scm> LYRIC_ELEMENT
355 %token <scm> LYRIC_ELEMENT_P
356 %token <scm> LYRIC_MARKUP_IDENTIFIER
357 %token <scm> MARKUP_FUNCTION
358 %token <scm> MARKUP_LIST_FUNCTION
359 %token <scm> MARKUP_IDENTIFIER
360 %token <scm> MARKUPLIST_IDENTIFIER
361 %token <scm> MUSIC_FUNCTION
362 %token <scm> MUSIC_IDENTIFIER
363 %token <scm> NOTENAME_PITCH
364 %token <scm> NUMBER_IDENTIFIER
365 %token <scm> OUTPUT_DEF_IDENTIFIER
367 %token <scm> RESTNAME
368 %token <scm> SCM_FUNCTION
369 %token <scm> SCM_IDENTIFIER
370 %token <scm> SCM_TOKEN
371 %token <scm> SCORE_IDENTIFIER
373 %token <scm> STRING_IDENTIFIER
374 %token <scm> TONICNAME_PITCH
377 %type <book> book_block
378 %type <book> book_body
379 %type <book> bookpart_block
380 %type <book> bookpart_body
382 %type <i> bare_unsigned
383 %type <scm> figured_bass_alteration
385 %type <i> exclamations
386 %type <i> optional_rest
391 %type <i> tremolo_type
394 %type <scm> composite_music
395 %type <scm> grouped_music_list
396 %type <scm> braced_music_list
397 %type <scm> closed_music
399 %type <scm> music_bare
400 %type <scm> music_arg
401 %type <scm> complex_music
402 %type <scm> complex_music_prefix
403 %type <scm> mode_changed_music
404 %type <scm> repeated_music
405 %type <scm> sequential_music
406 %type <scm> simple_music
407 %type <scm> simultaneous_music
408 %type <scm> chord_body
409 %type <scm> chord_body_element
410 %type <scm> command_element
411 %type <scm> command_event
412 %type <scm> context_modification
413 %type <scm> context_change
414 %type <scm> direction_less_event
415 %type <scm> direction_reqd_event
416 %type <scm> embedded_lilypond
417 %type <scm> event_chord
418 %type <scm> fingering
419 %type <scm> gen_text_def
420 %type <scm> music_property_def
421 %type <scm> note_chord_element
422 %type <scm> post_event
423 %type <scm> post_event_nofinger
424 %type <scm> re_rhythmed_music
425 %type <scm> simple_element
426 %type <scm> simple_music_property_def
427 %type <scm> start_symbol
428 %type <scm> string_number_event
429 %type <scm> tempo_event
431 %type <outputdef> output_def_body
432 %type <outputdef> output_def_head
433 %type <outputdef> output_def_head_with_mode_switch
434 %type <outputdef> output_def
435 %type <outputdef> paper_block
437 %type <scm> music_function_call
438 %type <scm> music_list
439 %type <scm> assignment_id
440 %type <scm> bare_number
441 %type <scm> bare_number_closed
442 %type <scm> unsigned_number
443 %type <scm> bass_figure
444 %type <scm> figured_bass_modification
445 %type <scm> br_bass_figure
446 %type <scm> bass_number
447 %type <scm> chord_body_elements
448 %type <scm> chord_item
449 %type <scm> chord_items
450 %type <scm> chord_separator
451 %type <scm> context_def_mod
452 %type <scm> context_def_spec_block
453 %type <scm> context_def_spec_body
454 %type <scm> context_mod
455 %type <scm> context_mod_list
456 %type <scm> context_prop_spec
457 %type <scm> direction_less_char
458 %type <scm> duration_length
459 %type <scm> embedded_scm
460 %type <scm> embedded_scm_arg
461 %type <scm> embedded_scm_arg_closed
462 %type <scm> embedded_scm_bare
463 %type <scm> embedded_scm_bare_arg
464 %type <scm> embedded_scm_closed
465 %type <scm> embedded_scm_chord_body
466 %type <scm> event_function_event
467 %type <scm> figure_list
468 %type <scm> figure_spec
470 %type <scm> full_markup
471 %type <scm> full_markup_list
472 %type <scm> function_arglist
473 %type <scm> function_arglist_optional
474 %type <scm> function_arglist_backup
475 %type <scm> function_arglist_nonbackup
476 %type <scm> function_arglist_skip
477 %type <scm> function_arglist_bare
478 %type <scm> function_arglist_closed
479 %type <scm> function_arglist_closed_optional
480 %type <scm> function_arglist_common
481 %type <scm> function_arglist_common_lyric
482 %type <scm> function_arglist_closed_common
483 %type <scm> function_arglist_keep
484 %type <scm> function_arglist_closed_keep
485 %type <scm> identifier_init
487 %type <scm> lilypond_header
488 %type <scm> lilypond_header_body
489 %type <scm> lyric_element
490 %type <scm> lyric_element_arg
491 %type <scm> lyric_element_music
492 %type <scm> lyric_markup
494 %type <scm> markup_braced_list
495 %type <scm> markup_braced_list_body
496 %type <scm> markup_composed_list
497 %type <scm> markup_command_list
498 %type <scm> markup_command_list_arguments
499 %type <scm> markup_command_basic_arguments
500 %type <scm> markup_head_1_item
501 %type <scm> markup_head_1_list
502 %type <scm> markup_list
503 %type <scm> markup_top
504 %type <scm> mode_changing_head
505 %type <scm> mode_changing_head_with_context
506 %type <scm> multiplied_duration
507 %type <scm> music_function_event
508 %type <scm> music_function_chord_body
509 %type <scm> music_function_chord_body_arglist
510 %type <scm> new_chord
511 %type <scm> new_lyrics
512 %type <scm> number_expression
513 %type <scm> number_factor
514 %type <scm> number_term
515 %type <scm> octave_check
516 %type <scm> optional_context_mod
517 %type <scm> optional_id
518 %type <scm> optional_notemode_duration
520 %type <scm> pitch_also_in_chords
521 %type <scm> post_events
522 %type <scm> property_operation
523 %type <scm> property_path property_path_revved
525 %type <scm> scalar_closed
526 %type <scm> scm_function_call
527 %type <scm> scm_function_call_closed
528 %type <scm> script_abbreviation
529 %type <scm> simple_chord_elements
530 %type <scm> simple_markup
531 %type <scm> simple_string
532 %type <scm> steno_duration
533 %type <scm> steno_pitch
534 %type <scm> steno_tonic_pitch
535 %type <scm> step_number
536 %type <scm> step_numbers
538 %type <scm> tempo_range
540 %type <score> score_block
541 %type <score> score_body
546 /* We don't assign precedence to / and *, because we might need varied
547 prec levels in different prods */
556 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
557 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
558 } embedded_lilypond {
559 PARSER->lexer_->pop_state ();
560 PARSER->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
564 lilypond: /* empty */ { }
565 | lilypond toplevel_expression {
567 | lilypond assignment {
570 PARSER->error_level_ = 1;
573 PARSER->error_level_ = 1;
580 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
584 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
585 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
590 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
591 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
592 bookpart->unprotect ();
597 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
598 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
602 Music *music = unsmob_music ($1);
603 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
604 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
607 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
608 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
611 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
612 scm_call_2 (proc, PARSER->self_scm (), $1);
616 Output_def * od = $1;
618 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
619 id = ly_symbol2scm ("$defaultpaper");
620 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
621 id = ly_symbol2scm ("$defaultmidi");
622 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
623 id = ly_symbol2scm ("$defaultlayout");
625 PARSER->lexer_->set_identifier (id, od->self_scm ());
635 embedded_scm_bare_arg:
641 | context_modification
644 $$ = $1->self_scm ();
647 | context_def_spec_block
650 $$ = $1->self_scm ();
655 $$ = $1->self_scm ();
660 $$ = $1->self_scm ();
665 /* The generic version may end in music, or not */
673 embedded_scm_bare_arg
679 SCM_FUNCTION function_arglist {
680 $$ = MAKE_SYNTAX ("music-function", @$,
688 $$ = MAKE_SYNTAX ("void-music", @$);
691 | music music music_list {
692 $$ = MAKE_SYNTAX ("sequential-music", @$,
693 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
696 PARSER->error_level_ = 1;
698 | INVALID embedded_lilypond {
699 PARSER->error_level_ = 1;
704 lilypond_header_body:
706 $$ = get_header (PARSER);
707 PARSER->lexer_->add_scope ($$);
709 | lilypond_header_body assignment {
715 HEADER '{' lilypond_header_body '}' {
716 $$ = PARSER->lexer_->remove_scope ();
725 | LYRICS_STRING { $$ = $1; }
729 assignment_id '=' identifier_init {
730 PARSER->lexer_->set_identifier ($1, $3);
732 | assignment_id property_path '=' identifier_init {
733 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
734 PARSER->lexer_->set_identifier (path, $4);
737 TODO: devise standard for protection in parser.
739 The parser stack lives on the C-stack, which means that
740 all objects can be unprotected as soon as they're here.
750 $$ = $1->self_scm ();
754 $$ = $1->self_scm ();
758 $$ = $1->self_scm ();
762 $$ = $1->self_scm ();
765 | context_def_spec_block {
769 /* Hack: Create event-chord around standalone events.
770 Prevents the identifier from being interpreted as a post-event. */
771 Music *mus = unsmob_music ($1);
772 bool is_event = mus &&
773 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
778 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
780 | post_event_nofinger {
783 | number_expression {
798 | context_modification {
803 context_def_spec_block:
804 CONTEXT '{' context_def_spec_body '}'
810 context_def_spec_body:
812 $$ = Context_def::make_scm ();
813 unsmob_context_def ($$)->origin ()->set_spot (@$);
815 | CONTEXT_DEF_IDENTIFIER {
817 unsmob_context_def ($$)->origin ()->set_spot (@$);
819 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
820 Context_def*td = unsmob_context_def ($$);
822 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
823 SCM tag = scm_caar (p);
825 /* TODO: should make new tag "grob-definition" ? */
826 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
827 tag, scm_cons (scm_cdar (p), SCM_EOL)));
830 | context_def_spec_body context_mod {
831 unsmob_context_def ($$)->add_context_mod ($2);
833 | context_def_spec_body context_modification {
834 Context_def *td = unsmob_context_def ($$);
835 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
836 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
837 td->add_context_mod (scm_car (m));
845 BOOK '{' book_body '}' {
848 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
853 * Use 'handlers' like for toplevel-* stuff?
854 * grok \layout and \midi? */
858 init_papers (PARSER);
859 $$->origin ()->set_spot (@$);
860 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
861 $$->paper_->unprotect ();
862 push_paper (PARSER, $$->paper_);
863 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
864 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
865 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
866 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
869 $$ = unsmob_book ($1);
871 $$->origin ()->set_spot (@$);
872 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
874 | book_body paper_block {
877 set_paper (PARSER, $2);
879 | book_body bookpart_block {
881 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
882 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
883 bookpart->unprotect ();
885 | book_body score_block {
887 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
888 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
891 | book_body composite_music {
892 Music *music = unsmob_music ($2);
893 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
894 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
896 | book_body full_markup {
897 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
898 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
900 | book_body full_markup_list {
901 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
902 scm_call_2 (proc, $$->self_scm (), $2);
904 | book_body lilypond_header {
907 | book_body embedded_scm { }
910 $$->scores_ = SCM_EOL;
911 $$->bookparts_ = SCM_EOL;
916 BOOKPART '{' bookpart_body '}' {
918 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
925 $$->origin ()->set_spot (@$);
926 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
929 $$ = unsmob_book ($1);
931 $$->origin ()->set_spot (@$);
932 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
934 | bookpart_body paper_block {
938 | bookpart_body score_block {
940 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
941 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
944 | bookpart_body composite_music {
945 Music *music = unsmob_music ($2);
946 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
947 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
949 | bookpart_body full_markup {
950 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
951 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
953 | bookpart_body full_markup_list {
954 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
955 scm_call_2 (proc, $$->self_scm (), $2);
957 | bookpart_body lilypond_header {
960 | bookpart_body embedded_scm { }
961 | bookpart_body error {
963 $$->scores_ = SCM_EOL;
968 SCORE '{' score_body '}' {
976 SCM scorify = ly_lily_module_constant ("scorify-music");
977 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
979 // pass ownernship to C++ again.
980 $$ = unsmob_score (score);
982 $$->origin ()->set_spot (@$);
985 $$ = unsmob_score ($1);
987 $$->origin ()->set_spot (@$);
989 | score_body lilypond_header {
992 | score_body output_def {
993 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
995 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1000 $$->add_output_def ($2);
1004 | score_body error {
1005 $$->error_found_ = true;
1017 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1019 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
1021 $$ = get_paper (PARSER);
1028 output_def_body '}' {
1031 PARSER->lexer_->remove_scope ();
1032 PARSER->lexer_->pop_state ();
1038 $$ = get_paper (PARSER);
1039 $$->input_origin_ = @$;
1040 PARSER->lexer_->add_scope ($$->scope_);
1043 Output_def *p = get_midi (PARSER);
1045 PARSER->lexer_->add_scope (p->scope_);
1048 Output_def *p = get_layout (PARSER);
1050 PARSER->lexer_->add_scope (p->scope_);
1055 output_def_head_with_mode_switch:
1057 PARSER->lexer_->push_initial_state ();
1063 output_def_head_with_mode_switch '{' {
1065 $$->input_origin_.set_spot (@$);
1067 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1070 Output_def *o = unsmob_output_def ($3);
1071 o->input_origin_.set_spot (@$);
1074 PARSER->lexer_->remove_scope ();
1075 PARSER->lexer_->add_scope (o->scope_);
1077 | output_def_body assignment {
1080 | output_def_body context_def_spec_block {
1081 assign_context_def ($$, $2);
1083 | output_def_body error {
1089 TEMPO steno_duration '=' tempo_range {
1090 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1092 | TEMPO scalar_closed steno_duration '=' tempo_range {
1093 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1096 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1101 The representation of a list is reversed to have efficient append. */
1107 | music_list music {
1108 $$ = scm_cons ($2, $1);
1110 | music_list embedded_scm {
1113 | music_list error {
1114 Music *m = MY_MAKE_MUSIC("Music", @$);
1116 m->set_property ("error-found", SCM_BOOL_T);
1117 $$ = scm_cons (m->self_scm (), $1);
1118 m->unprotect (); /* UGH */
1125 $$ = scm_reverse_x ($2, SCM_EOL);
1130 | lyric_element_music
1131 | composite_music %prec COMPOSITE
1136 | composite_music %prec COMPOSITE
1140 REPEAT simple_string unsigned_number music
1142 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1144 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1146 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1151 SEQUENTIAL braced_music_list {
1152 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1154 | braced_music_list {
1155 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1160 SIMULTANEOUS braced_music_list {
1161 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1163 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1164 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1170 | music_property_def
1174 context_modification:
1175 WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1177 PARSER->lexer_->pop_state ();
1180 | WITH CONTEXT_MOD_IDENTIFIER
1184 | CONTEXT_MOD_IDENTIFIER
1190 optional_context_mod:
1194 | context_modification
1202 $$ = Context_mod ().smobbed_copy ();
1204 | context_mod_list context_mod {
1205 unsmob_context_mod ($1)->add_context_mod ($2);
1207 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1208 Context_mod *md = unsmob_context_mod ($2);
1210 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1219 /* Music that can be parsed without lookahead */
1222 | complex_music_prefix closed_music
1224 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1231 | grouped_music_list
1235 simultaneous_music { $$ = $1; }
1236 | sequential_music { $$ = $1; }
1239 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1240 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1241 and this rule returns the reversed list of arguments. */
1243 function_arglist_skip:
1244 function_arglist_common
1245 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1247 $$ = scm_cons ($1, $3);
1248 } %prec FUNCTION_ARGLIST
1249 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1251 $$ = scm_cons ($1, $3);
1252 } %prec FUNCTION_ARGLIST
1253 | EXPECT_SCM EXPECT_DURATION function_arglist_skip
1255 $$ = scm_cons ($1, $3);
1256 } %prec FUNCTION_ARGLIST
1260 function_arglist_nonbackup:
1261 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1262 $$ = scm_cons ($4, $3);
1264 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1265 $$ = scm_cons ($4, $3);
1267 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1269 $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
1271 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1273 $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
1275 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed fraction
1277 $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
1279 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event
1281 $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
1286 function_arglist_keep:
1287 function_arglist_common
1288 | function_arglist_backup
1291 function_arglist_closed_keep:
1292 function_arglist_closed_common
1293 | function_arglist_backup
1296 function_arglist_backup:
1297 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1299 if (scm_is_true (scm_call_1 ($2, $4)))
1301 $$ = scm_cons ($4, $3);
1303 $$ = scm_cons (loc_on_music (@3, $1), $3);
1304 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1307 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event
1309 if (scm_is_true (scm_call_1 ($2, $4)))
1311 $$ = scm_cons ($4, $3);
1313 $$ = scm_cons (loc_on_music (@3, $1), $3);
1314 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1317 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1319 // There is no point interpreting a lyrics string as
1320 // an event, since we don't allow music possibly
1321 // followed by durations or postevent into closed
1322 // music, and we only accept closed music in optional
1323 // arguments at the moment. If this changes, more
1324 // complex schemes might become interesting here as
1325 // well: see how we do this at the mandatory argument
1327 if (scm_is_true (scm_call_1 ($2, $4)))
1328 $$ = scm_cons ($3, $2);
1330 $$ = scm_cons (loc_on_music (@3, $1), $3);
1331 MYBACKUP (LYRIC_MARKUP_IDENTIFIER, $4, @4);
1334 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1336 if (scm_is_true (scm_call_1 ($2, $4)))
1339 MYREPARSE (@4, $1, $2, UNSIGNED, $4);
1341 $$ = scm_cons (loc_on_music (@3, $1), $3);
1342 MYBACKUP (UNSIGNED, $4, @4);
1345 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1347 if (scm_is_true (scm_call_1 ($2, $4)))
1350 MYREPARSE (@4, $1, $2, REAL, $4);
1352 $$ = scm_cons (loc_on_music (@3, $1), $3);
1353 MYBACKUP (REAL, $4, @4);
1356 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1358 if (scm_is_true (scm_call_1 ($2, $4)))
1360 $$ = scm_cons ($4, $3);
1362 $$ = scm_cons (loc_on_music (@3, $1), $3);
1363 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1366 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1368 if (scm_is_true (scm_call_1 ($2, $4)))
1370 $$ = scm_cons ($4, $3);
1372 $$ = scm_cons (loc_on_music (@3, $1), $3);
1373 MYBACKUP (FRACTION, $4, @4);
1376 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1378 $$ = scm_cons ($4, $3);
1380 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1382 $$ = scm_cons ($4, $3);
1384 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1386 $$ = scm_cons ($1, $3);
1387 MYBACKUP(0, SCM_UNDEFINED, @3);
1389 | function_arglist_backup REPARSE embedded_scm_arg_closed
1391 $$ = check_scheme_arg (PARSER, @3, scm_car ($2),
1392 $3, $1, scm_cdr ($2));
1394 | function_arglist_backup REPARSE bare_number
1396 $$ = check_scheme_arg (PARSER, @3, scm_car ($2),
1397 $3, $1, scm_cdr ($2));
1399 | function_arglist_backup REPARSE fraction
1401 $$ = check_scheme_arg (PARSER, @3, scm_car ($2),
1402 $3, $1, scm_cdr ($2));
1407 function_arglist_common
1408 | function_arglist_nonbackup
1411 function_arglist_common:
1412 function_arglist_bare
1413 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1415 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1418 | EXPECT_SCM function_arglist_closed_optional bare_number
1420 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1423 | EXPECT_SCM function_arglist_closed_optional fraction
1425 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1428 | EXPECT_SCM function_arglist_closed_optional post_event
1430 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1433 | function_arglist_common_lyric
1436 function_arglist_common_lyric:
1437 EXPECT_SCM function_arglist_optional lyric_element
1439 // We check how the predicate thinks about a lyrics
1440 // event or about a markup. If it accepts neither, we
1441 // backup the original token. Otherwise we commit to
1442 // taking the token. Depending on what the predicate
1443 // is willing to accept, we interpret as a string, as
1444 // a lyric event, or ambiguously (meaning that if
1445 // something looking like a duration or post event
1446 // follows, we take the event, otherwise the string).
1447 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1448 PARSER->default_duration_.smobbed_copy ());
1449 if (scm_is_true (scm_call_1 ($1, $3)))
1450 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1453 MYREPARSE (@3, SCM_UNDEFINED, $1, LYRIC_ELEMENT_P, $3);
1455 $$ = scm_cons ($3, $2);
1457 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1460 MYREPARSE (@3, SCM_UNDEFINED, $1, LYRIC_ELEMENT, $3);
1462 // This is going to flag a syntax error, we
1463 // know the predicate to be false.
1464 check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1468 | function_arglist_common_lyric REPARSE lyric_element_arg
1470 // This should never be false
1471 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1476 function_arglist_closed:
1477 function_arglist_closed_common
1478 | function_arglist_nonbackup
1481 function_arglist_closed_common:
1482 function_arglist_bare
1483 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1485 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1488 | EXPECT_SCM function_arglist_closed_optional bare_number_closed
1490 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1493 | EXPECT_SCM function_arglist_closed_optional post_event
1495 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1498 | EXPECT_SCM function_arglist_closed_optional FRACTION
1500 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1503 | EXPECT_SCM function_arglist_optional lyric_element
1505 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
1510 function_arglist_optional:
1511 function_arglist_keep %prec FUNCTION_ARGLIST
1512 | function_arglist_backup BACKUP
1513 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1515 $$ = scm_cons ($1, $3);
1517 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1519 $$ = scm_cons ($1, $3);
1523 function_arglist_closed_optional:
1524 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1525 | function_arglist_backup BACKUP
1526 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1528 $$ = scm_cons ($1, $3);
1530 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1532 $$ = scm_cons ($1, $3);
1536 embedded_scm_closed:
1538 | scm_function_call_closed
1541 embedded_scm_arg_closed:
1542 embedded_scm_bare_arg
1543 | scm_function_call_closed
1547 scm_function_call_closed:
1548 SCM_FUNCTION function_arglist_closed {
1549 $$ = MAKE_SYNTAX ("music-function", @$,
1551 } %prec FUNCTION_ARGLIST
1554 function_arglist_bare:
1555 EXPECT_NO_MORE_ARGS {
1558 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1559 $$ = scm_cons ($3, $2);
1561 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1562 $$ = scm_cons ($3, $2);
1564 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1565 $$ = scm_cons ($1, $3);
1567 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1568 $$ = scm_cons ($1, $3);
1570 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1571 $$ = scm_cons ($1, $3);
1575 music_function_call:
1576 MUSIC_FUNCTION function_arglist {
1577 $$ = MAKE_SYNTAX ("music-function", @$,
1584 /**/ { $$ = SCM_EOL; }
1585 | '=' simple_string {
1592 | repeated_music { $$ = $1; }
1593 | re_rhythmed_music { $$ = $1; }
1594 | complex_music_prefix music
1596 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1600 complex_music_prefix:
1601 CONTEXT simple_string optional_id optional_context_mod {
1602 Context_mod *ctxmod = unsmob_context_mod ($4);
1605 mods = ctxmod->get_mods ();
1606 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1608 | NEWCONTEXT simple_string optional_id optional_context_mod {
1609 Context_mod *ctxmod = unsmob_context_mod ($4);
1612 mods = ctxmod->get_mods ();
1613 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1618 mode_changing_head grouped_music_list {
1619 if ($1 == ly_symbol2scm ("chords"))
1621 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1627 PARSER->lexer_->pop_state ();
1629 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1630 Context_mod *ctxmod = unsmob_context_mod ($2);
1633 mods = ctxmod->get_mods ();
1634 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1635 if ($1 == ly_symbol2scm ("ChordNames"))
1637 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1639 PARSER->lexer_->pop_state ();
1645 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1646 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1648 $$ = ly_symbol2scm ("notes");
1652 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1653 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1655 $$ = ly_symbol2scm ("drums");
1658 PARSER->lexer_->push_figuredbass_state ();
1660 $$ = ly_symbol2scm ("figures");
1663 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1664 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1665 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1666 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1667 $$ = ly_symbol2scm ("chords");
1671 { PARSER->lexer_->push_lyric_state ();
1672 $$ = ly_symbol2scm ("lyrics");
1676 mode_changing_head_with_context:
1678 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1679 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1681 $$ = ly_symbol2scm ("DrumStaff");
1684 PARSER->lexer_->push_figuredbass_state ();
1686 $$ = ly_symbol2scm ("FiguredBass");
1689 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1690 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1691 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1692 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1693 $$ = ly_symbol2scm ("ChordNames");
1696 { PARSER->lexer_->push_lyric_state ();
1697 $$ = ly_symbol2scm ("Lyrics");
1702 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1705 /* Can also use music at the expensive of two S/Rs similar to
1706 \repeat \alternative */
1707 PARSER->lexer_->pop_state ();
1709 $$ = scm_cons ($3, SCM_EOL);
1711 | new_lyrics ADDLYRICS {
1712 PARSER->lexer_->push_lyric_state ();
1714 PARSER->lexer_->pop_state ();
1715 $$ = scm_cons ($4, $1);
1720 composite_music new_lyrics {
1721 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1723 | LYRICSTO simple_string {
1724 PARSER->lexer_->push_lyric_state ();
1726 PARSER->lexer_->pop_state ();
1727 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1732 CHANGE STRING '=' STRING {
1733 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1738 property_path_revved:
1739 embedded_scm_closed {
1740 $$ = scm_cons ($1, SCM_EOL);
1742 | property_path_revved embedded_scm_closed {
1743 $$ = scm_cons ($2, $1);
1748 property_path_revved {
1749 $$ = scm_reverse_x ($1, SCM_EOL);
1755 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1756 scm_string_to_symbol ($1), $3);
1758 | UNSET simple_string {
1759 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1760 scm_string_to_symbol ($2));
1762 | OVERRIDE simple_string property_path '=' scalar {
1763 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1764 scm_string_to_symbol ($2), $5),
1767 | REVERT simple_string embedded_scm {
1768 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1769 scm_string_to_symbol ($2), $3);
1774 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1775 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1777 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1778 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1779 | DENIES { $$ = ly_symbol2scm ("denies"); }
1781 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1782 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1783 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1784 | NAME { $$ = ly_symbol2scm ("context-name"); }
1788 property_operation { $$ = $1; }
1789 | context_def_mod STRING {
1790 $$ = scm_list_2 ($1, $2);
1792 | context_def_mod embedded_scm {
1793 if (ly_symbol2scm ("consists") != $1)
1796 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1800 $$ = scm_list_2 ($1, $2);
1807 if (!is_regular_identifier ($1))
1809 @$.error (_("Grob name should be alphanumeric"));
1812 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1813 scm_string_to_symbol ($1));
1815 | simple_string '.' simple_string {
1816 $$ = scm_list_2 (scm_string_to_symbol ($1),
1817 scm_string_to_symbol ($3));
1821 simple_music_property_def:
1822 OVERRIDE context_prop_spec property_path '=' scalar {
1823 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1824 ly_symbol2scm ("OverrideProperty"),
1829 | REVERT context_prop_spec embedded_scm {
1830 $$ = scm_list_4 (scm_car ($2),
1831 ly_symbol2scm ("RevertProperty"),
1835 | SET context_prop_spec '=' scalar {
1836 $$ = scm_list_4 (scm_car ($2),
1837 ly_symbol2scm ("PropertySet"),
1841 | UNSET context_prop_spec {
1842 $$ = scm_list_3 (scm_car ($2),
1843 ly_symbol2scm ("PropertyUnset"),
1849 simple_music_property_def {
1850 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (PARSER->self_scm (), make_input (@$), $1));
1858 | STRING_IDENTIFIER {
1861 | string '+' string {
1862 $$ = scm_string_append (scm_list_2 ($1, $3));
1866 simple_string: STRING {
1872 | STRING_IDENTIFIER {
1884 embedded_scm_arg_closed
1891 /* TODO: Create a special case that avoids the creation of
1892 EventChords around simple_elements that have no post_events?
1894 simple_chord_elements post_events {
1895 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1898 /* why is this giving wrong start location? -ns
1900 i.set_location (@1, @2);
1901 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1903 | CHORD_REPETITION optional_notemode_duration post_events {
1905 i.set_location (@1, @3);
1906 $$ = MAKE_SYNTAX ("repetition-chord", i,
1907 PARSER->lexer_->chord_repetition_.last_chord_,
1908 PARSER->lexer_->chord_repetition_.repetition_function_,
1909 $2, scm_reverse_x ($3, SCM_EOL));
1911 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1913 i.set_location (@1, @3);
1914 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1915 scm_reverse_x ($3, SCM_EOL));
1918 /* note chord elements are memorized into
1919 PARSER->lexer_->chord_repetition_ so that the chord repetition
1920 mechanism copy them when a chord repetition symbol is found
1922 | note_chord_element {
1923 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
1929 chord_body optional_notemode_duration post_events
1931 Music *m = unsmob_music ($1);
1932 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1933 SCM es = m->get_property ("elements");
1934 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1936 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1937 unsmob_music (scm_car (s))->set_property ("duration", dur);
1938 es = ly_append2 (es, postevs);
1940 m-> set_property ("elements", es);
1942 $$ = m->self_scm ();
1947 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1949 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1953 chord_body_elements:
1954 /* empty */ { $$ = SCM_EOL; }
1955 | chord_body_elements chord_body_element {
1956 $$ = scm_cons ($2, $1);
1961 pitch exclamations questions octave_check post_events
1968 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1969 n->set_property ("pitch", $1);
1971 n->set_property ("cautionary", SCM_BOOL_T);
1972 if (ex % 2 || q % 2)
1973 n->set_property ("force-accidental", SCM_BOOL_T);
1975 if (scm_is_pair (post)) {
1976 SCM arts = scm_reverse_x (post, SCM_EOL);
1977 n->set_property ("articulations", arts);
1979 if (scm_is_number (check))
1981 int q = scm_to_int (check);
1982 n->set_property ("absolute-octave", scm_from_int (q-1));
1985 $$ = n->unprotect ();
1987 | DRUM_PITCH post_events {
1988 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1989 n->set_property ("drum-type", $1);
1991 if (scm_is_pair ($2)) {
1992 SCM arts = scm_reverse_x ($2, SCM_EOL);
1993 n->set_property ("articulations", arts);
1995 $$ = n->unprotect ();
1997 | music_function_chord_body
2000 /* We can't accept a music argument, not even a closed one,
2001 * immediately before chord_body_elements, otherwise a function \fun
2002 * with a signature of two music arguments can't be sorted out
2003 * properly in a construct like
2004 * <\fun { c } \fun { c } c>
2005 * The second call could be interpreted either as a chord constituent
2006 * or a music expression.
2009 music_function_chord_body_arglist:
2010 function_arglist_bare
2011 | EXPECT_SCM music_function_chord_body_arglist embedded_scm_chord_body
2013 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED,
2018 embedded_scm_chord_body:
2019 embedded_scm_bare_arg
2020 | SCM_FUNCTION music_function_chord_body_arglist {
2021 $$ = MAKE_SYNTAX ("music-function", @$,
2027 | chord_body_element
2030 music_function_chord_body:
2031 MUSIC_FUNCTION music_function_chord_body_arglist {
2032 $$ = MAKE_SYNTAX ("music-function", @$,
2037 // Event functions may only take closed arglists, otherwise it would
2038 // not be clear whether a following postevent should be associated
2039 // with the last argument of the event function or with the expression
2040 // for which the function call acts itself as event.
2042 music_function_event:
2043 MUSIC_FUNCTION function_arglist_closed {
2044 $$ = MAKE_SYNTAX ("music-function", @$,
2049 event_function_event:
2050 EVENT_FUNCTION function_arglist_closed {
2051 $$ = MAKE_SYNTAX ("music-function", @$,
2061 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2062 m->set_property ("span-direction", scm_from_int (START));
2063 $$ = m->unprotect();
2066 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2067 m->set_property ("span-direction", scm_from_int (STOP));
2068 $$ = m->unprotect ();
2071 $$ = MAKE_SYNTAX ("voice-separator", @$);
2074 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
2076 Music *m = unsmob_music (pipe);
2081 $$ = m->unprotect ();
2084 $$ = MAKE_SYNTAX ("bar-check", @$);
2091 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2103 | post_events post_event {
2104 unsmob_music ($2)->set_spot (@2);
2105 $$ = scm_cons ($2, $$);
2109 post_event_nofinger:
2110 direction_less_event {
2113 | script_dir music_function_event {
2117 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2121 if (!PARSER->lexer_->is_lyric_state ())
2122 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2123 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2126 if (!PARSER->lexer_->is_lyric_state ())
2127 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2128 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2130 | script_dir direction_reqd_event {
2133 Music *m = unsmob_music ($2);
2134 m->set_property ("direction", scm_from_int ($1));
2138 | script_dir direction_less_event {
2141 Music *m = unsmob_music ($2);
2142 m->set_property ("direction", scm_from_int ($1));
2146 | string_number_event
2151 | script_dir fingering {
2154 Music *m = unsmob_music ($2);
2155 m->set_property ("direction", scm_from_int ($1));
2161 string_number_event:
2163 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2164 s->set_property ("string-number", scm_from_int ($1));
2165 $$ = s->unprotect ();
2169 direction_less_char:
2171 $$ = ly_symbol2scm ("bracketOpenSymbol");
2174 $$ = ly_symbol2scm ("bracketCloseSymbol");
2177 $$ = ly_symbol2scm ("tildeSymbol");
2180 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2183 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2186 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2189 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2192 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2195 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2198 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2202 direction_less_event:
2203 direction_less_char {
2204 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
2206 if (unsmob_music (predefd))
2208 m = unsmob_music (predefd)->clone ();
2213 m = MY_MAKE_MUSIC ("Music", @$);
2215 $$ = m->unprotect ();
2217 | EVENT_IDENTIFIER {
2221 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2222 a->set_property ("tremolo-type", scm_from_int ($1));
2223 $$ = a->unprotect ();
2225 | event_function_event
2228 direction_reqd_event:
2232 | script_abbreviation {
2233 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2234 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2235 if (scm_is_string (s))
2236 a->set_property ("articulation-type", s);
2237 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
2238 $$ = a->unprotect ();
2243 /**/ { $$ = SCM_EOL; }
2244 | '=' { $$ = scm_from_int (0); }
2245 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2246 | '=' sup_quotes { $$ = scm_from_int ($2); }
2271 | NOTENAME_PITCH sup_quotes {
2272 Pitch p = *unsmob_pitch ($1);
2273 p = p.transposed (Pitch ($2,0,0));
2274 $$ = p.smobbed_copy ();
2276 | NOTENAME_PITCH sub_quotes {
2277 Pitch p =* unsmob_pitch ($1);
2278 p = p.transposed (Pitch (-$2,0,0));
2279 $$ = p.smobbed_copy ();
2291 | TONICNAME_PITCH sup_quotes {
2292 Pitch p = *unsmob_pitch ($1);
2293 p = p.transposed (Pitch ($2,0,0));
2294 $$ = p.smobbed_copy ();
2296 | TONICNAME_PITCH sub_quotes {
2297 Pitch p = *unsmob_pitch ($1);
2299 p = p.transposed (Pitch (-$2,0,0));
2300 $$ = p.smobbed_copy ();
2311 pitch_also_in_chords:
2318 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2319 t->set_property ("text", $1);
2320 $$ = t->unprotect ();
2323 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2324 t->set_property ("text",
2325 make_simple_markup ($1));
2326 $$ = t->unprotect ();
2332 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2333 t->set_property ("digit", $1);
2334 $$ = t->unprotect ();
2338 script_abbreviation:
2340 $$ = scm_from_locale_string ("Hat");
2343 $$ = scm_from_locale_string ("Plus");
2346 $$ = scm_from_locale_string ("Dash");
2349 $$ = scm_from_locale_string ("Bar");
2352 $$ = scm_from_locale_string ("Larger");
2355 $$ = scm_from_locale_string ("Dot");
2358 $$ = scm_from_locale_string ("Underscore");
2365 | '-' { $$ = CENTER; }
2369 multiplied_duration {
2374 optional_notemode_duration:
2376 Duration dd = PARSER->default_duration_;
2377 $$ = dd.smobbed_copy ();
2379 | multiplied_duration {
2381 PARSER->default_duration_ = *unsmob_duration ($$);
2386 bare_unsigned dots {
2388 if (!is_duration ($1))
2389 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
2393 $$ = Duration (len, $2).smobbed_copy ();
2395 | DURATION_IDENTIFIER dots {
2396 Duration *d = unsmob_duration ($1);
2397 Duration k (d->duration_log (), d->dot_count () + $2);
2398 k = k.compressed (d->factor ());
2404 multiplied_duration:
2408 | multiplied_duration '*' bare_unsigned {
2409 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2411 | multiplied_duration '*' FRACTION {
2412 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2414 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2419 FRACTION { $$ = $1; }
2420 | UNSIGNED '/' UNSIGNED {
2421 $$ = scm_cons ($1, $3);
2438 | ':' bare_unsigned {
2439 if (!is_duration ($2))
2440 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2446 UNSIGNED { $$ = $1; }
2447 | STRING { $$ = $1; }
2448 | full_markup { $$ = $1; }
2451 figured_bass_alteration:
2452 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2453 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2454 | '!' { $$ = scm_from_int (0); }
2459 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2460 $$ = bfr->unprotect ();
2463 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2464 $$ = bfr->self_scm ();
2466 if (scm_is_number ($1))
2467 bfr->set_property ("figure", $1);
2468 else if (Text_interface::is_markup ($1))
2469 bfr->set_property ("text", $1);
2475 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2477 | bass_figure figured_bass_alteration {
2478 Music *m = unsmob_music ($1);
2479 if (scm_to_double ($2)) {
2480 SCM salter = m->get_property ("alteration");
2481 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2482 m->set_property ("alteration",
2483 scm_sum (alter, $2));
2485 m->set_property ("alteration", scm_from_int (0));
2488 | bass_figure figured_bass_modification {
2489 Music *m = unsmob_music ($1);
2490 if ($2 == ly_symbol2scm ("plus"))
2492 m->set_property ("augmented", SCM_BOOL_T);
2494 else if ($2 == ly_symbol2scm ("slash"))
2496 m->set_property ("diminished", SCM_BOOL_T);
2498 else if ($2 == ly_symbol2scm ("exclamation"))
2500 m->set_property ("no-continuation", SCM_BOOL_T);
2502 else if ($2 == ly_symbol2scm ("backslash"))
2504 m->set_property ("augmented-slash", SCM_BOOL_T);
2510 figured_bass_modification:
2512 $$ = ly_symbol2scm ("plus");
2515 $$ = ly_symbol2scm ("exclamation");
2518 $$ = ly_symbol2scm ("slash");
2521 $$ = ly_symbol2scm ("backslash");
2531 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2539 | figure_list br_bass_figure {
2540 $$ = scm_cons ($2, $1);
2545 FIGURE_OPEN figure_list FIGURE_CLOSE {
2546 $$ = scm_reverse_x ($2, SCM_EOL);
2557 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2558 if (!PARSER->lexer_->is_note_state ())
2559 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2563 n = MY_MAKE_MUSIC ("RestEvent", @$);
2565 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2567 n->set_property ("pitch", $1);
2568 n->set_property ("duration", $5);
2570 if (scm_is_number ($4))
2572 int q = scm_to_int ($4);
2573 n->set_property ("absolute-octave", scm_from_int (q-1));
2577 n->set_property ("cautionary", SCM_BOOL_T);
2578 if ($2 % 2 || $3 % 2)
2579 n->set_property ("force-accidental", SCM_BOOL_T);
2581 $$ = n->unprotect ();
2583 | DRUM_PITCH optional_notemode_duration {
2584 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2585 n->set_property ("duration", $2);
2586 n->set_property ("drum-type", $1);
2588 $$ = n->unprotect ();
2590 | RESTNAME optional_notemode_duration {
2592 if (ly_scm2string ($1) == "s") {
2594 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2597 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2600 ev->set_property ("duration", $2);
2601 $$ = ev->unprotect ();
2605 simple_chord_elements:
2607 $$ = scm_list_1 ($1);
2610 if (!PARSER->lexer_->is_chord_state ())
2611 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2614 | figure_spec optional_notemode_duration {
2615 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2617 unsmob_music (scm_car (s))->set_property ("duration", $2);
2635 | lyric_element multiplied_duration post_events {
2636 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2637 $$ = MAKE_SYNTAX ("event-chord", @$,
2638 scm_cons (lyric_event,
2639 scm_reverse_x ($3, SCM_EOL)));
2641 | lyric_element post_event post_events {
2643 MAKE_SYNTAX ("lyric-event", @$, $1,
2644 PARSER->default_duration_.smobbed_copy ());
2645 $$ = MAKE_SYNTAX ("event-chord", @$,
2646 scm_cons2 (lyric_event, $2,
2647 scm_reverse_x ($3, SCM_EOL)));
2650 | LYRIC_ELEMENT optional_notemode_duration post_events {
2651 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2652 $$ = MAKE_SYNTAX ("event-chord", @$,
2653 scm_cons (lyric_event,
2654 scm_reverse_x ($3, SCM_EOL)));
2659 lyric_element_music:
2660 lyric_element optional_notemode_duration post_events {
2661 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2662 $$ = MAKE_SYNTAX ("event-chord", @$,
2663 scm_cons (lyric_event,
2664 scm_reverse_x ($3, SCM_EOL)));
2669 steno_tonic_pitch optional_notemode_duration {
2670 $$ = make_chord_elements ($1, $2, SCM_EOL);
2672 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2673 SCM its = scm_reverse_x ($4, SCM_EOL);
2674 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2682 | chord_items chord_item {
2683 $$ = scm_cons ($2, $$);
2689 $$ = ly_symbol2scm ("chord-colon");
2692 $$ = ly_symbol2scm ("chord-caret");
2694 | CHORD_SLASH steno_tonic_pitch {
2695 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2697 | CHORD_BASS steno_tonic_pitch {
2698 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2707 $$ = scm_reverse_x ($1, SCM_EOL);
2715 step_number { $$ = scm_cons ($1, SCM_EOL); }
2716 | step_numbers '.' step_number {
2717 $$ = scm_cons ($3, $$);
2723 $$ = make_chord_step ($1, 0);
2725 | bare_unsigned '+' {
2726 $$ = make_chord_step ($1, SHARP_ALTERATION);
2728 | bare_unsigned CHORD_MINUS {
2729 $$ = make_chord_step ($1, FLAT_ALTERATION);
2735 $$ = scm_from_int ($1);
2737 | bare_unsigned '~' bare_unsigned {
2738 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2745 TODO: should deprecate in favor of Scheme?
2749 number_expression '+' number_term {
2750 $$ = scm_sum ($1, $3);
2752 | number_expression '-' number_term {
2753 $$ = scm_difference ($1, $3);
2762 | number_factor '*' number_factor {
2763 $$ = scm_product ($1, $3);
2765 | number_factor '/' number_factor {
2766 $$ = scm_divide ($1, $3);
2771 '-' number_factor { /* %prec UNARY_MINUS */
2772 $$ = scm_difference ($2, SCM_UNDEFINED);
2780 | UNSIGNED NUMBER_IDENTIFIER {
2781 $$ = scm_product ($1, $2)
2783 | REAL NUMBER_IDENTIFIER {
2784 $$ = scm_product ($1, $2)
2796 $$ = scm_to_int ($1);
2807 | exclamations '!' { $$ ++; }
2812 | questions '?' { $$ ++; }
2816 This should be done more dynamically if possible.
2820 LYRIC_MARKUP_IDENTIFIER {
2824 { PARSER->lexer_->push_markup_state (); }
2827 PARSER->lexer_->pop_state ();
2832 MARKUPLIST_IDENTIFIER {
2836 { PARSER->lexer_->push_markup_state (); }
2839 PARSER->lexer_->pop_state ();
2848 { PARSER->lexer_->push_markup_state (); }
2851 PARSER->lexer_->pop_state ();
2857 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2859 | markup_head_1_list simple_markup {
2860 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2868 MARKUPLIST_IDENTIFIER {
2871 | markup_composed_list {
2874 | markup_braced_list {
2877 | markup_command_list {
2878 $$ = scm_list_1 ($1);
2882 markup_composed_list:
2883 markup_head_1_list markup_braced_list {
2884 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2890 '{' markup_braced_list_body '}' {
2891 $$ = scm_reverse_x ($2, SCM_EOL);
2895 markup_braced_list_body:
2896 /* empty */ { $$ = SCM_EOL; }
2897 | markup_braced_list_body markup {
2898 $$ = scm_cons ($2, $1);
2900 | markup_braced_list_body markup_list {
2901 $$ = scm_reverse_x ($2, $1);
2905 markup_command_list:
2906 MARKUP_LIST_FUNCTION markup_command_list_arguments {
2907 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
2911 markup_command_basic_arguments:
2912 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
2913 $$ = scm_cons ($3, $2);
2915 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
2916 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED, $3, $2, $1);
2918 | EXPECT_NO_MORE_ARGS {
2923 markup_command_list_arguments:
2924 markup_command_basic_arguments { $$ = $1; }
2925 | EXPECT_MARKUP markup_command_list_arguments markup {
2926 $$ = scm_cons ($3, $2);
2931 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
2932 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
2937 markup_head_1_item {
2938 $$ = scm_list_1 ($1);
2940 | markup_head_1_list markup_head_1_item {
2941 $$ = scm_cons ($2, $1);
2947 $$ = make_simple_markup ($1);
2949 | MARKUP_IDENTIFIER {
2952 | LYRIC_MARKUP_IDENTIFIER {
2955 | STRING_IDENTIFIER {
2959 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2960 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2961 } '{' score_body '}' {
2963 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2965 PARSER->lexer_->pop_state ();
2967 | MARKUP_FUNCTION markup_command_basic_arguments {
2968 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
2973 markup_head_1_list simple_markup {
2974 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2975 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2985 Lily_parser::set_yydebug (bool x)
2991 Lily_parser::do_yyparse ()
2993 yyparse ((void*)this);
3002 It is a little strange to have this function in this file, but
3003 otherwise, we have to import music classes into the lexer.
3007 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3009 if (scm_is_string (sid)) {
3011 return STRING_IDENTIFIER;
3012 } else if (unsmob_book (sid)) {
3013 Book *book = unsmob_book (sid)->clone ();
3014 *destination = book->self_scm ();
3017 return BOOK_IDENTIFIER;
3018 } else if (scm_is_number (sid)) {
3020 return NUMBER_IDENTIFIER;
3021 } else if (unsmob_context_def (sid)) {
3022 Context_def *def= unsmob_context_def (sid)->clone ();
3024 *destination = def->self_scm ();
3027 return CONTEXT_DEF_IDENTIFIER;
3028 } else if (unsmob_context_mod (sid)) {
3029 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3031 return CONTEXT_MOD_IDENTIFIER;
3032 } else if (unsmob_score (sid)) {
3033 Score *score = new Score (*unsmob_score (sid));
3034 *destination = score->self_scm ();
3036 score->unprotect ();
3037 return SCORE_IDENTIFIER;
3038 } else if (Music *mus = unsmob_music (sid)) {
3039 mus = mus->clone ();
3040 *destination = mus->self_scm ();
3041 unsmob_music (*destination)->
3042 set_property ("origin", make_input (last_input_));
3044 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
3048 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3049 } else if (unsmob_pitch (sid)) {
3050 *destination = unsmob_pitch (sid)->smobbed_copy ();
3051 return PITCH_IDENTIFIER;
3052 } else if (unsmob_duration (sid)) {
3053 *destination = unsmob_duration (sid)->smobbed_copy ();
3054 return DURATION_IDENTIFIER;
3055 } else if (unsmob_output_def (sid)) {
3056 Output_def *p = unsmob_output_def (sid);
3059 *destination = p->self_scm ();
3061 return OUTPUT_DEF_IDENTIFIER;
3062 } else if (Text_interface::is_markup (sid)) {
3064 if (is_lyric_state ())
3065 return LYRIC_MARKUP_IDENTIFIER;
3066 return MARKUP_IDENTIFIER;
3067 } else if (Text_interface::is_markup_list (sid)) {
3069 return MARKUPLIST_IDENTIFIER;
3076 get_next_unique_context_id ()
3078 return scm_from_locale_string ("$uniqueContextId");
3083 get_next_unique_lyrics_context_id ()
3085 static int new_context_count;
3087 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3088 return scm_from_locale_string (s);
3091 SCM check_scheme_arg (Lily_parser *my_lily_parser, Input loc, SCM fallback,
3092 SCM arg, SCM args, SCM pred)
3094 SCM unwrap = SCM_UNDEFINED;
3095 if (scm_is_true (scm_call_1 (pred, arg)))
3096 return scm_cons (arg, args);
3097 unwrap = try_unpack_lyrics (pred, arg);
3098 if (!SCM_UNBNDP (unwrap))
3099 return scm_cons (unwrap, args);
3100 if (SCM_UNBNDP (fallback)) {
3101 args = scm_cons (SCM_BOOL_F, args);
3102 fallback = SCM_BOOL_F;
3104 args = scm_cons (loc_on_music (loc, fallback), args);
3105 fallback = SCM_CDR (scm_last_pair (args));
3107 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3108 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3109 scm_set_cdr_x (scm_last_pair (args), fallback);
3113 SCM loc_on_music (Input loc, SCM arg)
3115 if (Music *m = unsmob_music (arg))
3119 return m->unprotect ();
3125 is_regular_identifier (SCM id)
3127 string str = ly_scm2string (id);
3128 char const *s = str.c_str ();
3137 v = v && isalnum (*s);
3144 make_music_with_input (SCM name, Input where)
3146 Music *m = make_music_by_name (name);
3147 m->set_spot (where);
3152 get_first_context_id (SCM type, Music *m)
3154 SCM id = m->get_property ("context-id");
3155 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
3156 && scm_is_string (m->get_property ("context-id"))
3157 && scm_c_string_length (id) > 0)
3165 make_simple_markup (SCM a)
3173 return t && t == 1 << intlog2 (t);
3177 set_music_properties (Music *p, SCM a)
3179 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3180 p->set_property (scm_caar (k), scm_cdar (k));
3185 make_chord_step (int step, Rational alter)
3188 alter += FLAT_ALTERATION;
3192 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3193 return m.smobbed_copy ();
3198 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
3200 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3201 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
3205 try_unpack_lyrics (SCM pred, SCM arg)
3207 if (Music *m = unsmob_music (arg))
3208 if (m->is_mus_type ("lyric-event")) {
3209 SCM text = m->get_property ("text");
3210 if (scm_is_true (scm_call_1 (pred, text)))
3213 return SCM_UNDEFINED;
3216 /* Todo: actually also use apply iso. call too ... */
3218 ly_input_procedure_p (SCM x)
3220 return ly_is_procedure (x)
3221 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
3225 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
3227 Lily_parser *pars = (Lily_parser*) v;
3228 Lily_lexer *lex = pars->lexer_;
3230 lex->lexval_ = (void*) s;
3232 lex->prepare_for_next_token ();
3233 return lex->yylex ();