1 /* -*- mode: c++; c-file-style: "linux" -*- */
3 This file is part of LilyPond, the GNU music typesetter.
5 Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 Jan Nieuwenhuizen <janneke@gnu.org>
8 LilyPond is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 /* Mode and indentation are at best a rough approximation based on TAB
23 * formatting (reasonable for compatibility with unspecific editor
24 * modes as Bison modes are hard to find) and need manual correction
25 * frequently. Without a reasonably dependable way of formatting a
26 * Bison file sensibly, there is little point in trying to fix the
27 * inconsistent state of indentation.
33 #define YYERROR_VERBOSE 1
35 #define yyerror Lily_parser::parser_error
37 /* We use custom location type: Input objects */
39 #define YYLLOC_DEFAULT(Current,Rhs,N) \
40 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
45 %parse-param {Lily_parser *parser}
46 %lex-param {Lily_parser *parser}
48 /* We use SCMs to do strings, because it saves us the trouble of
49 deleting them. Let's hope that a stack overflow doesn't trigger a move
50 of the parse stack onto the heap. */
56 /* The above precedences tackle the shift/reduce problem
59 \repeat .. \alternative
61 \repeat { \repeat .. \alternative }
65 \repeat { \repeat } \alternative
71 /* ADDLYRICS needs to have lower precedence than argument scanning,
72 * or we won't be able to tell music apart from closed_music without
73 * lookahead in the context of function calls.
78 /* \default is only applied after exhausting function arguments */
80 %nonassoc FUNCTION_ARGLIST
82 /* expressions with units are permitted into argument lists */
84 %right PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
85 UNSIGNED REAL DURATION_IDENTIFIER ':'
87 /* The above are the symbols that can start optional function arguments
88 that are recognized in the grammar rather than by predicate
91 %nonassoc NUMBER_IDENTIFIER '/'
93 /* Number-unit expressions, where permitted, are concatenated into
94 * function arguments, just like fractions and tremoli. Tremoli must
95 * not have higher precedence than UNSIGNED, or Lilypond will not
96 * join ':' with a following optional number.
109 %{ // -*-Fundamental-*-
114 * The rules for who is protecting what are very shady. Uniformise
117 * There are too many lexical modes?
128 #include "context-def.hh"
129 #include "context-mod.hh"
130 #include "dimensions.hh"
131 #include "file-path.hh"
133 #include "international.hh"
134 #include "lily-guile.hh"
135 #include "lily-lexer.hh"
136 #include "lily-parser.hh"
140 #include "output-def.hh"
141 #include "paper-book.hh"
142 #include "scm-hash.hh"
144 #include "text-interface.hh"
148 Lily_parser::parser_error (Input const *i, Lily_parser *parser, string s)
150 parser->parser_error (*i, s);
153 #define MYBACKUP(Token, Value, Location) \
155 if (yychar == YYEMPTY) \
158 parser->lexer_->push_extra_token (Token, Value); \
159 parser->lexer_->push_extra_token (BACKUP); \
161 parser->parser_error \
162 (Location, _("Too much lookahead")); \
167 #define MYREPARSE(Location, Pred, Token, Value) \
169 if (yychar == YYEMPTY) \
171 parser->lexer_->push_extra_token (Token, Value); \
172 parser->lexer_->push_extra_token (REPARSE, \
175 parser->parser_error \
176 (Location, _("Too much lookahead")); \
185 Output_def *outputdef;
194 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
197 - Don't use lily module, create a new module instead.
198 - delay application of the function
200 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
201 scm_apply_0 (proc, args)
202 /* Syntactic Sugar. */
203 #define MAKE_SYNTAX(name, location, ...) \
204 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (location) , ##__VA_ARGS__, SCM_UNDEFINED))
205 #define START_MAKE_SYNTAX(name, ...) \
206 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
207 #define FINISH_MAKE_SYNTAX(start, location, ...) \
208 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)))))
210 SCM get_next_unique_context_id ();
211 SCM get_next_unique_lyrics_context_id ();
218 #define _(x) gettext (x)
222 static Music *make_music_with_input (SCM name, Input where);
223 SCM check_scheme_arg (Lily_parser *parser, Input loc,
224 SCM arg, SCM args, SCM pred);
225 SCM loc_on_music (Input loc, SCM arg);
226 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
227 SCM make_chord_step (int step, Rational alter);
228 SCM make_simple_markup (SCM a);
229 bool is_duration (int t);
230 bool is_regular_identifier (SCM id);
231 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
232 void set_music_properties (Music *p, SCM a);
236 /* The third option is an alias that will be used to display the
237 syntax error. Bison CVS now correctly handles backslash escapes.
239 FIXME: Bison needs to translate some of these, eg, STRING.
243 /* Keyword tokens with plain escaped name. */
244 %token ACCEPTS "\\accepts"
245 %token ADDLYRICS "\\addlyrics"
246 %token ALIAS "\\alias"
247 %token ALTERNATIVE "\\alternative"
249 %token BOOKPART "\\bookpart"
250 %token CHANGE "\\change"
251 %token CHORDMODE "\\chordmode"
252 %token CHORDS "\\chords"
253 %token CONSISTS "\\consists"
254 %token CONTEXT "\\context"
255 %token DEFAULT "\\default"
256 %token DEFAULTCHILD "\\defaultchild"
257 %token DENIES "\\denies"
258 %token DESCRIPTION "\\description"
259 %token DRUMMODE "\\drummode"
260 %token DRUMS "\\drums"
261 %token FIGUREMODE "\\figuremode"
262 %token FIGURES "\\figures"
263 %token HEADER "\\header"
264 %token INVALID "\\version-error"
265 %token LAYOUT "\\layout"
266 %token LYRICMODE "\\lyricmode"
267 %token LYRICS "\\lyrics"
268 %token LYRICSTO "\\lyricsto"
269 %token MARKUP "\\markup"
270 %token MARKUPLIST "\\markuplist"
273 %token NOTEMODE "\\notemode"
274 %token OVERRIDE "\\override"
275 %token PAPER "\\paper"
276 %token REMOVE "\\remove"
277 %token REPEAT "\\repeat"
279 %token REVERT "\\revert"
280 %token SCORE "\\score"
281 %token SEQUENTIAL "\\sequential"
283 %token SIMULTANEOUS "\\simultaneous"
284 %token TEMPO "\\tempo"
286 %token UNSET "\\unset"
289 /* Keyword token exceptions. */
290 %token NEWCONTEXT "\\new"
293 /* Other string tokens. */
295 %token CHORD_BASS "/+"
296 %token CHORD_CARET "^"
297 %token CHORD_COLON ":"
298 %token CHORD_MINUS "-"
299 %token CHORD_SLASH "/"
300 %token ANGLE_OPEN "<"
301 %token ANGLE_CLOSE ">"
302 %token DOUBLE_ANGLE_OPEN "<<"
303 %token DOUBLE_ANGLE_CLOSE ">>"
304 %token E_BACKSLASH "\\"
305 %token E_ANGLE_CLOSE "\\>"
306 %token E_CHAR "\\C[haracter]"
308 %token E_EXCLAMATION "\\!"
309 %token E_BRACKET_OPEN "\\["
311 %token E_BRACKET_CLOSE "\\]"
312 %token E_ANGLE_OPEN "\\<"
318 If we give names, Bison complains.
320 %token FIGURE_CLOSE /* "\\>" */
321 %token FIGURE_OPEN /* "\\<" */
322 %token FIGURE_SPACE "_"
325 %token CHORDMODIFIERS
327 %token MULTI_MEASURE_REST
330 %token <i> E_UNSIGNED
331 %token <scm> UNSIGNED
333 /* Artificial tokens, for more generic function syntax */
334 %token <i> EXPECT_MARKUP "markup?"
335 %token <i> EXPECT_PITCH "ly:pitch?"
336 %token <i> EXPECT_DURATION "ly:duration?"
337 %token <scm> EXPECT_SCM "scheme?"
338 %token <scm> BACKUP "(backed-up?)"
339 %token <scm> REPARSE "(reparsed?)"
340 %token <i> EXPECT_MARKUP_LIST "markup-list?"
341 %token <scm> EXPECT_OPTIONAL "optional?"
342 /* After the last argument. */
343 %token <i> EXPECT_NO_MORE_ARGS;
345 /* An artificial token for parsing embedded Lilypond */
346 %token <i> EMBEDDED_LILY "#{"
348 %token <scm> BOOK_IDENTIFIER
349 %token <scm> CHORDMODIFIER_PITCH
350 %token <scm> CHORD_MODIFIER
351 %token <scm> CHORD_REPETITION
352 %token <scm> CONTEXT_DEF_IDENTIFIER
353 %token <scm> CONTEXT_MOD_IDENTIFIER
354 %token <scm> DRUM_PITCH
355 %token <scm> PITCH_IDENTIFIER
356 %token <scm> DURATION_IDENTIFIER
357 %token <scm> EVENT_IDENTIFIER
358 %token <scm> EVENT_FUNCTION
359 %token <scm> FRACTION
360 %token <scm> LYRICS_STRING
361 %token <scm> LYRIC_ELEMENT
362 %token <scm> LYRIC_MARKUP_IDENTIFIER
363 %token <scm> MARKUP_FUNCTION
364 %token <scm> MARKUP_LIST_FUNCTION
365 %token <scm> MARKUP_IDENTIFIER
366 %token <scm> MARKUPLIST_IDENTIFIER
367 %token <scm> MUSIC_FUNCTION
368 %token <scm> MUSIC_IDENTIFIER
369 %token <scm> NOTENAME_PITCH
370 %token <scm> NUMBER_IDENTIFIER
371 %token <scm> OUTPUT_DEF_IDENTIFIER
373 %token <scm> RESTNAME
374 %token <scm> SCM_FUNCTION
375 %token <scm> SCM_IDENTIFIER
376 %token <scm> SCM_TOKEN
377 %token <scm> SCORE_IDENTIFIER
379 %token <scm> STRING_IDENTIFIER
380 %token <scm> TONICNAME_PITCH
383 %type <book> book_block
384 %type <book> book_body
385 %type <book> bookpart_block
386 %type <book> bookpart_body
388 %type <i> bare_unsigned
389 %type <scm> figured_bass_alteration
391 %type <i> exclamations
392 %type <i> optional_rest
397 %type <i> tremolo_type
400 %type <scm> composite_music
401 %type <scm> grouped_music_list
402 %type <scm> braced_music_list
403 %type <scm> closed_music
405 %type <scm> music_bare
406 %type <scm> music_arg
407 %type <scm> music_assign
408 %type <scm> complex_music
409 %type <scm> complex_music_prefix
410 %type <scm> mode_changed_music
411 %type <scm> repeated_music
412 %type <scm> sequential_music
413 %type <scm> simple_music
414 %type <scm> simultaneous_music
415 %type <scm> chord_body
416 %type <scm> chord_body_element
417 %type <scm> command_element
418 %type <scm> command_event
419 %type <scm> context_modification
420 %type <scm> context_change
421 %type <scm> direction_less_event
422 %type <scm> direction_reqd_event
423 %type <scm> embedded_lilypond
424 %type <scm> event_chord
425 %type <scm> fingering
426 %type <scm> gen_text_def
427 %type <scm> music_property_def
428 %type <scm> note_chord_element
429 %type <scm> post_event
430 %type <scm> post_event_nofinger
431 %type <scm> re_rhythmed_music
432 %type <scm> simple_element
433 %type <scm> simple_music_property_def
434 %type <scm> start_symbol
435 %type <scm> string_number_event
436 %type <scm> tempo_event
438 %type <outputdef> output_def_body
439 %type <outputdef> output_def_head
440 %type <outputdef> output_def_head_with_mode_switch
441 %type <outputdef> output_def
442 %type <outputdef> paper_block
444 %type <scm> music_function_call
445 %type <scm> music_list
446 %type <scm> assignment_id
447 %type <scm> bare_number
448 %type <scm> bare_number_closed
449 %type <scm> unsigned_number
450 %type <scm> bass_figure
451 %type <scm> figured_bass_modification
452 %type <scm> br_bass_figure
453 %type <scm> bass_number
454 %type <scm> chord_body_elements
455 %type <scm> chord_item
456 %type <scm> chord_items
457 %type <scm> chord_separator
458 %type <scm> context_def_mod
459 %type <scm> context_def_spec_block
460 %type <scm> context_def_spec_body
461 %type <scm> context_mod
462 %type <scm> context_mod_list
463 %type <scm> context_prop_spec
464 %type <scm> direction_less_char
465 %type <scm> duration_length
466 %type <scm> embedded_scm
467 %type <scm> embedded_scm_arg
468 %type <scm> embedded_scm_arg_closed
469 %type <scm> embedded_scm_bare
470 %type <scm> embedded_scm_bare_arg
471 %type <scm> embedded_scm_closed
472 %type <scm> event_function_event
473 %type <scm> figure_list
474 %type <scm> figure_spec
476 %type <scm> full_markup
477 %type <scm> full_markup_list
478 %type <scm> function_arglist
479 %type <scm> function_arglist_optional
480 %type <scm> function_arglist_backup
481 %type <scm> function_arglist_nonbackup
482 %type <scm> function_arglist_skip
483 %type <scm> function_arglist_bare
484 %type <scm> function_arglist_closed
485 %type <scm> function_arglist_closed_optional
486 %type <scm> function_arglist_common
487 %type <scm> function_arglist_common_lyric
488 %type <scm> function_arglist_common_minus
489 %type <scm> function_arglist_closed_common
490 %type <scm> function_arglist_keep
491 %type <scm> function_arglist_closed_keep
492 %type <scm> identifier_init
494 %type <scm> lilypond_header
495 %type <scm> lilypond_header_body
496 %type <scm> lyric_element
497 %type <scm> lyric_element_arg
498 %type <scm> lyric_element_music
499 %type <scm> lyric_markup
501 %type <scm> markup_braced_list
502 %type <scm> markup_braced_list_body
503 %type <scm> markup_composed_list
504 %type <scm> markup_command_list
505 %type <scm> markup_command_list_arguments
506 %type <scm> markup_command_basic_arguments
507 %type <scm> markup_head_1_item
508 %type <scm> markup_head_1_list
509 %type <scm> markup_list
510 %type <scm> markup_top
511 %type <scm> maybe_notemode_duration
512 %type <scm> mode_changing_head
513 %type <scm> mode_changing_head_with_context
514 %type <scm> multiplied_duration
515 %type <scm> music_function_event
516 %type <scm> music_function_chord_body
517 %type <scm> new_chord
518 %type <scm> new_lyrics
519 %type <scm> number_expression
520 %type <scm> number_factor
521 %type <scm> number_term
522 %type <scm> octave_check
523 %type <scm> optional_context_mod
524 %type <scm> optional_id
525 %type <scm> optional_notemode_duration
527 %type <scm> pitch_also_in_chords
528 %type <scm> post_events
529 %type <scm> property_operation
530 %type <scm> property_path property_path_revved
532 %type <scm> scalar_closed
533 %type <scm> scm_function_call
534 %type <scm> scm_function_call_closed
535 %type <scm> script_abbreviation
536 %type <scm> simple_chord_elements
537 %type <scm> simple_markup
538 %type <scm> simple_string
539 %type <scm> steno_duration
540 %type <scm> steno_pitch
541 %type <scm> steno_tonic_pitch
542 %type <scm> step_number
543 %type <scm> step_numbers
545 %type <scm> tempo_range
547 %type <score> score_block
548 %type <score> score_body
553 /* We don't assign precedence to / and *, because we might need varied
554 prec levels in different prods */
563 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
564 parser->lexer_->push_note_state (alist_to_hashq (nn));
565 } embedded_lilypond {
566 parser->lexer_->pop_state ();
567 parser->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
571 lilypond: /* empty */ { }
572 | lilypond toplevel_expression {
574 | lilypond assignment {
577 parser->error_level_ = 1;
580 parser->error_level_ = 1;
587 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
591 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
592 scm_call_2 (proc, parser->self_scm (), book->self_scm ());
597 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
598 scm_call_2 (proc, parser->self_scm (), bookpart->self_scm ());
599 bookpart->unprotect ();
604 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
605 scm_call_2 (proc, parser->self_scm (), score->self_scm ());
609 Music *music = unsmob_music ($1);
610 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
611 scm_call_2 (proc, parser->self_scm (), music->self_scm ());
614 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
615 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
618 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
619 scm_call_2 (proc, parser->self_scm (), $1);
623 Output_def * od = $1;
625 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
626 id = ly_symbol2scm ("$defaultpaper");
627 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
628 id = ly_symbol2scm ("$defaultmidi");
629 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
630 id = ly_symbol2scm ("$defaultlayout");
632 parser->lexer_->set_identifier (id, od->self_scm ());
640 $$ = parser->lexer_->eval_scm ($1);
645 embedded_scm_bare_arg:
651 | context_modification
654 $$ = $1->self_scm ();
657 | context_def_spec_block
660 $$ = $1->self_scm ();
665 $$ = $1->self_scm ();
670 $$ = $1->self_scm ();
675 /* The generic version may end in music, or not */
683 embedded_scm_bare_arg
689 SCM_FUNCTION function_arglist {
690 $$ = MAKE_SYNTAX ("music-function", @$,
698 $$ = MAKE_SYNTAX ("void-music", @$);
701 | music music music_list {
702 $$ = MAKE_SYNTAX ("sequential-music", @$,
703 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
706 parser->error_level_ = 1;
708 | INVALID embedded_lilypond {
709 parser->error_level_ = 1;
714 lilypond_header_body:
716 $$ = get_header (parser);
717 parser->lexer_->add_scope ($$);
719 | lilypond_header_body assignment {
725 HEADER '{' lilypond_header_body '}' {
726 $$ = parser->lexer_->remove_scope ();
735 | LYRICS_STRING { $$ = $1; }
739 assignment_id '=' identifier_init {
740 parser->lexer_->set_identifier ($1, $3);
742 | assignment_id property_path '=' identifier_init {
743 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
744 parser->lexer_->set_identifier (path, $4);
747 TODO: devise standard for protection in parser.
749 The parser stack lives on the C-stack, which means that
750 all objects can be unprotected as soon as they're here.
760 $$ = $1->self_scm ();
764 $$ = $1->self_scm ();
768 $$ = $1->self_scm ();
772 $$ = $1->self_scm ();
775 | context_def_spec_block {
781 | post_event_nofinger {
784 | number_expression {
799 | context_modification {
804 context_def_spec_block:
805 CONTEXT '{' context_def_spec_body '}'
811 context_def_spec_body:
813 $$ = Context_def::make_scm ();
814 unsmob_context_def ($$)->origin ()->set_spot (@$);
816 | CONTEXT_DEF_IDENTIFIER {
818 unsmob_context_def ($$)->origin ()->set_spot (@$);
820 | context_def_spec_body embedded_scm {
821 if (Context_mod *cm = unsmob_context_mod ($2)) {
822 SCM p = cm->get_mods ();
823 Context_def*td = unsmob_context_def ($$);
825 for (; scm_is_pair (p); p = scm_cdr (p)) {
826 td->add_context_mod (scm_car (p));
829 parser->parser_error (@2, _ ("not a context mod"));
832 | context_def_spec_body context_mod {
833 unsmob_context_def ($$)->add_context_mod ($2);
835 | context_def_spec_body context_modification {
836 Context_def *td = unsmob_context_def ($$);
837 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
838 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
839 td->add_context_mod (scm_car (m));
847 BOOK '{' book_body '}' {
850 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
855 * Use 'handlers' like for toplevel-* stuff?
856 * grok \layout and \midi? */
860 init_papers (parser);
861 $$->origin ()->set_spot (@$);
862 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
863 $$->paper_->unprotect ();
864 push_paper (parser, $$->paper_);
865 $$->header_ = parser->lexer_->lookup_identifier ("$defaultheader");
866 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
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
1136 if (unsmob_pitch ($1)) {
1137 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
1138 n->set_property ("pitch", $1);
1139 n->set_property ("duration",
1140 parser->default_duration_.smobbed_copy ());
1141 $$ = n->unprotect ();
1144 | composite_music %prec COMPOSITE
1149 | composite_music %prec COMPOSITE
1150 | lyric_element_music
1154 REPEAT simple_string unsigned_number music
1156 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1158 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1160 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1165 SEQUENTIAL braced_music_list {
1166 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1168 | braced_music_list {
1169 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1174 SIMULTANEOUS braced_music_list {
1175 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1177 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1178 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1184 | music_property_def
1188 context_modification:
1189 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1191 parser->lexer_->pop_state ();
1194 | WITH CONTEXT_MOD_IDENTIFIER
1198 | CONTEXT_MOD_IDENTIFIER
1202 | WITH embedded_scm_closed
1204 if (unsmob_context_mod ($2))
1207 parser->parser_error (@2, _ ("not a context mod"));
1208 $$ = Context_mod ().smobbed_copy ();
1213 optional_context_mod:
1217 | context_modification
1225 $$ = Context_mod ().smobbed_copy ();
1227 | context_mod_list context_mod {
1228 unsmob_context_mod ($1)->add_context_mod ($2);
1230 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1231 Context_mod *md = unsmob_context_mod ($2);
1233 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1235 | context_mod_list embedded_scm {
1236 Context_mod *md = unsmob_context_mod ($2);
1238 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1240 parser->parser_error (@2, _ ("not a context mod"));
1249 /* Music that can be parsed without lookahead */
1252 | complex_music_prefix closed_music
1254 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1261 | grouped_music_list
1265 simultaneous_music { $$ = $1; }
1266 | sequential_music { $$ = $1; }
1269 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1270 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1271 and this rule returns the reversed list of arguments. */
1273 function_arglist_skip:
1274 function_arglist_common
1275 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1277 $$ = scm_cons ($1, $3);
1278 } %prec FUNCTION_ARGLIST
1279 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1281 $$ = scm_cons ($1, $3);
1282 } %prec FUNCTION_ARGLIST
1283 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1285 $$ = scm_cons ($1, $3);
1286 } %prec FUNCTION_ARGLIST
1290 function_arglist_nonbackup:
1291 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1292 $$ = scm_cons ($4, $3);
1294 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1295 $$ = scm_cons ($4, $3);
1297 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1299 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1301 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1303 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1305 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1307 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1309 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1311 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1313 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1315 SCM n = scm_difference ($5, SCM_UNDEFINED);
1316 if (scm_is_true (scm_call_1 ($2, n)))
1317 $$ = scm_cons (n, $3);
1319 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1320 t->set_property ("digit", $5);
1321 $$ = t->unprotect ();
1322 if (scm_is_true (scm_call_1 ($2, $$)))
1323 $$ = scm_cons ($$, $3);
1325 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1329 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1331 $$ = check_scheme_arg (parser, @4,
1332 scm_difference ($5, SCM_UNDEFINED),
1335 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1337 $$ = check_scheme_arg (parser, @4,
1338 scm_difference ($5, SCM_UNDEFINED),
1344 function_arglist_keep:
1345 function_arglist_common
1346 | function_arglist_backup
1349 function_arglist_closed_keep:
1350 function_arglist_closed_common
1351 | function_arglist_backup
1354 function_arglist_backup:
1355 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1357 if (scm_is_true (scm_call_1 ($2, $4)))
1359 $$ = scm_cons ($4, $3);
1361 $$ = scm_cons (loc_on_music (@3, $1), $3);
1362 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1365 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1367 if (scm_is_true (scm_call_1 ($2, $4)))
1369 $$ = scm_cons ($4, $3);
1371 $$ = scm_cons (loc_on_music (@3, $1), $3);
1372 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1375 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1377 // There is no point interpreting a lyrics string as
1378 // an event, since we don't allow music possibly
1379 // followed by durations or postevent into closed
1380 // music, and we only accept closed music in optional
1381 // arguments at the moment. If this changes, more
1382 // complex schemes might become interesting here as
1383 // well: see how we do this at the mandatory argument
1385 if (scm_is_true (scm_call_1 ($2, $4)))
1386 $$ = scm_cons ($4, $3);
1388 $$ = scm_cons (loc_on_music (@3, $1), $3);
1389 MYBACKUP (LYRICS_STRING, $4, @4);
1392 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1394 if (scm_is_true (scm_call_1 ($2, $4)))
1397 MYREPARSE (@4, $2, UNSIGNED, $4);
1399 $$ = scm_cons (loc_on_music (@3, $1), $3);
1400 MYBACKUP (UNSIGNED, $4, @4);
1403 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1405 if (scm_is_true (scm_call_1 ($2, $4)))
1408 MYREPARSE (@4, $2, REAL, $4);
1410 $$ = scm_cons (loc_on_music (@3, $1), $3);
1411 MYBACKUP (REAL, $4, @4);
1414 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1416 if (scm_is_true (scm_call_1 ($2, $4)))
1418 $$ = scm_cons ($4, $3);
1420 $$ = scm_cons (loc_on_music (@3, $1), $3);
1421 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1424 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1426 if (scm_is_true (scm_call_1 ($2, $4)))
1428 $$ = scm_cons ($4, $3);
1430 $$ = scm_cons (loc_on_music (@3, $1), $3);
1431 MYBACKUP (FRACTION, $4, @4);
1434 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1436 SCM n = scm_difference ($5, SCM_UNDEFINED);
1437 if (scm_is_true (scm_call_1 ($2, n))) {
1439 MYREPARSE (@5, $2, REAL, n);
1441 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1442 t->set_property ("digit", $5);
1443 $$ = t->unprotect ();
1444 if (scm_is_true (scm_call_1 ($2, $$)))
1445 $$ = scm_cons ($$, $3);
1447 $$ = scm_cons (loc_on_music (@3, $1), $3);
1448 MYBACKUP (UNSIGNED, $5, @5);
1449 parser->lexer_->push_extra_token ('-');
1454 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1456 SCM n = scm_difference ($5, SCM_UNDEFINED);
1457 if (scm_is_true (scm_call_1 ($2, n))) {
1458 MYREPARSE (@5, $2, REAL, n);
1461 MYBACKUP (REAL, n, @5);
1464 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1466 SCM n = scm_difference ($5, SCM_UNDEFINED);
1467 if (scm_is_true (scm_call_1 ($2, n))) {
1468 $$ = scm_cons (n, $3);
1470 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1473 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1475 $$ = scm_cons ($4, $3);
1477 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1479 $$ = scm_cons ($4, $3);
1481 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1483 $$ = scm_cons ($1, $3);
1484 MYBACKUP(0, SCM_UNDEFINED, @3);
1486 | function_arglist_backup REPARSE embedded_scm_arg_closed
1488 $$ = check_scheme_arg (parser, @3,
1491 | function_arglist_backup REPARSE bare_number
1493 $$ = check_scheme_arg (parser, @3,
1496 | function_arglist_backup REPARSE fraction
1498 $$ = check_scheme_arg (parser, @3,
1504 function_arglist_common
1505 | function_arglist_nonbackup
1508 function_arglist_common:
1509 function_arglist_bare
1510 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1512 $$ = check_scheme_arg (parser, @3,
1515 | EXPECT_SCM function_arglist_closed_optional bare_number
1517 $$ = check_scheme_arg (parser, @3,
1520 | EXPECT_SCM function_arglist_closed_optional fraction
1522 $$ = check_scheme_arg (parser, @3,
1525 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1527 $$ = check_scheme_arg (parser, @3,
1530 | function_arglist_common_minus
1531 | function_arglist_common_lyric
1534 function_arglist_common_lyric:
1535 EXPECT_SCM function_arglist_optional lyric_element
1537 // We check how the predicate thinks about a lyrics
1538 // event or about a markup. If it accepts neither, we
1539 // backup the original token. Otherwise we commit to
1540 // taking the token. Depending on what the predicate
1541 // is willing to accept, we interpret as a string, as
1542 // a lyric event, or ambiguously (meaning that if
1543 // something looking like a duration or post event
1544 // follows, we take the event, otherwise the string).
1545 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1546 parser->default_duration_.smobbed_copy ());
1547 if (scm_is_true (scm_call_1 ($1, $3)))
1548 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1551 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1553 $$ = scm_cons ($3, $2);
1555 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1558 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1560 // This is going to flag a syntax error, we
1561 // know the predicate to be false.
1562 check_scheme_arg (parser, @3,
1566 | function_arglist_common_lyric REPARSE lyric_element_arg
1568 // This should never be false
1569 $$ = check_scheme_arg (parser, @3,
1574 function_arglist_common_minus:
1575 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1577 SCM n = scm_difference ($4, SCM_UNDEFINED);
1578 if (scm_is_true (scm_call_1 ($1, n))) {
1580 MYREPARSE (@4, $1, REAL, n);
1582 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1583 t->set_property ("digit", $4);
1584 $$ = t->unprotect ();
1585 if (scm_is_true (scm_call_1 ($1, $$)))
1586 $$ = scm_cons ($$, $2);
1588 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1592 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1595 SCM n = scm_difference ($4, SCM_UNDEFINED);
1596 MYREPARSE (@4, $1, REAL, n);
1598 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1600 SCM n = scm_difference ($4, SCM_UNDEFINED);
1601 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1603 | function_arglist_common_minus REPARSE bare_number
1605 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1609 function_arglist_closed:
1610 function_arglist_closed_common
1611 | function_arglist_nonbackup
1614 function_arglist_closed_common:
1615 function_arglist_bare
1616 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1618 $$ = check_scheme_arg (parser, @3,
1621 | EXPECT_SCM function_arglist_closed_optional bare_number
1623 $$ = check_scheme_arg (parser, @3,
1626 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1628 SCM n = scm_difference ($4, SCM_UNDEFINED);
1629 if (scm_is_true (scm_call_1 ($1, n))) {
1630 $$ = scm_cons (n, $2);
1632 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1633 t->set_property ("digit", $4);
1634 $$ = t->unprotect ();
1635 if (scm_is_true (scm_call_1 ($1, $$)))
1636 $$ = scm_cons ($$, $2);
1638 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1642 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1644 $$ = check_scheme_arg (parser, @3,
1645 scm_difference ($4, SCM_UNDEFINED),
1648 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1650 $$ = check_scheme_arg (parser, @3,
1651 scm_difference ($4, SCM_UNDEFINED),
1654 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1656 $$ = check_scheme_arg (parser, @3,
1659 | EXPECT_SCM function_arglist_closed_optional fraction
1661 $$ = check_scheme_arg (parser, @3,
1664 | EXPECT_SCM function_arglist_optional lyric_element
1666 $$ = check_scheme_arg (parser, @3,
1671 function_arglist_optional:
1672 function_arglist_keep %prec FUNCTION_ARGLIST
1673 | function_arglist_backup BACKUP
1674 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1676 $$ = scm_cons ($1, $3);
1678 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1680 $$ = scm_cons ($1, $3);
1684 function_arglist_closed_optional:
1685 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1686 | function_arglist_backup BACKUP
1687 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1689 $$ = scm_cons ($1, $3);
1691 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1693 $$ = scm_cons ($1, $3);
1697 embedded_scm_closed:
1699 | scm_function_call_closed
1702 embedded_scm_arg_closed:
1703 embedded_scm_bare_arg
1704 | scm_function_call_closed
1708 scm_function_call_closed:
1709 SCM_FUNCTION function_arglist_closed {
1710 $$ = MAKE_SYNTAX ("music-function", @$,
1712 } %prec FUNCTION_ARGLIST
1715 function_arglist_bare:
1716 EXPECT_NO_MORE_ARGS {
1719 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1720 $$ = scm_cons ($3, $2);
1722 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1723 $$ = scm_cons ($3, $2);
1725 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1726 $$ = scm_cons ($1, $3);
1728 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1729 $$ = scm_cons ($1, $3);
1731 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1732 $$ = scm_cons ($1, $3);
1736 music_function_call:
1737 MUSIC_FUNCTION function_arglist {
1738 $$ = MAKE_SYNTAX ("music-function", @$,
1745 /**/ { $$ = SCM_EOL; }
1746 | '=' simple_string {
1753 | repeated_music { $$ = $1; }
1754 | re_rhythmed_music { $$ = $1; }
1755 | complex_music_prefix music
1757 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1761 complex_music_prefix:
1762 CONTEXT simple_string optional_id optional_context_mod {
1763 Context_mod *ctxmod = unsmob_context_mod ($4);
1766 mods = ctxmod->get_mods ();
1767 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1769 | NEWCONTEXT simple_string optional_id optional_context_mod {
1770 Context_mod *ctxmod = unsmob_context_mod ($4);
1773 mods = ctxmod->get_mods ();
1774 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1779 mode_changing_head grouped_music_list {
1780 if ($1 == ly_symbol2scm ("chords"))
1782 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1788 parser->lexer_->pop_state ();
1790 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1791 Context_mod *ctxmod = unsmob_context_mod ($2);
1794 mods = ctxmod->get_mods ();
1795 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1796 if ($1 == ly_symbol2scm ("ChordNames"))
1798 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1800 parser->lexer_->pop_state ();
1806 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1807 parser->lexer_->push_note_state (alist_to_hashq (nn));
1809 $$ = ly_symbol2scm ("notes");
1813 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1814 parser->lexer_->push_note_state (alist_to_hashq (nn));
1816 $$ = ly_symbol2scm ("drums");
1819 parser->lexer_->push_figuredbass_state ();
1821 $$ = ly_symbol2scm ("figures");
1824 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1825 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1826 nn = parser->lexer_->lookup_identifier ("pitchnames");
1827 parser->lexer_->push_chord_state (alist_to_hashq (nn));
1828 $$ = ly_symbol2scm ("chords");
1832 { parser->lexer_->push_lyric_state ();
1833 $$ = ly_symbol2scm ("lyrics");
1837 mode_changing_head_with_context:
1839 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1840 parser->lexer_->push_note_state (alist_to_hashq (nn));
1842 $$ = ly_symbol2scm ("DrumStaff");
1845 parser->lexer_->push_figuredbass_state ();
1847 $$ = ly_symbol2scm ("FiguredBass");
1850 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1851 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1852 nn = parser->lexer_->lookup_identifier ("pitchnames");
1853 parser->lexer_->push_chord_state (alist_to_hashq (nn));
1854 $$ = ly_symbol2scm ("ChordNames");
1857 { parser->lexer_->push_lyric_state ();
1858 $$ = ly_symbol2scm ("Lyrics");
1863 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1866 /* Can also use music at the expensive of two S/Rs similar to
1867 \repeat \alternative */
1868 parser->lexer_->pop_state ();
1870 $$ = scm_cons ($3, SCM_EOL);
1872 | new_lyrics ADDLYRICS {
1873 parser->lexer_->push_lyric_state ();
1875 parser->lexer_->pop_state ();
1876 $$ = scm_cons ($4, $1);
1881 composite_music new_lyrics {
1882 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1884 | LYRICSTO simple_string {
1885 parser->lexer_->push_lyric_state ();
1887 parser->lexer_->pop_state ();
1888 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1893 CHANGE STRING '=' STRING {
1894 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1899 property_path_revved:
1900 embedded_scm_closed {
1901 $$ = scm_cons ($1, SCM_EOL);
1903 | property_path_revved embedded_scm_closed {
1904 $$ = scm_cons ($2, $1);
1909 property_path_revved {
1910 $$ = scm_reverse_x ($1, SCM_EOL);
1916 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1917 scm_string_to_symbol ($1), $3);
1919 | UNSET simple_string {
1920 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1921 scm_string_to_symbol ($2));
1923 | OVERRIDE simple_string property_path '=' scalar {
1924 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1925 scm_string_to_symbol ($2), $5),
1928 | REVERT simple_string embedded_scm {
1929 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1930 scm_string_to_symbol ($2), $3);
1935 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1936 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1938 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1939 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1940 | DENIES { $$ = ly_symbol2scm ("denies"); }
1942 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1943 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1944 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1945 | NAME { $$ = ly_symbol2scm ("context-name"); }
1949 property_operation { $$ = $1; }
1950 | context_def_mod STRING {
1951 $$ = scm_list_2 ($1, $2);
1953 | context_def_mod embedded_scm
1955 if (!scm_is_string ($2)
1956 && ly_symbol2scm ("consists") != $1
1957 && ly_symbol2scm ("remove") != $1)
1960 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
1964 $$ = scm_list_2 ($1, $2);
1971 if (!is_regular_identifier ($1))
1973 @$.error (_("Grob name should be alphanumeric"));
1976 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1977 scm_string_to_symbol ($1));
1979 | simple_string '.' simple_string {
1980 $$ = scm_list_2 (scm_string_to_symbol ($1),
1981 scm_string_to_symbol ($3));
1985 simple_music_property_def:
1986 OVERRIDE context_prop_spec property_path '=' scalar {
1987 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1988 ly_symbol2scm ("OverrideProperty"),
1993 | REVERT context_prop_spec embedded_scm {
1994 $$ = scm_list_4 (scm_car ($2),
1995 ly_symbol2scm ("RevertProperty"),
1999 | SET context_prop_spec '=' scalar {
2000 $$ = scm_list_4 (scm_car ($2),
2001 ly_symbol2scm ("PropertySet"),
2005 | UNSET context_prop_spec {
2006 $$ = scm_list_3 (scm_car ($2),
2007 ly_symbol2scm ("PropertyUnset"),
2013 simple_music_property_def {
2014 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2022 | STRING_IDENTIFIER {
2025 | string '+' string {
2026 $$ = scm_string_append (scm_list_2 ($1, $3));
2030 simple_string: STRING {
2036 | STRING_IDENTIFIER {
2048 embedded_scm_arg_closed
2055 simple_element post_events {
2056 // Let the rhythmic music iterator sort this mess out.
2057 if (scm_is_pair ($2)) {
2058 if (unsmob_pitch ($1)) {
2059 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
2060 n->set_property ("pitch", $1);
2061 n->set_property ("duration",
2062 parser->default_duration_.smobbed_copy ());
2063 $$ = n->unprotect ();
2065 unsmob_music ($$)->set_property ("articulations",
2066 scm_reverse_x ($2, SCM_EOL));
2069 | simple_chord_elements post_events {
2070 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2073 /* why is this giving wrong start location? -ns
2075 i.set_location (@1, @2);
2076 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2078 | CHORD_REPETITION optional_notemode_duration post_events {
2080 i.set_location (@1, @3);
2081 $$ = MAKE_SYNTAX ("repetition-chord", i,
2082 $2, scm_reverse_x ($3, SCM_EOL));
2084 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2086 i.set_location (@1, @3);
2087 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2088 scm_reverse_x ($3, SCM_EOL));
2091 | note_chord_element
2096 chord_body optional_notemode_duration post_events
2098 Music *m = unsmob_music ($1);
2099 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2100 SCM es = m->get_property ("elements");
2101 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2103 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2104 unsmob_music (scm_car (s))->set_property ("duration", dur);
2105 es = ly_append2 (es, postevs);
2107 m-> set_property ("elements", es);
2109 $$ = m->self_scm ();
2114 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2116 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2120 chord_body_elements:
2121 /* empty */ { $$ = SCM_EOL; }
2122 | chord_body_elements chord_body_element {
2123 if (!SCM_UNBNDP ($2))
2124 $$ = scm_cons ($2, $1);
2129 pitch exclamations questions octave_check post_events
2136 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2137 n->set_property ("pitch", $1);
2139 n->set_property ("cautionary", SCM_BOOL_T);
2140 if (ex % 2 || q % 2)
2141 n->set_property ("force-accidental", SCM_BOOL_T);
2143 if (scm_is_pair (post)) {
2144 SCM arts = scm_reverse_x (post, SCM_EOL);
2145 n->set_property ("articulations", arts);
2147 if (scm_is_number (check))
2149 int q = scm_to_int (check);
2150 n->set_property ("absolute-octave", scm_from_int (q-1));
2153 $$ = n->unprotect ();
2155 | DRUM_PITCH post_events {
2156 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2157 n->set_property ("drum-type", $1);
2159 if (scm_is_pair ($2)) {
2160 SCM arts = scm_reverse_x ($2, SCM_EOL);
2161 n->set_property ("articulations", arts);
2163 $$ = n->unprotect ();
2165 | music_function_chord_body
2167 Music *m = unsmob_music ($1);
2169 while (m && m->is_mus_type ("music-wrapper-music")) {
2170 $$ = m->get_property ("element");
2171 m = unsmob_music ($$);
2174 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2175 parser->parser_error (@$, _ ("not a rhythmic event"));
2181 music_function_chord_body:
2186 // Event functions may only take closed arglists, otherwise it would
2187 // not be clear whether a following postevent should be associated
2188 // with the last argument of the event function or with the expression
2189 // for which the function call acts itself as event.
2191 music_function_event:
2192 MUSIC_FUNCTION function_arglist_closed {
2193 $$ = MAKE_SYNTAX ("music-function", @$,
2198 event_function_event:
2199 EVENT_FUNCTION function_arglist_closed {
2200 $$ = MAKE_SYNTAX ("music-function", @$,
2210 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2211 m->set_property ("span-direction", scm_from_int (START));
2212 $$ = m->unprotect();
2215 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2216 m->set_property ("span-direction", scm_from_int (STOP));
2217 $$ = m->unprotect ();
2220 $$ = MAKE_SYNTAX ("voice-separator", @$);
2223 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2225 Music *m = unsmob_music (pipe);
2230 $$ = m->unprotect ();
2233 $$ = MAKE_SYNTAX ("bar-check", @$);
2240 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2252 | post_events post_event {
2253 unsmob_music ($2)->set_spot (@2);
2254 $$ = scm_cons ($2, $$);
2258 post_event_nofinger:
2259 direction_less_event {
2262 | script_dir music_function_event {
2266 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2270 if (!parser->lexer_->is_lyric_state ())
2271 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2272 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2275 if (!parser->lexer_->is_lyric_state ())
2276 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2277 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2279 | script_dir direction_reqd_event {
2282 Music *m = unsmob_music ($2);
2283 m->set_property ("direction", scm_from_int ($1));
2287 | script_dir direction_less_event {
2290 Music *m = unsmob_music ($2);
2291 m->set_property ("direction", scm_from_int ($1));
2295 | string_number_event
2299 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2304 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2315 string_number_event:
2317 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2318 s->set_property ("string-number", scm_from_int ($1));
2319 $$ = s->unprotect ();
2323 direction_less_char:
2325 $$ = ly_symbol2scm ("bracketOpenSymbol");
2328 $$ = ly_symbol2scm ("bracketCloseSymbol");
2331 $$ = ly_symbol2scm ("tildeSymbol");
2334 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2337 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2340 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2343 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2346 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2349 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2352 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2356 direction_less_event:
2357 direction_less_char {
2358 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2360 if (unsmob_music (predefd))
2362 m = unsmob_music (predefd)->clone ();
2367 m = MY_MAKE_MUSIC ("Music", @$);
2369 $$ = m->unprotect ();
2371 | EVENT_IDENTIFIER {
2375 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2376 a->set_property ("tremolo-type", scm_from_int ($1));
2377 $$ = a->unprotect ();
2379 | event_function_event
2382 direction_reqd_event:
2386 | script_abbreviation {
2387 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2388 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2389 if (scm_is_string (s))
2390 a->set_property ("articulation-type", s);
2391 else parser->parser_error (@1, _ ("expecting string as script definition"));
2392 $$ = a->unprotect ();
2397 /**/ { $$ = SCM_EOL; }
2398 | '=' { $$ = scm_from_int (0); }
2399 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2400 | '=' sup_quotes { $$ = scm_from_int ($2); }
2425 | NOTENAME_PITCH sup_quotes {
2426 Pitch p = *unsmob_pitch ($1);
2427 p = p.transposed (Pitch ($2,0,0));
2428 $$ = p.smobbed_copy ();
2430 | NOTENAME_PITCH sub_quotes {
2431 Pitch p =* unsmob_pitch ($1);
2432 p = p.transposed (Pitch (-$2,0,0));
2433 $$ = p.smobbed_copy ();
2445 | TONICNAME_PITCH sup_quotes {
2446 Pitch p = *unsmob_pitch ($1);
2447 p = p.transposed (Pitch ($2,0,0));
2448 $$ = p.smobbed_copy ();
2450 | TONICNAME_PITCH sub_quotes {
2451 Pitch p = *unsmob_pitch ($1);
2453 p = p.transposed (Pitch (-$2,0,0));
2454 $$ = p.smobbed_copy ();
2465 pitch_also_in_chords:
2472 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2473 t->set_property ("text", $1);
2474 $$ = t->unprotect ();
2477 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2478 t->set_property ("text",
2479 make_simple_markup ($1));
2480 $$ = t->unprotect ();
2486 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2487 t->set_property ("digit", $1);
2488 $$ = t->unprotect ();
2492 script_abbreviation:
2494 $$ = scm_from_locale_string ("Hat");
2497 $$ = scm_from_locale_string ("Plus");
2500 $$ = scm_from_locale_string ("Dash");
2503 $$ = scm_from_locale_string ("Bar");
2506 $$ = scm_from_locale_string ("Larger");
2509 $$ = scm_from_locale_string ("Dot");
2512 $$ = scm_from_locale_string ("Underscore");
2519 | '-' { $$ = CENTER; }
2523 multiplied_duration {
2528 maybe_notemode_duration:
2532 | multiplied_duration {
2534 parser->default_duration_ = *unsmob_duration ($$);
2539 optional_notemode_duration:
2540 maybe_notemode_duration
2542 if (SCM_UNBNDP ($$))
2543 $$ = parser->default_duration_.smobbed_copy ();
2548 bare_unsigned dots {
2550 if (!is_duration ($1))
2551 parser->parser_error (@1, _f ("not a duration: %d", $1));
2555 $$ = Duration (len, $2).smobbed_copy ();
2557 | DURATION_IDENTIFIER dots {
2558 Duration *d = unsmob_duration ($1);
2559 Duration k (d->duration_log (), d->dot_count () + $2);
2560 k = k.compressed (d->factor ());
2566 multiplied_duration:
2570 | multiplied_duration '*' bare_unsigned {
2571 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2573 | multiplied_duration '*' FRACTION {
2574 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2576 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2581 FRACTION { $$ = $1; }
2582 | UNSIGNED '/' UNSIGNED {
2583 $$ = scm_cons ($1, $3);
2600 | ':' bare_unsigned {
2601 if (!is_duration ($2))
2602 parser->parser_error (@2, _f ("not a duration: %d", $2));
2608 UNSIGNED { $$ = $1; }
2609 | STRING { $$ = $1; }
2610 | full_markup { $$ = $1; }
2613 figured_bass_alteration:
2614 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2615 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2616 | '!' { $$ = scm_from_int (0); }
2621 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2622 $$ = bfr->unprotect ();
2625 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2626 $$ = bfr->self_scm ();
2628 if (scm_is_number ($1))
2629 bfr->set_property ("figure", $1);
2630 else if (Text_interface::is_markup ($1))
2631 bfr->set_property ("text", $1);
2637 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2639 | bass_figure figured_bass_alteration {
2640 Music *m = unsmob_music ($1);
2641 if (scm_to_double ($2)) {
2642 SCM salter = m->get_property ("alteration");
2643 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2644 m->set_property ("alteration",
2645 scm_sum (alter, $2));
2647 m->set_property ("alteration", scm_from_int (0));
2650 | bass_figure figured_bass_modification {
2651 Music *m = unsmob_music ($1);
2652 if ($2 == ly_symbol2scm ("plus"))
2654 m->set_property ("augmented", SCM_BOOL_T);
2656 else if ($2 == ly_symbol2scm ("slash"))
2658 m->set_property ("diminished", SCM_BOOL_T);
2660 else if ($2 == ly_symbol2scm ("exclamation"))
2662 m->set_property ("no-continuation", SCM_BOOL_T);
2664 else if ($2 == ly_symbol2scm ("backslash"))
2666 m->set_property ("augmented-slash", SCM_BOOL_T);
2672 figured_bass_modification:
2674 $$ = ly_symbol2scm ("plus");
2677 $$ = ly_symbol2scm ("exclamation");
2680 $$ = ly_symbol2scm ("slash");
2683 $$ = ly_symbol2scm ("backslash");
2693 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2701 | figure_list br_bass_figure {
2702 $$ = scm_cons ($2, $1);
2707 FIGURE_OPEN figure_list FIGURE_CLOSE {
2708 $$ = scm_reverse_x ($2, SCM_EOL);
2719 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2720 if (!parser->lexer_->is_note_state ())
2721 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2722 if ($2 || $3 || scm_is_number ($4) || !SCM_UNBNDP ($5) || $6)
2726 n = MY_MAKE_MUSIC ("RestEvent", @$);
2728 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2730 n->set_property ("pitch", $1);
2731 if (SCM_UNBNDP ($5))
2732 n->set_property ("duration",
2733 parser->default_duration_.smobbed_copy ());
2735 n->set_property ("duration", $5);
2737 if (scm_is_number ($4))
2739 int q = scm_to_int ($4);
2740 n->set_property ("absolute-octave", scm_from_int (q-1));
2744 n->set_property ("cautionary", SCM_BOOL_T);
2745 if ($2 % 2 || $3 % 2)
2746 n->set_property ("force-accidental", SCM_BOOL_T);
2748 $$ = n->unprotect ();
2751 | DRUM_PITCH optional_notemode_duration {
2752 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2753 n->set_property ("duration", $2);
2754 n->set_property ("drum-type", $1);
2756 $$ = n->unprotect ();
2758 | RESTNAME optional_notemode_duration {
2760 if (ly_scm2string ($1) == "s") {
2762 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2765 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2768 ev->set_property ("duration", $2);
2769 $$ = ev->unprotect ();
2773 simple_chord_elements:
2775 if (!parser->lexer_->is_chord_state ())
2776 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2779 | figure_spec optional_notemode_duration {
2780 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2782 unsmob_music (scm_car (s))->set_property ("duration", $2);
2799 | lyric_element multiplied_duration post_events {
2800 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2801 if (scm_is_pair ($3))
2802 unsmob_music ($$)->set_property
2803 ("articulations", scm_reverse_x ($3, SCM_EOL));
2805 | lyric_element post_event post_events {
2806 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2807 parser->default_duration_.smobbed_copy ());
2808 unsmob_music ($$)->set_property
2809 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2811 | LYRIC_ELEMENT optional_notemode_duration post_events {
2812 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2813 if (scm_is_pair ($3))
2814 unsmob_music ($$)->set_property
2815 ("articulations", scm_reverse_x ($3, SCM_EOL));
2820 lyric_element_music:
2821 lyric_element optional_notemode_duration post_events {
2822 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2823 if (scm_is_pair ($3))
2824 unsmob_music ($$)->set_property
2825 ("articulations", scm_reverse_x ($3, SCM_EOL));
2830 steno_tonic_pitch optional_notemode_duration {
2831 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2833 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2834 SCM its = scm_reverse_x ($4, SCM_EOL);
2835 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2843 | chord_items chord_item {
2844 $$ = scm_cons ($2, $$);
2850 $$ = ly_symbol2scm ("chord-colon");
2853 $$ = ly_symbol2scm ("chord-caret");
2855 | CHORD_SLASH steno_tonic_pitch {
2856 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2858 | CHORD_BASS steno_tonic_pitch {
2859 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2868 $$ = scm_reverse_x ($1, SCM_EOL);
2876 step_number { $$ = scm_cons ($1, SCM_EOL); }
2877 | step_numbers '.' step_number {
2878 $$ = scm_cons ($3, $$);
2884 $$ = make_chord_step ($1, 0);
2886 | bare_unsigned '+' {
2887 $$ = make_chord_step ($1, SHARP_ALTERATION);
2889 | bare_unsigned CHORD_MINUS {
2890 $$ = make_chord_step ($1, FLAT_ALTERATION);
2896 $$ = scm_from_int ($1);
2898 | bare_unsigned '~' bare_unsigned {
2899 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2906 TODO: should deprecate in favor of Scheme?
2910 number_expression '+' number_term {
2911 $$ = scm_sum ($1, $3);
2913 | number_expression '-' number_term {
2914 $$ = scm_difference ($1, $3);
2923 | number_factor '*' number_factor {
2924 $$ = scm_product ($1, $3);
2926 | number_factor '/' number_factor {
2927 $$ = scm_divide ($1, $3);
2932 '-' number_factor { /* %prec UNARY_MINUS */
2933 $$ = scm_difference ($2, SCM_UNDEFINED);
2941 | UNSIGNED NUMBER_IDENTIFIER {
2942 $$ = scm_product ($1, $2);
2944 | REAL NUMBER_IDENTIFIER {
2945 $$ = scm_product ($1, $2);
2957 $$ = scm_to_int ($1);
2968 | exclamations '!' { $$ ++; }
2973 | questions '?' { $$ ++; }
2977 This should be done more dynamically if possible.
2981 LYRIC_MARKUP_IDENTIFIER {
2985 { parser->lexer_->push_markup_state (); }
2988 parser->lexer_->pop_state ();
2993 MARKUPLIST_IDENTIFIER {
2997 { parser->lexer_->push_markup_state (); }
3000 parser->lexer_->pop_state ();
3009 { parser->lexer_->push_markup_state (); }
3012 parser->lexer_->pop_state ();
3018 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3020 | markup_head_1_list simple_markup {
3021 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3031 if (Text_interface::is_markup ($1))
3032 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3033 else if (Text_interface::is_markup_list ($1))
3034 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3036 parser->parser_error (@1, _ ("not a markup"));
3037 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3044 MARKUPLIST_IDENTIFIER {
3047 | markup_composed_list {
3050 | markup_braced_list {
3053 | markup_command_list {
3054 $$ = scm_list_1 ($1);
3056 | markup_scm MARKUPLIST_IDENTIFIER
3062 markup_composed_list:
3063 markup_head_1_list markup_braced_list {
3064 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3070 '{' markup_braced_list_body '}' {
3071 $$ = scm_reverse_x ($2, SCM_EOL);
3075 markup_braced_list_body:
3076 /* empty */ { $$ = SCM_EOL; }
3077 | markup_braced_list_body markup {
3078 $$ = scm_cons ($2, $1);
3080 | markup_braced_list_body markup_list {
3081 $$ = scm_reverse_x ($2, $1);
3085 markup_command_list:
3086 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3087 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3091 markup_command_basic_arguments:
3092 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3093 $$ = scm_cons ($3, $2);
3095 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3096 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3098 | EXPECT_NO_MORE_ARGS {
3103 markup_command_list_arguments:
3104 markup_command_basic_arguments { $$ = $1; }
3105 | EXPECT_MARKUP markup_command_list_arguments markup {
3106 $$ = scm_cons ($3, $2);
3111 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3112 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3117 markup_head_1_item {
3118 $$ = scm_list_1 ($1);
3120 | markup_head_1_list markup_head_1_item {
3121 $$ = scm_cons ($2, $1);
3127 $$ = make_simple_markup ($1);
3129 | MARKUP_IDENTIFIER {
3132 | LYRIC_MARKUP_IDENTIFIER {
3135 | STRING_IDENTIFIER {
3139 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3140 parser->lexer_->push_note_state (alist_to_hashq (nn));
3141 } '{' score_body '}' {
3143 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3145 parser->lexer_->pop_state ();
3147 | MARKUP_FUNCTION markup_command_basic_arguments {
3148 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3150 | markup_scm MARKUP_IDENTIFIER
3157 markup_head_1_list simple_markup {
3158 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3159 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3169 Lily_parser::set_yydebug (bool x)
3175 Lily_parser::do_yyparse ()
3186 It is a little strange to have this function in this file, but
3187 otherwise, we have to import music classes into the lexer.
3191 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3193 if (scm_is_string (sid)) {
3195 return STRING_IDENTIFIER;
3196 } else if (unsmob_book (sid)) {
3197 Book *book = unsmob_book (sid)->clone ();
3198 *destination = book->self_scm ();
3201 return BOOK_IDENTIFIER;
3202 } else if (scm_is_number (sid)) {
3204 return NUMBER_IDENTIFIER;
3205 } else if (unsmob_context_def (sid)) {
3206 Context_def *def= unsmob_context_def (sid)->clone ();
3208 *destination = def->self_scm ();
3211 return CONTEXT_DEF_IDENTIFIER;
3212 } else if (unsmob_context_mod (sid)) {
3213 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3215 return CONTEXT_MOD_IDENTIFIER;
3216 } else if (unsmob_score (sid)) {
3217 Score *score = new Score (*unsmob_score (sid));
3218 *destination = score->self_scm ();
3220 score->unprotect ();
3221 return SCORE_IDENTIFIER;
3222 } else if (Music *mus = unsmob_music (sid)) {
3223 mus = mus->clone ();
3224 *destination = mus->self_scm ();
3225 unsmob_music (*destination)->
3226 set_property ("origin", make_input (last_input_));
3228 bool is_event = mus->is_mus_type ("post-event");
3230 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3231 } else if (unsmob_pitch (sid)) {
3232 *destination = unsmob_pitch (sid)->smobbed_copy ();
3233 return PITCH_IDENTIFIER;
3234 } else if (unsmob_duration (sid)) {
3235 *destination = unsmob_duration (sid)->smobbed_copy ();
3236 return DURATION_IDENTIFIER;
3237 } else if (unsmob_output_def (sid)) {
3238 Output_def *p = unsmob_output_def (sid);
3241 *destination = p->self_scm ();
3243 return OUTPUT_DEF_IDENTIFIER;
3244 } else if (Text_interface::is_markup (sid)) {
3246 if (is_lyric_state ())
3247 return LYRIC_MARKUP_IDENTIFIER;
3248 return MARKUP_IDENTIFIER;
3249 } else if (Text_interface::is_markup_list (sid)) {
3251 return MARKUPLIST_IDENTIFIER;
3258 get_next_unique_context_id ()
3260 return scm_from_locale_string ("$uniqueContextId");
3265 get_next_unique_lyrics_context_id ()
3267 static int new_context_count;
3269 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3270 return scm_from_locale_string (s);
3273 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3274 SCM arg, SCM args, SCM pred)
3276 args = scm_cons (arg, args);
3277 if (scm_is_true (scm_call_1 (pred, arg)))
3279 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3280 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3281 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3285 SCM loc_on_music (Input loc, SCM arg)
3287 if (Music *m = unsmob_music (arg))
3291 return m->unprotect ();
3297 is_regular_identifier (SCM id)
3299 string str = ly_scm2string (id);
3300 char const *s = str.c_str ();
3309 v = v && isalnum (*s);
3316 make_music_with_input (SCM name, Input where)
3318 Music *m = make_music_by_name (name);
3319 m->set_spot (where);
3324 make_simple_markup (SCM a)
3332 return t && t == 1 << intlog2 (t);
3336 set_music_properties (Music *p, SCM a)
3338 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3339 p->set_property (scm_caar (k), scm_cdar (k));
3344 make_chord_step (int step, Rational alter)
3347 alter += FLAT_ALTERATION;
3351 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3352 return m.smobbed_copy ();
3357 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3359 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3360 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3361 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3363 unsmob_music (scm_car (s))->set_spot (loc);
3369 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3371 Lily_lexer *lex = parser->lexer_;
3375 lex->prepare_for_next_token ();
3376 return lex->yylex ();