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
27 #define yyerror Lily_parser::parser_error
29 /* We use custom location type: Input objects */
31 #define YYLLOC_DEFAULT(Current,Rhs,N) \
32 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
37 %parse-param {Lily_parser *parser}
38 %lex-param {Lily_parser *parser}
40 /* We use SCMs to do strings, because it saves us the trouble of
41 deleting them. Let's hope that a stack overflow doesnt trigger a move
42 of the parse stack onto the heap. */
48 /* The above precedences tackle the shift/reduce problem
51 \repeat .. \alternative
53 \repeat { \repeat .. \alternative }
57 \repeat { \repeat } \alternative
63 /* ADDLYRICS needs to have lower precedence than argument scanning,
64 * or we won't be able to tell music apart from closed_music without
65 * lookahead in the context of function calls.
70 /* \default is only applied after exhausting function arguments */
72 %nonassoc FUNCTION_ARGLIST
74 /* expressions with units are permitted into argument lists */
76 %right PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
77 UNSIGNED REAL DURATION_IDENTIFIER ':'
79 /* The above are the symbols that can start optional function arguments
80 that are recognized in the grammar rather than by predicate
83 %nonassoc NUMBER_IDENTIFIER '/'
85 /* Number-unit expressions, where permitted, are concatenated into
86 * function arguments, just like fractions and tremoli. Tremoli must
87 * not have higher precedence than UNSIGNED, or Lilypond will not
88 * join ':' with a following optional number.
101 %{ // -*-Fundamental-*-
106 * The rules for who is protecting what are very shady. Uniformise
109 * There are too many lexical modes?
120 #include "context-def.hh"
121 #include "context-mod.hh"
122 #include "dimensions.hh"
123 #include "file-path.hh"
125 #include "international.hh"
126 #include "lily-guile.hh"
127 #include "lily-lexer.hh"
128 #include "lily-parser.hh"
132 #include "output-def.hh"
133 #include "paper-book.hh"
134 #include "scm-hash.hh"
136 #include "text-interface.hh"
140 Lily_parser::parser_error (Input const *i, Lily_parser *parser, string s)
142 parser->parser_error (*i, s);
145 #define MYBACKUP(Token, Value, Location) \
147 if (yychar == YYEMPTY) \
150 PARSER->lexer_->push_extra_token (Token, Value); \
151 PARSER->lexer_->push_extra_token (BACKUP); \
153 PARSER->parser_error \
154 (Location, _("Too much lookahead")); \
159 #define MYREPARSE(Location, Pred, Token, Value) \
161 if (yychar == YYEMPTY) \
163 PARSER->lexer_->push_extra_token (Token, Value); \
164 PARSER->lexer_->push_extra_token (REPARSE, \
167 PARSER->parser_error \
168 (Location, _("Too much lookahead")); \
177 Output_def *outputdef;
186 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
189 - Don't use lily module, create a new module instead.
190 - delay application of the function
192 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
193 scm_apply_0 (proc, args)
194 /* Syntactic Sugar. */
195 #define MAKE_SYNTAX(name, location, ...) \
196 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location) , ##__VA_ARGS__, SCM_UNDEFINED));
197 #define START_MAKE_SYNTAX(name, ...) \
198 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
199 #define FINISH_MAKE_SYNTAX(start, location, ...) \
200 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)))))
202 SCM get_next_unique_context_id ();
203 SCM get_next_unique_lyrics_context_id ();
210 #define _(x) gettext (x)
214 static Music *make_music_with_input (SCM name, Input where);
215 SCM check_scheme_arg (Lily_parser *parser, Input loc,
216 SCM arg, SCM args, SCM pred);
217 SCM loc_on_music (Input loc, SCM arg);
218 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
219 SCM make_chord_step (int step, Rational alter);
220 SCM make_simple_markup (SCM a);
221 bool is_duration (int t);
222 bool is_regular_identifier (SCM id);
223 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
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 HEADER "\\header"
256 %token INVALID "\\version-error"
257 %token LAYOUT "\\layout"
258 %token LYRICMODE "\\lyricmode"
259 %token LYRICS "\\lyrics"
260 %token LYRICSTO "\\lyricsto"
261 %token MARKUP "\\markup"
262 %token MARKUPLIST "\\markuplist"
265 %token NOTEMODE "\\notemode"
266 %token OVERRIDE "\\override"
267 %token PAPER "\\paper"
268 %token REMOVE "\\remove"
269 %token REPEAT "\\repeat"
271 %token REVERT "\\revert"
272 %token SCORE "\\score"
273 %token SEQUENTIAL "\\sequential"
275 %token SIMULTANEOUS "\\simultaneous"
276 %token TEMPO "\\tempo"
278 %token UNSET "\\unset"
281 /* Keyword token exceptions. */
282 %token NEWCONTEXT "\\new"
285 /* Other string tokens. */
287 %token CHORD_BASS "/+"
288 %token CHORD_CARET "^"
289 %token CHORD_COLON ":"
290 %token CHORD_MINUS "-"
291 %token CHORD_SLASH "/"
292 %token ANGLE_OPEN "<"
293 %token ANGLE_CLOSE ">"
294 %token DOUBLE_ANGLE_OPEN "<<"
295 %token DOUBLE_ANGLE_CLOSE ">>"
296 %token E_BACKSLASH "\\"
297 %token E_ANGLE_CLOSE "\\>"
298 %token E_CHAR "\\C[haracter]"
300 %token E_EXCLAMATION "\\!"
301 %token E_BRACKET_OPEN "\\["
303 %token E_BRACKET_CLOSE "\\]"
304 %token E_ANGLE_OPEN "\\<"
310 If we give names, Bison complains.
312 %token FIGURE_CLOSE /* "\\>" */
313 %token FIGURE_OPEN /* "\\<" */
314 %token FIGURE_SPACE "_"
317 %token CHORDMODIFIERS
319 %token MULTI_MEASURE_REST
322 %token <i> E_UNSIGNED
323 %token <scm> UNSIGNED
325 /* Artificial tokens, for more generic function syntax */
326 %token <i> EXPECT_MARKUP "markup?"
327 %token <i> EXPECT_PITCH "ly:pitch?"
328 %token <i> EXPECT_DURATION "ly:duration?"
329 %token <scm> EXPECT_SCM "scheme?"
330 %token <scm> BACKUP "(backed-up?)"
331 %token <scm> REPARSE "(reparsed?)"
332 %token <i> EXPECT_MARKUP_LIST "markup-list?"
333 %token <scm> EXPECT_OPTIONAL "optional?"
334 /* After the last argument. */
335 %token <i> EXPECT_NO_MORE_ARGS;
337 /* An artificial token for parsing embedded Lilypond */
338 %token <i> EMBEDDED_LILY "#{"
340 %token <scm> BOOK_IDENTIFIER
341 %token <scm> CHORDMODIFIER_PITCH
342 %token <scm> CHORD_MODIFIER
343 %token <scm> CHORD_REPETITION
344 %token <scm> CONTEXT_DEF_IDENTIFIER
345 %token <scm> CONTEXT_MOD_IDENTIFIER
346 %token <scm> DRUM_PITCH
347 %token <scm> PITCH_IDENTIFIER
348 %token <scm> DURATION_IDENTIFIER
349 %token <scm> EVENT_IDENTIFIER
350 %token <scm> EVENT_FUNCTION
351 %token <scm> FRACTION
352 %token <scm> LYRICS_STRING
353 %token <scm> LYRIC_ELEMENT
354 %token <scm> LYRIC_MARKUP_IDENTIFIER
355 %token <scm> MARKUP_FUNCTION
356 %token <scm> MARKUP_LIST_FUNCTION
357 %token <scm> MARKUP_IDENTIFIER
358 %token <scm> MARKUPLIST_IDENTIFIER
359 %token <scm> MUSIC_FUNCTION
360 %token <scm> MUSIC_IDENTIFIER
361 %token <scm> NOTENAME_PITCH
362 %token <scm> NUMBER_IDENTIFIER
363 %token <scm> OUTPUT_DEF_IDENTIFIER
365 %token <scm> RESTNAME
366 %token <scm> SCM_FUNCTION
367 %token <scm> SCM_IDENTIFIER
368 %token <scm> SCM_TOKEN
369 %token <scm> SCORE_IDENTIFIER
371 %token <scm> STRING_IDENTIFIER
372 %token <scm> TONICNAME_PITCH
375 %type <book> book_block
376 %type <book> book_body
377 %type <book> bookpart_block
378 %type <book> bookpart_body
380 %type <i> bare_unsigned
381 %type <scm> figured_bass_alteration
383 %type <i> exclamations
384 %type <i> optional_rest
389 %type <i> tremolo_type
392 %type <scm> composite_music
393 %type <scm> grouped_music_list
394 %type <scm> braced_music_list
395 %type <scm> closed_music
397 %type <scm> music_bare
398 %type <scm> music_arg
399 %type <scm> complex_music
400 %type <scm> complex_music_prefix
401 %type <scm> mode_changed_music
402 %type <scm> repeated_music
403 %type <scm> sequential_music
404 %type <scm> simple_music
405 %type <scm> simultaneous_music
406 %type <scm> chord_body
407 %type <scm> chord_body_element
408 %type <scm> command_element
409 %type <scm> command_event
410 %type <scm> context_modification
411 %type <scm> context_change
412 %type <scm> direction_less_event
413 %type <scm> direction_reqd_event
414 %type <scm> embedded_lilypond
415 %type <scm> event_chord
416 %type <scm> fingering
417 %type <scm> gen_text_def
418 %type <scm> music_property_def
419 %type <scm> note_chord_element
420 %type <scm> post_event
421 %type <scm> post_event_nofinger
422 %type <scm> re_rhythmed_music
423 %type <scm> simple_element
424 %type <scm> simple_music_property_def
425 %type <scm> start_symbol
426 %type <scm> string_number_event
427 %type <scm> tempo_event
429 %type <outputdef> output_def_body
430 %type <outputdef> output_def_head
431 %type <outputdef> output_def_head_with_mode_switch
432 %type <outputdef> output_def
433 %type <outputdef> paper_block
435 %type <scm> music_function_call
436 %type <scm> music_list
437 %type <scm> assignment_id
438 %type <scm> bare_number
439 %type <scm> bare_number_closed
440 %type <scm> unsigned_number
441 %type <scm> bass_figure
442 %type <scm> figured_bass_modification
443 %type <scm> br_bass_figure
444 %type <scm> bass_number
445 %type <scm> chord_body_elements
446 %type <scm> chord_item
447 %type <scm> chord_items
448 %type <scm> chord_separator
449 %type <scm> context_def_mod
450 %type <scm> context_def_spec_block
451 %type <scm> context_def_spec_body
452 %type <scm> context_mod
453 %type <scm> context_mod_list
454 %type <scm> context_prop_spec
455 %type <scm> direction_less_char
456 %type <scm> duration_length
457 %type <scm> embedded_scm
458 %type <scm> embedded_scm_arg
459 %type <scm> embedded_scm_arg_closed
460 %type <scm> embedded_scm_bare
461 %type <scm> embedded_scm_bare_arg
462 %type <scm> embedded_scm_closed
463 %type <scm> embedded_scm_chord_body
464 %type <scm> event_function_event
465 %type <scm> figure_list
466 %type <scm> figure_spec
468 %type <scm> full_markup
469 %type <scm> full_markup_list
470 %type <scm> function_arglist
471 %type <scm> function_arglist_optional
472 %type <scm> function_arglist_backup
473 %type <scm> function_arglist_nonbackup
474 %type <scm> function_arglist_skip
475 %type <scm> function_arglist_bare
476 %type <scm> function_arglist_closed
477 %type <scm> function_arglist_closed_optional
478 %type <scm> function_arglist_common
479 %type <scm> function_arglist_common_lyric
480 %type <scm> function_arglist_common_minus
481 %type <scm> function_arglist_closed_common
482 %type <scm> function_arglist_keep
483 %type <scm> function_arglist_closed_keep
484 %type <scm> identifier_init
486 %type <scm> lilypond_header
487 %type <scm> lilypond_header_body
488 %type <scm> lyric_element
489 %type <scm> lyric_element_arg
490 %type <scm> lyric_element_music
491 %type <scm> lyric_markup
493 %type <scm> markup_braced_list
494 %type <scm> markup_braced_list_body
495 %type <scm> markup_composed_list
496 %type <scm> markup_command_list
497 %type <scm> markup_command_list_arguments
498 %type <scm> markup_command_basic_arguments
499 %type <scm> markup_head_1_item
500 %type <scm> markup_head_1_list
501 %type <scm> markup_list
502 %type <scm> markup_top
503 %type <scm> mode_changing_head
504 %type <scm> mode_changing_head_with_context
505 %type <scm> multiplied_duration
506 %type <scm> music_function_event
507 %type <scm> music_function_chord_body
508 %type <scm> music_function_chord_body_arglist
509 %type <scm> new_chord
510 %type <scm> new_lyrics
511 %type <scm> number_expression
512 %type <scm> number_factor
513 %type <scm> number_term
514 %type <scm> octave_check
515 %type <scm> optional_context_mod
516 %type <scm> optional_id
517 %type <scm> optional_notemode_duration
519 %type <scm> pitch_also_in_chords
520 %type <scm> post_events
521 %type <scm> property_operation
522 %type <scm> property_path property_path_revved
524 %type <scm> scalar_closed
525 %type <scm> scm_function_call
526 %type <scm> scm_function_call_closed
527 %type <scm> script_abbreviation
528 %type <scm> simple_chord_elements
529 %type <scm> simple_markup
530 %type <scm> simple_string
531 %type <scm> steno_duration
532 %type <scm> steno_pitch
533 %type <scm> steno_tonic_pitch
534 %type <scm> step_number
535 %type <scm> step_numbers
537 %type <scm> tempo_range
539 %type <score> score_block
540 %type <score> score_body
545 /* We don't assign precedence to / and *, because we might need varied
546 prec levels in different prods */
555 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
556 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
557 } embedded_lilypond {
558 PARSER->lexer_->pop_state ();
559 PARSER->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
563 lilypond: /* empty */ { }
564 | lilypond toplevel_expression {
566 | lilypond assignment {
569 PARSER->error_level_ = 1;
572 PARSER->error_level_ = 1;
579 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
583 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
584 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
589 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
590 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
591 bookpart->unprotect ();
596 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
597 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
601 Music *music = unsmob_music ($1);
602 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
603 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
606 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
607 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
610 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
611 scm_call_2 (proc, PARSER->self_scm (), $1);
615 Output_def * od = $1;
617 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
618 id = ly_symbol2scm ("$defaultpaper");
619 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
620 id = ly_symbol2scm ("$defaultmidi");
621 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
622 id = ly_symbol2scm ("$defaultlayout");
624 PARSER->lexer_->set_identifier (id, od->self_scm ());
632 $$ = PARSER->lexer_->eval_scm ($1);
637 embedded_scm_bare_arg:
643 | context_modification
646 $$ = $1->self_scm ();
649 | context_def_spec_block
652 $$ = $1->self_scm ();
657 $$ = $1->self_scm ();
662 $$ = $1->self_scm ();
667 /* The generic version may end in music, or not */
675 embedded_scm_bare_arg
681 SCM_FUNCTION function_arglist {
682 $$ = MAKE_SYNTAX ("music-function", @$,
690 $$ = MAKE_SYNTAX ("void-music", @$);
693 | music music music_list {
694 $$ = MAKE_SYNTAX ("sequential-music", @$,
695 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
698 PARSER->error_level_ = 1;
700 | INVALID embedded_lilypond {
701 PARSER->error_level_ = 1;
706 lilypond_header_body:
708 $$ = get_header (PARSER);
709 PARSER->lexer_->add_scope ($$);
711 | lilypond_header_body assignment {
717 HEADER '{' lilypond_header_body '}' {
718 $$ = PARSER->lexer_->remove_scope ();
727 | LYRICS_STRING { $$ = $1; }
731 assignment_id '=' identifier_init {
732 PARSER->lexer_->set_identifier ($1, $3);
734 | assignment_id property_path '=' identifier_init {
735 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
736 PARSER->lexer_->set_identifier (path, $4);
739 TODO: devise standard for protection in parser.
741 The parser stack lives on the C-stack, which means that
742 all objects can be unprotected as soon as they're here.
752 $$ = $1->self_scm ();
756 $$ = $1->self_scm ();
760 $$ = $1->self_scm ();
764 $$ = $1->self_scm ();
767 | context_def_spec_block {
771 /* Hack: Create event-chord around standalone events.
772 Prevents the identifier from being interpreted as a post-event. */
773 Music *mus = unsmob_music ($1);
774 bool is_event = mus &&
775 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
780 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
782 | post_event_nofinger {
785 | number_expression {
800 | context_modification {
805 context_def_spec_block:
806 CONTEXT '{' context_def_spec_body '}'
812 context_def_spec_body:
814 $$ = Context_def::make_scm ();
815 unsmob_context_def ($$)->origin ()->set_spot (@$);
817 | CONTEXT_DEF_IDENTIFIER {
819 unsmob_context_def ($$)->origin ()->set_spot (@$);
821 | context_def_spec_body embedded_scm {
822 if (Context_mod *cm = unsmob_context_mod ($2)) {
823 SCM p = cm->get_mods ();
824 Context_def*td = unsmob_context_def ($$);
826 for (; scm_is_pair (p); p = scm_cdr (p)) {
827 td->add_context_mod (scm_car (p));
830 PARSER->parser_error (@2, _ ("not a context mod"));
833 | context_def_spec_body context_mod {
834 unsmob_context_def ($$)->add_context_mod ($2);
836 | context_def_spec_body context_modification {
837 Context_def *td = unsmob_context_def ($$);
838 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
839 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
840 td->add_context_mod (scm_car (m));
848 BOOK '{' book_body '}' {
851 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
856 * Use 'handlers' like for toplevel-* stuff?
857 * grok \layout and \midi? */
861 init_papers (PARSER);
862 $$->origin ()->set_spot (@$);
863 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
864 $$->paper_->unprotect ();
865 push_paper (PARSER, $$->paper_);
866 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
867 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
868 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
869 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
872 $$ = unsmob_book ($1);
874 $$->origin ()->set_spot (@$);
875 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
877 | book_body paper_block {
880 set_paper (PARSER, $2);
882 | book_body bookpart_block {
884 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
885 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
886 bookpart->unprotect ();
888 | book_body score_block {
890 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
891 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
894 | book_body composite_music {
895 Music *music = unsmob_music ($2);
896 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
897 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
899 | book_body full_markup {
900 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
901 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
903 | book_body full_markup_list {
904 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
905 scm_call_2 (proc, $$->self_scm (), $2);
907 | book_body lilypond_header {
910 | book_body embedded_scm { }
913 $$->scores_ = SCM_EOL;
914 $$->bookparts_ = SCM_EOL;
919 BOOKPART '{' bookpart_body '}' {
921 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
928 $$->origin ()->set_spot (@$);
929 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
932 $$ = unsmob_book ($1);
934 $$->origin ()->set_spot (@$);
935 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
937 | bookpart_body paper_block {
941 | bookpart_body score_block {
943 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
944 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
947 | bookpart_body composite_music {
948 Music *music = unsmob_music ($2);
949 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
950 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
952 | bookpart_body full_markup {
953 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
954 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
956 | bookpart_body full_markup_list {
957 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
958 scm_call_2 (proc, $$->self_scm (), $2);
960 | bookpart_body lilypond_header {
963 | bookpart_body embedded_scm { }
964 | bookpart_body error {
966 $$->scores_ = SCM_EOL;
971 SCORE '{' score_body '}' {
979 SCM scorify = ly_lily_module_constant ("scorify-music");
980 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
982 // pass ownernship to C++ again.
983 $$ = unsmob_score (score);
985 $$->origin ()->set_spot (@$);
988 $$ = unsmob_score ($1);
990 $$->origin ()->set_spot (@$);
992 | score_body lilypond_header {
995 | score_body output_def {
996 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
998 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1003 $$->add_output_def ($2);
1007 | score_body error {
1008 $$->error_found_ = true;
1020 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1022 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
1024 $$ = get_paper (PARSER);
1031 output_def_body '}' {
1034 PARSER->lexer_->remove_scope ();
1035 PARSER->lexer_->pop_state ();
1041 $$ = get_paper (PARSER);
1042 $$->input_origin_ = @$;
1043 PARSER->lexer_->add_scope ($$->scope_);
1046 Output_def *p = get_midi (PARSER);
1048 PARSER->lexer_->add_scope (p->scope_);
1051 Output_def *p = get_layout (PARSER);
1053 PARSER->lexer_->add_scope (p->scope_);
1058 output_def_head_with_mode_switch:
1060 PARSER->lexer_->push_initial_state ();
1066 output_def_head_with_mode_switch '{' {
1068 $$->input_origin_.set_spot (@$);
1070 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1073 Output_def *o = unsmob_output_def ($3);
1074 o->input_origin_.set_spot (@$);
1077 PARSER->lexer_->remove_scope ();
1078 PARSER->lexer_->add_scope (o->scope_);
1080 | output_def_body assignment {
1083 | output_def_body context_def_spec_block {
1084 assign_context_def ($$, $2);
1086 | output_def_body error {
1092 TEMPO steno_duration '=' tempo_range {
1093 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1095 | TEMPO scalar_closed steno_duration '=' tempo_range {
1096 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1099 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1104 The representation of a list is reversed to have efficient append. */
1110 | music_list music {
1111 $$ = scm_cons ($2, $1);
1113 | music_list embedded_scm {
1116 | music_list error {
1117 Music *m = MY_MAKE_MUSIC("Music", @$);
1119 m->set_property ("error-found", SCM_BOOL_T);
1120 $$ = scm_cons (m->self_scm (), $1);
1121 m->unprotect (); /* UGH */
1128 $$ = scm_reverse_x ($2, SCM_EOL);
1133 | lyric_element_music
1134 | composite_music %prec COMPOSITE
1139 | composite_music %prec COMPOSITE
1143 REPEAT simple_string unsigned_number music
1145 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1147 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1149 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1154 SEQUENTIAL braced_music_list {
1155 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1157 | braced_music_list {
1158 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1163 SIMULTANEOUS braced_music_list {
1164 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1166 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1167 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1173 | music_property_def
1177 context_modification:
1178 WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1180 PARSER->lexer_->pop_state ();
1183 | WITH CONTEXT_MOD_IDENTIFIER
1187 | CONTEXT_MOD_IDENTIFIER
1191 | WITH embedded_scm_closed
1193 if (unsmob_context_mod ($2))
1196 PARSER->parser_error (@2, _ ("not a context mod"));
1197 $$ = Context_mod ().smobbed_copy ();
1202 optional_context_mod:
1206 | context_modification
1214 $$ = Context_mod ().smobbed_copy ();
1216 | context_mod_list context_mod {
1217 unsmob_context_mod ($1)->add_context_mod ($2);
1219 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1220 Context_mod *md = unsmob_context_mod ($2);
1222 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1224 | context_mod_list embedded_scm {
1225 Context_mod *md = unsmob_context_mod ($2);
1227 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1229 PARSER->parser_error (@2, _ ("not a context mod"));
1238 /* Music that can be parsed without lookahead */
1241 | complex_music_prefix closed_music
1243 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1250 | grouped_music_list
1254 simultaneous_music { $$ = $1; }
1255 | sequential_music { $$ = $1; }
1258 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1259 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1260 and this rule returns the reversed list of arguments. */
1262 function_arglist_skip:
1263 function_arglist_common
1264 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1266 $$ = scm_cons ($1, $3);
1267 } %prec FUNCTION_ARGLIST
1268 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1270 $$ = scm_cons ($1, $3);
1271 } %prec FUNCTION_ARGLIST
1272 | EXPECT_SCM EXPECT_DURATION function_arglist_skip
1274 $$ = scm_cons ($1, $3);
1275 } %prec FUNCTION_ARGLIST
1279 function_arglist_nonbackup:
1280 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1281 $$ = scm_cons ($4, $3);
1283 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1284 $$ = scm_cons ($4, $3);
1286 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1288 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1290 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1292 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1294 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1296 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1298 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1300 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1302 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1304 SCM n = scm_difference ($5, SCM_UNDEFINED);
1305 if (scm_is_true (scm_call_1 ($2, n)))
1306 $$ = scm_cons (n, $3);
1308 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1309 t->set_property ("digit", $5);
1310 $$ = t->unprotect ();
1311 if (scm_is_true (scm_call_1 ($2, $$)))
1312 $$ = scm_cons ($$, $3);
1314 $$ = check_scheme_arg (PARSER, @4, n, $3, $2);
1318 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1320 $$ = check_scheme_arg (PARSER, @4,
1321 scm_difference ($5, SCM_UNDEFINED),
1324 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1326 $$ = check_scheme_arg (PARSER, @4,
1327 scm_difference ($5, SCM_UNDEFINED),
1333 function_arglist_keep:
1334 function_arglist_common
1335 | function_arglist_backup
1338 function_arglist_closed_keep:
1339 function_arglist_closed_common
1340 | function_arglist_backup
1343 function_arglist_backup:
1344 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1346 if (scm_is_true (scm_call_1 ($2, $4)))
1348 $$ = scm_cons ($4, $3);
1350 $$ = scm_cons (loc_on_music (@3, $1), $3);
1351 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1354 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1356 if (scm_is_true (scm_call_1 ($2, $4)))
1358 $$ = scm_cons ($4, $3);
1360 $$ = scm_cons (loc_on_music (@3, $1), $3);
1361 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1364 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1366 // There is no point interpreting a lyrics string as
1367 // an event, since we don't allow music possibly
1368 // followed by durations or postevent into closed
1369 // music, and we only accept closed music in optional
1370 // arguments at the moment. If this changes, more
1371 // complex schemes might become interesting here as
1372 // well: see how we do this at the mandatory argument
1374 if (scm_is_true (scm_call_1 ($2, $4)))
1375 $$ = scm_cons ($4, $3);
1377 $$ = scm_cons (loc_on_music (@3, $1), $3);
1378 MYBACKUP (LYRICS_STRING, $4, @4);
1381 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1383 if (scm_is_true (scm_call_1 ($2, $4)))
1386 MYREPARSE (@4, $2, UNSIGNED, $4);
1388 $$ = scm_cons (loc_on_music (@3, $1), $3);
1389 MYBACKUP (UNSIGNED, $4, @4);
1392 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1394 if (scm_is_true (scm_call_1 ($2, $4)))
1397 MYREPARSE (@4, $2, REAL, $4);
1399 $$ = scm_cons (loc_on_music (@3, $1), $3);
1400 MYBACKUP (REAL, $4, @4);
1403 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1405 if (scm_is_true (scm_call_1 ($2, $4)))
1407 $$ = scm_cons ($4, $3);
1409 $$ = scm_cons (loc_on_music (@3, $1), $3);
1410 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1413 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1415 if (scm_is_true (scm_call_1 ($2, $4)))
1417 $$ = scm_cons ($4, $3);
1419 $$ = scm_cons (loc_on_music (@3, $1), $3);
1420 MYBACKUP (FRACTION, $4, @4);
1423 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1425 SCM n = scm_difference ($5, SCM_UNDEFINED);
1426 if (scm_is_true (scm_call_1 ($2, n))) {
1428 MYREPARSE (@5, $2, REAL, n);
1430 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1431 t->set_property ("digit", $5);
1432 $$ = t->unprotect ();
1433 if (scm_is_true (scm_call_1 ($2, $$)))
1434 $$ = scm_cons ($$, $3);
1436 $$ = scm_cons (loc_on_music (@3, $1), $3);
1437 MYBACKUP (UNSIGNED, $5, @5);
1438 PARSER->lexer_->push_extra_token ('-');
1443 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1445 SCM n = scm_difference ($5, SCM_UNDEFINED);
1446 if (scm_is_true (scm_call_1 ($2, n))) {
1447 MYREPARSE (@5, $2, REAL, n);
1450 MYBACKUP (REAL, n, @5);
1453 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1455 SCM n = scm_difference ($5, SCM_UNDEFINED);
1456 if (scm_is_true (scm_call_1 ($2, n))) {
1457 $$ = scm_cons (n, $3);
1459 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1462 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1464 $$ = scm_cons ($4, $3);
1466 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1468 $$ = scm_cons ($4, $3);
1470 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1472 $$ = scm_cons ($1, $3);
1473 MYBACKUP(0, SCM_UNDEFINED, @3);
1475 | function_arglist_backup REPARSE embedded_scm_arg_closed
1477 $$ = check_scheme_arg (PARSER, @3,
1480 | function_arglist_backup REPARSE bare_number
1482 $$ = check_scheme_arg (PARSER, @3,
1485 | function_arglist_backup REPARSE fraction
1487 $$ = check_scheme_arg (PARSER, @3,
1493 function_arglist_common
1494 | function_arglist_nonbackup
1497 function_arglist_common:
1498 function_arglist_bare
1499 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1501 $$ = check_scheme_arg (PARSER, @3,
1504 | EXPECT_SCM function_arglist_closed_optional bare_number
1506 $$ = check_scheme_arg (PARSER, @3,
1509 | EXPECT_SCM function_arglist_closed_optional fraction
1511 $$ = check_scheme_arg (PARSER, @3,
1514 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1516 $$ = check_scheme_arg (PARSER, @3,
1519 | function_arglist_common_minus
1520 | function_arglist_common_lyric
1523 function_arglist_common_lyric:
1524 EXPECT_SCM function_arglist_optional lyric_element
1526 // We check how the predicate thinks about a lyrics
1527 // event or about a markup. If it accepts neither, we
1528 // backup the original token. Otherwise we commit to
1529 // taking the token. Depending on what the predicate
1530 // is willing to accept, we interpret as a string, as
1531 // a lyric event, or ambiguously (meaning that if
1532 // something looking like a duration or post event
1533 // follows, we take the event, otherwise the string).
1534 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1535 PARSER->default_duration_.smobbed_copy ());
1536 if (scm_is_true (scm_call_1 ($1, $3)))
1537 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1540 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1542 $$ = scm_cons ($3, $2);
1544 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1547 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1549 // This is going to flag a syntax error, we
1550 // know the predicate to be false.
1551 check_scheme_arg (PARSER, @3,
1555 | function_arglist_common_lyric REPARSE lyric_element_arg
1557 // This should never be false
1558 $$ = check_scheme_arg (PARSER, @3,
1563 function_arglist_common_minus:
1564 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1566 SCM n = scm_difference ($4, SCM_UNDEFINED);
1567 if (scm_is_true (scm_call_1 ($1, n))) {
1569 MYREPARSE (@4, $1, REAL, n);
1571 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1572 t->set_property ("digit", $4);
1573 $$ = t->unprotect ();
1574 if (scm_is_true (scm_call_1 ($1, $$)))
1575 $$ = scm_cons ($$, $2);
1577 $$ = check_scheme_arg (PARSER, @3, n, $2, $1);
1581 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1584 SCM n = scm_difference ($4, SCM_UNDEFINED);
1585 MYREPARSE (@4, $1, REAL, n);
1587 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1589 SCM n = scm_difference ($4, SCM_UNDEFINED);
1590 $$ = check_scheme_arg (PARSER, @4, n, $2, $1);
1592 | function_arglist_common_minus REPARSE bare_number
1594 $$ = check_scheme_arg (PARSER, @3, $3, $1, $2);
1598 function_arglist_closed:
1599 function_arglist_closed_common
1600 | function_arglist_nonbackup
1603 function_arglist_closed_common:
1604 function_arglist_bare
1605 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1607 $$ = check_scheme_arg (PARSER, @3,
1610 | EXPECT_SCM function_arglist_closed_optional bare_number
1612 $$ = check_scheme_arg (PARSER, @3,
1615 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1617 SCM n = scm_difference ($4, SCM_UNDEFINED);
1618 if (scm_is_true (scm_call_1 ($1, n))) {
1619 $$ = scm_cons (n, $2);
1621 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1622 t->set_property ("digit", $4);
1623 $$ = t->unprotect ();
1624 if (scm_is_true (scm_call_1 ($1, $$)))
1625 $$ = scm_cons ($$, $2);
1627 $$ = check_scheme_arg (PARSER, @3, n, $2, $1);
1631 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1633 $$ = check_scheme_arg (PARSER, @3,
1634 scm_difference ($4, SCM_UNDEFINED),
1637 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1639 $$ = check_scheme_arg (PARSER, @3,
1640 scm_difference ($4, SCM_UNDEFINED),
1643 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1645 $$ = check_scheme_arg (PARSER, @3,
1648 | EXPECT_SCM function_arglist_closed_optional fraction
1650 $$ = check_scheme_arg (PARSER, @3,
1653 | EXPECT_SCM function_arglist_optional lyric_element
1655 $$ = check_scheme_arg (PARSER, @3,
1660 function_arglist_optional:
1661 function_arglist_keep %prec FUNCTION_ARGLIST
1662 | function_arglist_backup BACKUP
1663 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1665 $$ = scm_cons ($1, $3);
1667 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1669 $$ = scm_cons ($1, $3);
1673 function_arglist_closed_optional:
1674 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1675 | function_arglist_backup BACKUP
1676 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1678 $$ = scm_cons ($1, $3);
1680 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1682 $$ = scm_cons ($1, $3);
1686 embedded_scm_closed:
1688 | scm_function_call_closed
1691 embedded_scm_arg_closed:
1692 embedded_scm_bare_arg
1693 | scm_function_call_closed
1697 scm_function_call_closed:
1698 SCM_FUNCTION function_arglist_closed {
1699 $$ = MAKE_SYNTAX ("music-function", @$,
1701 } %prec FUNCTION_ARGLIST
1704 function_arglist_bare:
1705 EXPECT_NO_MORE_ARGS {
1708 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1709 $$ = scm_cons ($3, $2);
1711 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1712 $$ = scm_cons ($3, $2);
1714 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1715 $$ = scm_cons ($1, $3);
1717 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1718 $$ = scm_cons ($1, $3);
1720 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1721 $$ = scm_cons ($1, $3);
1725 music_function_call:
1726 MUSIC_FUNCTION function_arglist {
1727 $$ = MAKE_SYNTAX ("music-function", @$,
1734 /**/ { $$ = SCM_EOL; }
1735 | '=' simple_string {
1742 | repeated_music { $$ = $1; }
1743 | re_rhythmed_music { $$ = $1; }
1744 | complex_music_prefix music
1746 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1750 complex_music_prefix:
1751 CONTEXT simple_string optional_id optional_context_mod {
1752 Context_mod *ctxmod = unsmob_context_mod ($4);
1755 mods = ctxmod->get_mods ();
1756 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1758 | NEWCONTEXT simple_string optional_id optional_context_mod {
1759 Context_mod *ctxmod = unsmob_context_mod ($4);
1762 mods = ctxmod->get_mods ();
1763 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1768 mode_changing_head grouped_music_list {
1769 if ($1 == ly_symbol2scm ("chords"))
1771 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1777 PARSER->lexer_->pop_state ();
1779 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1780 Context_mod *ctxmod = unsmob_context_mod ($2);
1783 mods = ctxmod->get_mods ();
1784 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1785 if ($1 == ly_symbol2scm ("ChordNames"))
1787 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1789 PARSER->lexer_->pop_state ();
1795 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1796 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1798 $$ = ly_symbol2scm ("notes");
1802 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1803 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1805 $$ = ly_symbol2scm ("drums");
1808 PARSER->lexer_->push_figuredbass_state ();
1810 $$ = ly_symbol2scm ("figures");
1813 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1814 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1815 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1816 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1817 $$ = ly_symbol2scm ("chords");
1821 { PARSER->lexer_->push_lyric_state ();
1822 $$ = ly_symbol2scm ("lyrics");
1826 mode_changing_head_with_context:
1828 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1829 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1831 $$ = ly_symbol2scm ("DrumStaff");
1834 PARSER->lexer_->push_figuredbass_state ();
1836 $$ = ly_symbol2scm ("FiguredBass");
1839 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1840 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1841 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1842 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1843 $$ = ly_symbol2scm ("ChordNames");
1846 { PARSER->lexer_->push_lyric_state ();
1847 $$ = ly_symbol2scm ("Lyrics");
1852 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1855 /* Can also use music at the expensive of two S/Rs similar to
1856 \repeat \alternative */
1857 PARSER->lexer_->pop_state ();
1859 $$ = scm_cons ($3, SCM_EOL);
1861 | new_lyrics ADDLYRICS {
1862 PARSER->lexer_->push_lyric_state ();
1864 PARSER->lexer_->pop_state ();
1865 $$ = scm_cons ($4, $1);
1870 composite_music new_lyrics {
1871 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1873 | LYRICSTO simple_string {
1874 PARSER->lexer_->push_lyric_state ();
1876 PARSER->lexer_->pop_state ();
1877 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1882 CHANGE STRING '=' STRING {
1883 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1888 property_path_revved:
1889 embedded_scm_closed {
1890 $$ = scm_cons ($1, SCM_EOL);
1892 | property_path_revved embedded_scm_closed {
1893 $$ = scm_cons ($2, $1);
1898 property_path_revved {
1899 $$ = scm_reverse_x ($1, SCM_EOL);
1905 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1906 scm_string_to_symbol ($1), $3);
1908 | UNSET simple_string {
1909 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1910 scm_string_to_symbol ($2));
1912 | OVERRIDE simple_string property_path '=' scalar {
1913 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1914 scm_string_to_symbol ($2), $5),
1917 | REVERT simple_string embedded_scm {
1918 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1919 scm_string_to_symbol ($2), $3);
1924 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1925 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1927 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1928 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1929 | DENIES { $$ = ly_symbol2scm ("denies"); }
1931 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1932 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1933 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1934 | NAME { $$ = ly_symbol2scm ("context-name"); }
1938 property_operation { $$ = $1; }
1939 | context_def_mod STRING {
1940 $$ = scm_list_2 ($1, $2);
1942 | context_def_mod embedded_scm {
1943 if (ly_symbol2scm ("consists") != $1)
1946 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1950 $$ = scm_list_2 ($1, $2);
1957 if (!is_regular_identifier ($1))
1959 @$.error (_("Grob name should be alphanumeric"));
1962 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1963 scm_string_to_symbol ($1));
1965 | simple_string '.' simple_string {
1966 $$ = scm_list_2 (scm_string_to_symbol ($1),
1967 scm_string_to_symbol ($3));
1971 simple_music_property_def:
1972 OVERRIDE context_prop_spec property_path '=' scalar {
1973 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1974 ly_symbol2scm ("OverrideProperty"),
1979 | REVERT context_prop_spec embedded_scm {
1980 $$ = scm_list_4 (scm_car ($2),
1981 ly_symbol2scm ("RevertProperty"),
1985 | SET context_prop_spec '=' scalar {
1986 $$ = scm_list_4 (scm_car ($2),
1987 ly_symbol2scm ("PropertySet"),
1991 | UNSET context_prop_spec {
1992 $$ = scm_list_3 (scm_car ($2),
1993 ly_symbol2scm ("PropertyUnset"),
1999 simple_music_property_def {
2000 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (PARSER->self_scm (), make_input (@$), $1));
2008 | STRING_IDENTIFIER {
2011 | string '+' string {
2012 $$ = scm_string_append (scm_list_2 ($1, $3));
2016 simple_string: STRING {
2022 | STRING_IDENTIFIER {
2034 embedded_scm_arg_closed
2041 /* TODO: Create a special case that avoids the creation of
2042 EventChords around simple_elements that have no post_events?
2044 simple_chord_elements post_events {
2045 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2048 /* why is this giving wrong start location? -ns
2050 i.set_location (@1, @2);
2051 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2053 | CHORD_REPETITION optional_notemode_duration post_events {
2055 i.set_location (@1, @3);
2056 $$ = MAKE_SYNTAX ("repetition-chord", i,
2057 PARSER->lexer_->chord_repetition_.last_chord_,
2058 PARSER->lexer_->chord_repetition_.repetition_function_,
2059 $2, scm_reverse_x ($3, SCM_EOL));
2061 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2063 i.set_location (@1, @3);
2064 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2065 scm_reverse_x ($3, SCM_EOL));
2068 /* note chord elements are memorized into
2069 PARSER->lexer_->chord_repetition_ so that the chord repetition
2070 mechanism copy them when a chord repetition symbol is found
2072 | note_chord_element {
2073 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
2079 chord_body optional_notemode_duration post_events
2081 Music *m = unsmob_music ($1);
2082 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2083 SCM es = m->get_property ("elements");
2084 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2086 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2087 unsmob_music (scm_car (s))->set_property ("duration", dur);
2088 es = ly_append2 (es, postevs);
2090 m-> set_property ("elements", es);
2092 $$ = m->self_scm ();
2097 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2099 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2103 chord_body_elements:
2104 /* empty */ { $$ = SCM_EOL; }
2105 | chord_body_elements chord_body_element {
2106 $$ = scm_cons ($2, $1);
2111 pitch exclamations questions octave_check post_events
2118 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2119 n->set_property ("pitch", $1);
2121 n->set_property ("cautionary", SCM_BOOL_T);
2122 if (ex % 2 || q % 2)
2123 n->set_property ("force-accidental", SCM_BOOL_T);
2125 if (scm_is_pair (post)) {
2126 SCM arts = scm_reverse_x (post, SCM_EOL);
2127 n->set_property ("articulations", arts);
2129 if (scm_is_number (check))
2131 int q = scm_to_int (check);
2132 n->set_property ("absolute-octave", scm_from_int (q-1));
2135 $$ = n->unprotect ();
2137 | DRUM_PITCH post_events {
2138 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2139 n->set_property ("drum-type", $1);
2141 if (scm_is_pair ($2)) {
2142 SCM arts = scm_reverse_x ($2, SCM_EOL);
2143 n->set_property ("articulations", arts);
2145 $$ = n->unprotect ();
2147 | music_function_chord_body
2150 /* We can't accept a music argument, not even a closed one,
2151 * immediately before chord_body_elements, otherwise a function \fun
2152 * with a signature of two music arguments can't be sorted out
2153 * properly in a construct like
2154 * <\fun { c } \fun { c } c>
2155 * The second call could be interpreted either as a chord constituent
2156 * or a music expression.
2159 music_function_chord_body_arglist:
2160 function_arglist_bare
2161 | EXPECT_SCM music_function_chord_body_arglist embedded_scm_chord_body
2163 $$ = check_scheme_arg (PARSER, @3,
2168 embedded_scm_chord_body:
2169 embedded_scm_bare_arg
2170 | SCM_FUNCTION music_function_chord_body_arglist {
2171 $$ = MAKE_SYNTAX ("music-function", @$,
2177 | chord_body_element
2180 music_function_chord_body:
2181 MUSIC_FUNCTION music_function_chord_body_arglist {
2182 $$ = MAKE_SYNTAX ("music-function", @$,
2187 // Event functions may only take closed arglists, otherwise it would
2188 // not be clear whether a following postevent should be associated
2189 // with the last argument of the event function or with the expression
2190 // for which the function call acts itself as event.
2192 music_function_event:
2193 MUSIC_FUNCTION function_arglist_closed {
2194 $$ = MAKE_SYNTAX ("music-function", @$,
2199 event_function_event:
2200 EVENT_FUNCTION function_arglist_closed {
2201 $$ = MAKE_SYNTAX ("music-function", @$,
2211 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2212 m->set_property ("span-direction", scm_from_int (START));
2213 $$ = m->unprotect();
2216 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2217 m->set_property ("span-direction", scm_from_int (STOP));
2218 $$ = m->unprotect ();
2221 $$ = MAKE_SYNTAX ("voice-separator", @$);
2224 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
2226 Music *m = unsmob_music (pipe);
2231 $$ = m->unprotect ();
2234 $$ = MAKE_SYNTAX ("bar-check", @$);
2241 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2253 | post_events post_event {
2254 unsmob_music ($2)->set_spot (@2);
2255 $$ = scm_cons ($2, $$);
2259 post_event_nofinger:
2260 direction_less_event {
2263 | script_dir music_function_event {
2267 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2271 if (!PARSER->lexer_->is_lyric_state ())
2272 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2273 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2276 if (!PARSER->lexer_->is_lyric_state ())
2277 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2278 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2280 | script_dir direction_reqd_event {
2283 Music *m = unsmob_music ($2);
2284 m->set_property ("direction", scm_from_int ($1));
2288 | script_dir direction_less_event {
2291 Music *m = unsmob_music ($2);
2292 m->set_property ("direction", scm_from_int ($1));
2296 | string_number_event
2300 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2305 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2316 string_number_event:
2318 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2319 s->set_property ("string-number", scm_from_int ($1));
2320 $$ = s->unprotect ();
2324 direction_less_char:
2326 $$ = ly_symbol2scm ("bracketOpenSymbol");
2329 $$ = ly_symbol2scm ("bracketCloseSymbol");
2332 $$ = ly_symbol2scm ("tildeSymbol");
2335 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2338 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2341 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2344 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2347 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2350 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2353 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2357 direction_less_event:
2358 direction_less_char {
2359 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
2361 if (unsmob_music (predefd))
2363 m = unsmob_music (predefd)->clone ();
2368 m = MY_MAKE_MUSIC ("Music", @$);
2370 $$ = m->unprotect ();
2372 | EVENT_IDENTIFIER {
2376 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2377 a->set_property ("tremolo-type", scm_from_int ($1));
2378 $$ = a->unprotect ();
2380 | event_function_event
2383 direction_reqd_event:
2387 | script_abbreviation {
2388 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2389 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2390 if (scm_is_string (s))
2391 a->set_property ("articulation-type", s);
2392 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
2393 $$ = a->unprotect ();
2398 /**/ { $$ = SCM_EOL; }
2399 | '=' { $$ = scm_from_int (0); }
2400 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2401 | '=' sup_quotes { $$ = scm_from_int ($2); }
2426 | NOTENAME_PITCH sup_quotes {
2427 Pitch p = *unsmob_pitch ($1);
2428 p = p.transposed (Pitch ($2,0,0));
2429 $$ = p.smobbed_copy ();
2431 | NOTENAME_PITCH sub_quotes {
2432 Pitch p =* unsmob_pitch ($1);
2433 p = p.transposed (Pitch (-$2,0,0));
2434 $$ = p.smobbed_copy ();
2446 | TONICNAME_PITCH sup_quotes {
2447 Pitch p = *unsmob_pitch ($1);
2448 p = p.transposed (Pitch ($2,0,0));
2449 $$ = p.smobbed_copy ();
2451 | TONICNAME_PITCH sub_quotes {
2452 Pitch p = *unsmob_pitch ($1);
2454 p = p.transposed (Pitch (-$2,0,0));
2455 $$ = p.smobbed_copy ();
2466 pitch_also_in_chords:
2473 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2474 t->set_property ("text", $1);
2475 $$ = t->unprotect ();
2478 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2479 t->set_property ("text",
2480 make_simple_markup ($1));
2481 $$ = t->unprotect ();
2487 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2488 t->set_property ("digit", $1);
2489 $$ = t->unprotect ();
2493 script_abbreviation:
2495 $$ = scm_from_locale_string ("Hat");
2498 $$ = scm_from_locale_string ("Plus");
2501 $$ = scm_from_locale_string ("Dash");
2504 $$ = scm_from_locale_string ("Bar");
2507 $$ = scm_from_locale_string ("Larger");
2510 $$ = scm_from_locale_string ("Dot");
2513 $$ = scm_from_locale_string ("Underscore");
2520 | '-' { $$ = CENTER; }
2524 multiplied_duration {
2529 optional_notemode_duration:
2531 Duration dd = PARSER->default_duration_;
2532 $$ = dd.smobbed_copy ();
2534 | multiplied_duration {
2536 PARSER->default_duration_ = *unsmob_duration ($$);
2541 bare_unsigned dots {
2543 if (!is_duration ($1))
2544 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
2548 $$ = Duration (len, $2).smobbed_copy ();
2550 | DURATION_IDENTIFIER dots {
2551 Duration *d = unsmob_duration ($1);
2552 Duration k (d->duration_log (), d->dot_count () + $2);
2553 k = k.compressed (d->factor ());
2559 multiplied_duration:
2563 | multiplied_duration '*' bare_unsigned {
2564 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2566 | multiplied_duration '*' FRACTION {
2567 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2569 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2574 FRACTION { $$ = $1; }
2575 | UNSIGNED '/' UNSIGNED {
2576 $$ = scm_cons ($1, $3);
2593 | ':' bare_unsigned {
2594 if (!is_duration ($2))
2595 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2601 UNSIGNED { $$ = $1; }
2602 | STRING { $$ = $1; }
2603 | full_markup { $$ = $1; }
2606 figured_bass_alteration:
2607 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2608 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2609 | '!' { $$ = scm_from_int (0); }
2614 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2615 $$ = bfr->unprotect ();
2618 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2619 $$ = bfr->self_scm ();
2621 if (scm_is_number ($1))
2622 bfr->set_property ("figure", $1);
2623 else if (Text_interface::is_markup ($1))
2624 bfr->set_property ("text", $1);
2630 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2632 | bass_figure figured_bass_alteration {
2633 Music *m = unsmob_music ($1);
2634 if (scm_to_double ($2)) {
2635 SCM salter = m->get_property ("alteration");
2636 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2637 m->set_property ("alteration",
2638 scm_sum (alter, $2));
2640 m->set_property ("alteration", scm_from_int (0));
2643 | bass_figure figured_bass_modification {
2644 Music *m = unsmob_music ($1);
2645 if ($2 == ly_symbol2scm ("plus"))
2647 m->set_property ("augmented", SCM_BOOL_T);
2649 else if ($2 == ly_symbol2scm ("slash"))
2651 m->set_property ("diminished", SCM_BOOL_T);
2653 else if ($2 == ly_symbol2scm ("exclamation"))
2655 m->set_property ("no-continuation", SCM_BOOL_T);
2657 else if ($2 == ly_symbol2scm ("backslash"))
2659 m->set_property ("augmented-slash", SCM_BOOL_T);
2665 figured_bass_modification:
2667 $$ = ly_symbol2scm ("plus");
2670 $$ = ly_symbol2scm ("exclamation");
2673 $$ = ly_symbol2scm ("slash");
2676 $$ = ly_symbol2scm ("backslash");
2686 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2694 | figure_list br_bass_figure {
2695 $$ = scm_cons ($2, $1);
2700 FIGURE_OPEN figure_list FIGURE_CLOSE {
2701 $$ = scm_reverse_x ($2, SCM_EOL);
2712 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2713 if (!PARSER->lexer_->is_note_state ())
2714 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2718 n = MY_MAKE_MUSIC ("RestEvent", @$);
2720 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2722 n->set_property ("pitch", $1);
2723 n->set_property ("duration", $5);
2725 if (scm_is_number ($4))
2727 int q = scm_to_int ($4);
2728 n->set_property ("absolute-octave", scm_from_int (q-1));
2732 n->set_property ("cautionary", SCM_BOOL_T);
2733 if ($2 % 2 || $3 % 2)
2734 n->set_property ("force-accidental", SCM_BOOL_T);
2736 $$ = n->unprotect ();
2738 | DRUM_PITCH optional_notemode_duration {
2739 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2740 n->set_property ("duration", $2);
2741 n->set_property ("drum-type", $1);
2743 $$ = n->unprotect ();
2745 | RESTNAME optional_notemode_duration {
2747 if (ly_scm2string ($1) == "s") {
2749 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2752 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2755 ev->set_property ("duration", $2);
2756 $$ = ev->unprotect ();
2760 simple_chord_elements:
2762 $$ = scm_list_1 ($1);
2765 if (!PARSER->lexer_->is_chord_state ())
2766 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2769 | figure_spec optional_notemode_duration {
2770 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2772 unsmob_music (scm_car (s))->set_property ("duration", $2);
2789 | lyric_element multiplied_duration post_events {
2790 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2791 $$ = MAKE_SYNTAX ("event-chord", @$,
2792 scm_cons (lyric_event,
2793 scm_reverse_x ($3, SCM_EOL)));
2795 | lyric_element post_event post_events {
2797 MAKE_SYNTAX ("lyric-event", @$, $1,
2798 PARSER->default_duration_.smobbed_copy ());
2799 $$ = MAKE_SYNTAX ("event-chord", @$,
2800 scm_cons2 (lyric_event, $2,
2801 scm_reverse_x ($3, SCM_EOL)));
2804 | LYRIC_ELEMENT optional_notemode_duration post_events {
2805 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2806 $$ = MAKE_SYNTAX ("event-chord", @$,
2807 scm_cons (lyric_event,
2808 scm_reverse_x ($3, SCM_EOL)));
2813 lyric_element_music:
2814 lyric_element optional_notemode_duration post_events {
2815 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2816 $$ = MAKE_SYNTAX ("event-chord", @$,
2817 scm_cons (lyric_event,
2818 scm_reverse_x ($3, SCM_EOL)));
2823 steno_tonic_pitch optional_notemode_duration {
2824 $$ = make_chord_elements ($1, $2, SCM_EOL);
2826 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2827 SCM its = scm_reverse_x ($4, SCM_EOL);
2828 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2836 | chord_items chord_item {
2837 $$ = scm_cons ($2, $$);
2843 $$ = ly_symbol2scm ("chord-colon");
2846 $$ = ly_symbol2scm ("chord-caret");
2848 | CHORD_SLASH steno_tonic_pitch {
2849 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2851 | CHORD_BASS steno_tonic_pitch {
2852 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2861 $$ = scm_reverse_x ($1, SCM_EOL);
2869 step_number { $$ = scm_cons ($1, SCM_EOL); }
2870 | step_numbers '.' step_number {
2871 $$ = scm_cons ($3, $$);
2877 $$ = make_chord_step ($1, 0);
2879 | bare_unsigned '+' {
2880 $$ = make_chord_step ($1, SHARP_ALTERATION);
2882 | bare_unsigned CHORD_MINUS {
2883 $$ = make_chord_step ($1, FLAT_ALTERATION);
2889 $$ = scm_from_int ($1);
2891 | bare_unsigned '~' bare_unsigned {
2892 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2899 TODO: should deprecate in favor of Scheme?
2903 number_expression '+' number_term {
2904 $$ = scm_sum ($1, $3);
2906 | number_expression '-' number_term {
2907 $$ = scm_difference ($1, $3);
2916 | number_factor '*' number_factor {
2917 $$ = scm_product ($1, $3);
2919 | number_factor '/' number_factor {
2920 $$ = scm_divide ($1, $3);
2925 '-' number_factor { /* %prec UNARY_MINUS */
2926 $$ = scm_difference ($2, SCM_UNDEFINED);
2934 | UNSIGNED NUMBER_IDENTIFIER {
2935 $$ = scm_product ($1, $2)
2937 | REAL NUMBER_IDENTIFIER {
2938 $$ = scm_product ($1, $2)
2950 $$ = scm_to_int ($1);
2961 | exclamations '!' { $$ ++; }
2966 | questions '?' { $$ ++; }
2970 This should be done more dynamically if possible.
2974 LYRIC_MARKUP_IDENTIFIER {
2978 { PARSER->lexer_->push_markup_state (); }
2981 PARSER->lexer_->pop_state ();
2986 MARKUPLIST_IDENTIFIER {
2990 { PARSER->lexer_->push_markup_state (); }
2993 PARSER->lexer_->pop_state ();
3002 { PARSER->lexer_->push_markup_state (); }
3005 PARSER->lexer_->pop_state ();
3011 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3013 | markup_head_1_list simple_markup {
3014 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3024 if (Text_interface::is_markup ($1))
3025 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3026 else if (Text_interface::is_markup_list ($1))
3027 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3029 PARSER->parser_error (@1, _ ("not a markup"));
3030 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3037 MARKUPLIST_IDENTIFIER {
3040 | markup_composed_list {
3043 | markup_braced_list {
3046 | markup_command_list {
3047 $$ = scm_list_1 ($1);
3049 | markup_scm MARKUPLIST_IDENTIFIER
3055 markup_composed_list:
3056 markup_head_1_list markup_braced_list {
3057 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3063 '{' markup_braced_list_body '}' {
3064 $$ = scm_reverse_x ($2, SCM_EOL);
3068 markup_braced_list_body:
3069 /* empty */ { $$ = SCM_EOL; }
3070 | markup_braced_list_body markup {
3071 $$ = scm_cons ($2, $1);
3073 | markup_braced_list_body markup_list {
3074 $$ = scm_reverse_x ($2, $1);
3078 markup_command_list:
3079 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3080 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3084 markup_command_basic_arguments:
3085 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3086 $$ = scm_cons ($3, $2);
3088 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3089 $$ = check_scheme_arg (PARSER, @3, $3, $2, $1);
3091 | EXPECT_NO_MORE_ARGS {
3096 markup_command_list_arguments:
3097 markup_command_basic_arguments { $$ = $1; }
3098 | EXPECT_MARKUP markup_command_list_arguments markup {
3099 $$ = scm_cons ($3, $2);
3104 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3105 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3110 markup_head_1_item {
3111 $$ = scm_list_1 ($1);
3113 | markup_head_1_list markup_head_1_item {
3114 $$ = scm_cons ($2, $1);
3120 $$ = make_simple_markup ($1);
3122 | MARKUP_IDENTIFIER {
3125 | LYRIC_MARKUP_IDENTIFIER {
3128 | STRING_IDENTIFIER {
3132 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
3133 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
3134 } '{' score_body '}' {
3136 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3138 PARSER->lexer_->pop_state ();
3140 | MARKUP_FUNCTION markup_command_basic_arguments {
3141 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3143 | markup_scm MARKUP_IDENTIFIER
3150 markup_head_1_list simple_markup {
3151 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3152 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3162 Lily_parser::set_yydebug (bool x)
3168 Lily_parser::do_yyparse ()
3179 It is a little strange to have this function in this file, but
3180 otherwise, we have to import music classes into the lexer.
3184 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3186 if (scm_is_string (sid)) {
3188 return STRING_IDENTIFIER;
3189 } else if (unsmob_book (sid)) {
3190 Book *book = unsmob_book (sid)->clone ();
3191 *destination = book->self_scm ();
3194 return BOOK_IDENTIFIER;
3195 } else if (scm_is_number (sid)) {
3197 return NUMBER_IDENTIFIER;
3198 } else if (unsmob_context_def (sid)) {
3199 Context_def *def= unsmob_context_def (sid)->clone ();
3201 *destination = def->self_scm ();
3204 return CONTEXT_DEF_IDENTIFIER;
3205 } else if (unsmob_context_mod (sid)) {
3206 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3208 return CONTEXT_MOD_IDENTIFIER;
3209 } else if (unsmob_score (sid)) {
3210 Score *score = new Score (*unsmob_score (sid));
3211 *destination = score->self_scm ();
3213 score->unprotect ();
3214 return SCORE_IDENTIFIER;
3215 } else if (Music *mus = unsmob_music (sid)) {
3216 mus = mus->clone ();
3217 *destination = mus->self_scm ();
3218 unsmob_music (*destination)->
3219 set_property ("origin", make_input (last_input_));
3221 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
3225 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3226 } else if (unsmob_pitch (sid)) {
3227 *destination = unsmob_pitch (sid)->smobbed_copy ();
3228 return PITCH_IDENTIFIER;
3229 } else if (unsmob_duration (sid)) {
3230 *destination = unsmob_duration (sid)->smobbed_copy ();
3231 return DURATION_IDENTIFIER;
3232 } else if (unsmob_output_def (sid)) {
3233 Output_def *p = unsmob_output_def (sid);
3236 *destination = p->self_scm ();
3238 return OUTPUT_DEF_IDENTIFIER;
3239 } else if (Text_interface::is_markup (sid)) {
3241 if (is_lyric_state ())
3242 return LYRIC_MARKUP_IDENTIFIER;
3243 return MARKUP_IDENTIFIER;
3244 } else if (Text_interface::is_markup_list (sid)) {
3246 return MARKUPLIST_IDENTIFIER;
3253 get_next_unique_context_id ()
3255 return scm_from_locale_string ("$uniqueContextId");
3260 get_next_unique_lyrics_context_id ()
3262 static int new_context_count;
3264 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3265 return scm_from_locale_string (s);
3268 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3269 SCM arg, SCM args, SCM pred)
3271 args = scm_cons (arg, args);
3272 if (scm_is_true (scm_call_1 (pred, arg)))
3274 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3275 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3276 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3280 SCM loc_on_music (Input loc, SCM arg)
3282 if (Music *m = unsmob_music (arg))
3286 return m->unprotect ();
3292 is_regular_identifier (SCM id)
3294 string str = ly_scm2string (id);
3295 char const *s = str.c_str ();
3304 v = v && isalnum (*s);
3311 make_music_with_input (SCM name, Input where)
3313 Music *m = make_music_by_name (name);
3314 m->set_spot (where);
3319 make_simple_markup (SCM a)
3327 return t && t == 1 << intlog2 (t);
3331 set_music_properties (Music *p, SCM a)
3333 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3334 p->set_property (scm_caar (k), scm_cdar (k));
3339 make_chord_step (int step, Rational alter)
3342 alter += FLAT_ALTERATION;
3346 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3347 return m.smobbed_copy ();
3352 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
3354 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3355 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
3359 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3361 Lily_lexer *lex = parser->lexer_;
3365 lex->prepare_for_next_token ();
3366 return lex->yylex ();