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 (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> complex_music
408 %type <scm> complex_music_prefix
409 %type <scm> mode_changed_music
410 %type <scm> repeated_music
411 %type <scm> sequential_music
412 %type <scm> simple_music
413 %type <scm> simultaneous_music
414 %type <scm> chord_body
415 %type <scm> chord_body_element
416 %type <scm> command_element
417 %type <scm> command_event
418 %type <scm> context_modification
419 %type <scm> context_change
420 %type <scm> direction_less_event
421 %type <scm> direction_reqd_event
422 %type <scm> embedded_lilypond
423 %type <scm> event_chord
424 %type <scm> fingering
425 %type <scm> gen_text_def
426 %type <scm> music_property_def
427 %type <scm> note_chord_element
428 %type <scm> post_event
429 %type <scm> post_event_nofinger
430 %type <scm> re_rhythmed_music
431 %type <scm> simple_element
432 %type <scm> simple_music_property_def
433 %type <scm> start_symbol
434 %type <scm> string_number_event
435 %type <scm> tempo_event
437 %type <outputdef> output_def_body
438 %type <outputdef> output_def_head
439 %type <outputdef> output_def_head_with_mode_switch
440 %type <outputdef> output_def
441 %type <outputdef> paper_block
443 %type <scm> music_function_call
444 %type <scm> music_list
445 %type <scm> assignment_id
446 %type <scm> bare_number
447 %type <scm> bare_number_closed
448 %type <scm> unsigned_number
449 %type <scm> bass_figure
450 %type <scm> figured_bass_modification
451 %type <scm> br_bass_figure
452 %type <scm> bass_number
453 %type <scm> chord_body_elements
454 %type <scm> chord_item
455 %type <scm> chord_items
456 %type <scm> chord_separator
457 %type <scm> context_def_mod
458 %type <scm> context_def_spec_block
459 %type <scm> context_def_spec_body
460 %type <scm> context_mod
461 %type <scm> context_mod_list
462 %type <scm> context_prop_spec
463 %type <scm> direction_less_char
464 %type <scm> duration_length
465 %type <scm> embedded_scm
466 %type <scm> embedded_scm_arg
467 %type <scm> embedded_scm_arg_closed
468 %type <scm> embedded_scm_bare
469 %type <scm> embedded_scm_bare_arg
470 %type <scm> embedded_scm_closed
471 %type <scm> event_function_event
472 %type <scm> figure_list
473 %type <scm> figure_spec
475 %type <scm> full_markup
476 %type <scm> full_markup_list
477 %type <scm> function_arglist
478 %type <scm> function_arglist_optional
479 %type <scm> function_arglist_backup
480 %type <scm> function_arglist_nonbackup
481 %type <scm> function_arglist_skip
482 %type <scm> function_arglist_bare
483 %type <scm> function_arglist_closed
484 %type <scm> function_arglist_closed_optional
485 %type <scm> function_arglist_common
486 %type <scm> function_arglist_common_lyric
487 %type <scm> function_arglist_common_minus
488 %type <scm> function_arglist_closed_common
489 %type <scm> function_arglist_keep
490 %type <scm> function_arglist_closed_keep
491 %type <scm> identifier_init
493 %type <scm> lilypond_header
494 %type <scm> lilypond_header_body
495 %type <scm> lyric_element
496 %type <scm> lyric_element_arg
497 %type <scm> lyric_element_music
498 %type <scm> lyric_markup
500 %type <scm> markup_braced_list
501 %type <scm> markup_braced_list_body
502 %type <scm> markup_composed_list
503 %type <scm> markup_command_list
504 %type <scm> markup_command_list_arguments
505 %type <scm> markup_command_basic_arguments
506 %type <scm> markup_head_1_item
507 %type <scm> markup_head_1_list
508 %type <scm> markup_list
509 %type <scm> markup_top
510 %type <scm> mode_changing_head
511 %type <scm> mode_changing_head_with_context
512 %type <scm> multiplied_duration
513 %type <scm> music_function_event
514 %type <scm> music_function_chord_body
515 %type <scm> new_chord
516 %type <scm> new_lyrics
517 %type <scm> number_expression
518 %type <scm> number_factor
519 %type <scm> number_term
520 %type <scm> octave_check
521 %type <scm> optional_context_mod
522 %type <scm> optional_id
523 %type <scm> optional_notemode_duration
525 %type <scm> pitch_also_in_chords
526 %type <scm> post_events
527 %type <scm> property_operation
528 %type <scm> property_path property_path_revved
530 %type <scm> scalar_closed
531 %type <scm> scm_function_call
532 %type <scm> scm_function_call_closed
533 %type <scm> script_abbreviation
534 %type <scm> simple_chord_elements
535 %type <scm> simple_markup
536 %type <scm> simple_string
537 %type <scm> steno_duration
538 %type <scm> steno_pitch
539 %type <scm> steno_tonic_pitch
540 %type <scm> step_number
541 %type <scm> step_numbers
543 %type <scm> tempo_range
545 %type <score> score_block
546 %type <score> score_body
551 /* We don't assign precedence to / and *, because we might need varied
552 prec levels in different prods */
561 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
562 parser->lexer_->push_note_state (alist_to_hashq (nn));
563 } embedded_lilypond {
564 parser->lexer_->pop_state ();
565 parser->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
569 lilypond: /* empty */ { }
570 | lilypond toplevel_expression {
572 | lilypond assignment {
575 parser->error_level_ = 1;
578 parser->error_level_ = 1;
585 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
589 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
590 scm_call_2 (proc, parser->self_scm (), book->self_scm ());
595 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
596 scm_call_2 (proc, parser->self_scm (), bookpart->self_scm ());
597 bookpart->unprotect ();
602 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
603 scm_call_2 (proc, parser->self_scm (), score->self_scm ());
607 Music *music = unsmob_music ($1);
608 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
609 scm_call_2 (proc, parser->self_scm (), music->self_scm ());
612 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
613 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
616 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
617 scm_call_2 (proc, parser->self_scm (), $1);
621 Output_def * od = $1;
623 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
624 id = ly_symbol2scm ("$defaultpaper");
625 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
626 id = ly_symbol2scm ("$defaultmidi");
627 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
628 id = ly_symbol2scm ("$defaultlayout");
630 parser->lexer_->set_identifier (id, od->self_scm ());
638 $$ = parser->lexer_->eval_scm ($1);
643 embedded_scm_bare_arg:
649 | context_modification
652 $$ = $1->self_scm ();
655 | context_def_spec_block
658 $$ = $1->self_scm ();
663 $$ = $1->self_scm ();
668 $$ = $1->self_scm ();
673 /* The generic version may end in music, or not */
681 embedded_scm_bare_arg
687 SCM_FUNCTION function_arglist {
688 $$ = MAKE_SYNTAX ("music-function", @$,
696 $$ = MAKE_SYNTAX ("void-music", @$);
699 | music music music_list {
700 $$ = MAKE_SYNTAX ("sequential-music", @$,
701 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
704 parser->error_level_ = 1;
706 | INVALID embedded_lilypond {
707 parser->error_level_ = 1;
712 lilypond_header_body:
714 $$ = get_header (parser);
715 parser->lexer_->add_scope ($$);
717 | lilypond_header_body assignment {
723 HEADER '{' lilypond_header_body '}' {
724 $$ = parser->lexer_->remove_scope ();
733 | LYRICS_STRING { $$ = $1; }
737 assignment_id '=' identifier_init {
738 parser->lexer_->set_identifier ($1, $3);
740 | assignment_id property_path '=' identifier_init {
741 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
742 parser->lexer_->set_identifier (path, $4);
745 TODO: devise standard for protection in parser.
747 The parser stack lives on the C-stack, which means that
748 all objects can be unprotected as soon as they're here.
758 $$ = $1->self_scm ();
762 $$ = $1->self_scm ();
766 $$ = $1->self_scm ();
770 $$ = $1->self_scm ();
773 | context_def_spec_block {
779 | post_event_nofinger {
782 | number_expression {
797 | context_modification {
802 context_def_spec_block:
803 CONTEXT '{' context_def_spec_body '}'
809 context_def_spec_body:
811 $$ = Context_def::make_scm ();
812 unsmob_context_def ($$)->origin ()->set_spot (@$);
814 | CONTEXT_DEF_IDENTIFIER {
816 unsmob_context_def ($$)->origin ()->set_spot (@$);
818 | context_def_spec_body embedded_scm {
819 if (Context_mod *cm = unsmob_context_mod ($2)) {
820 SCM p = cm->get_mods ();
821 Context_def*td = unsmob_context_def ($$);
823 for (; scm_is_pair (p); p = scm_cdr (p)) {
824 td->add_context_mod (scm_car (p));
827 parser->parser_error (@2, _ ("not a context mod"));
830 | context_def_spec_body context_mod {
831 unsmob_context_def ($$)->add_context_mod ($2);
833 | context_def_spec_body context_modification {
834 Context_def *td = unsmob_context_def ($$);
835 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
836 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
837 td->add_context_mod (scm_car (m));
845 BOOK '{' book_body '}' {
848 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
853 * Use 'handlers' like for toplevel-* stuff?
854 * grok \layout and \midi? */
858 init_papers (parser);
859 $$->origin ()->set_spot (@$);
860 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
861 $$->paper_->unprotect ();
862 push_paper (parser, $$->paper_);
863 $$->header_ = parser->lexer_->lookup_identifier ("$defaultheader");
864 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
865 parser->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
866 parser->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
869 $$ = unsmob_book ($1);
871 $$->origin ()->set_spot (@$);
872 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
874 | book_body paper_block {
877 set_paper (parser, $2);
879 | book_body bookpart_block {
881 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
882 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
883 bookpart->unprotect ();
885 | book_body score_block {
887 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
888 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
891 | book_body composite_music {
892 Music *music = unsmob_music ($2);
893 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
894 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
896 | book_body full_markup {
897 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
898 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
900 | book_body full_markup_list {
901 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
902 scm_call_2 (proc, $$->self_scm (), $2);
904 | book_body lilypond_header {
907 | book_body embedded_scm { }
910 $$->scores_ = SCM_EOL;
911 $$->bookparts_ = SCM_EOL;
916 BOOKPART '{' bookpart_body '}' {
918 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
925 $$->origin ()->set_spot (@$);
926 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
929 $$ = unsmob_book ($1);
931 $$->origin ()->set_spot (@$);
932 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
934 | bookpart_body paper_block {
938 | bookpart_body score_block {
940 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
941 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
944 | bookpart_body composite_music {
945 Music *music = unsmob_music ($2);
946 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
947 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
949 | bookpart_body full_markup {
950 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
951 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
953 | bookpart_body full_markup_list {
954 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
955 scm_call_2 (proc, $$->self_scm (), $2);
957 | bookpart_body lilypond_header {
960 | bookpart_body embedded_scm { }
961 | bookpart_body error {
963 $$->scores_ = SCM_EOL;
968 SCORE '{' score_body '}' {
976 SCM scorify = ly_lily_module_constant ("scorify-music");
977 SCM score = scm_call_2 (scorify, m, parser->self_scm ());
979 // pass ownernship to C++ again.
980 $$ = unsmob_score (score);
982 $$->origin ()->set_spot (@$);
985 $$ = unsmob_score ($1);
987 $$->origin ()->set_spot (@$);
989 | score_body lilypond_header {
992 | score_body output_def {
993 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
995 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1000 $$->add_output_def ($2);
1004 | score_body error {
1005 $$->error_found_ = true;
1017 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1019 parser->parser_error (@1, _ ("need \\paper for paper block"));
1021 $$ = get_paper (parser);
1028 output_def_body '}' {
1031 parser->lexer_->remove_scope ();
1032 parser->lexer_->pop_state ();
1038 $$ = get_paper (parser);
1039 $$->input_origin_ = @$;
1040 parser->lexer_->add_scope ($$->scope_);
1043 Output_def *p = get_midi (parser);
1045 parser->lexer_->add_scope (p->scope_);
1048 Output_def *p = get_layout (parser);
1050 parser->lexer_->add_scope (p->scope_);
1055 output_def_head_with_mode_switch:
1057 parser->lexer_->push_initial_state ();
1063 output_def_head_with_mode_switch '{' {
1065 $$->input_origin_.set_spot (@$);
1067 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1070 Output_def *o = unsmob_output_def ($3);
1071 o->input_origin_.set_spot (@$);
1074 parser->lexer_->remove_scope ();
1075 parser->lexer_->add_scope (o->scope_);
1077 | output_def_body assignment {
1080 | output_def_body context_def_spec_block {
1081 assign_context_def ($$, $2);
1083 | output_def_body error {
1089 TEMPO steno_duration '=' tempo_range {
1090 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1092 | TEMPO scalar_closed steno_duration '=' tempo_range {
1093 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1096 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1101 The representation of a list is reversed to have efficient append. */
1107 | music_list music {
1108 $$ = scm_cons ($2, $1);
1110 | music_list embedded_scm {
1113 | music_list error {
1114 Music *m = MY_MAKE_MUSIC("Music", @$);
1116 m->set_property ("error-found", SCM_BOOL_T);
1117 $$ = scm_cons (m->self_scm (), $1);
1118 m->unprotect (); /* UGH */
1125 $$ = scm_reverse_x ($2, SCM_EOL);
1130 | lyric_element_music
1131 | composite_music %prec COMPOSITE
1136 | composite_music %prec COMPOSITE
1140 REPEAT simple_string unsigned_number music
1142 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1144 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1146 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1151 SEQUENTIAL braced_music_list {
1152 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1154 | braced_music_list {
1155 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1160 SIMULTANEOUS braced_music_list {
1161 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1163 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1164 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1170 | music_property_def
1174 context_modification:
1175 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1177 parser->lexer_->pop_state ();
1180 | WITH CONTEXT_MOD_IDENTIFIER
1184 | CONTEXT_MOD_IDENTIFIER
1188 | WITH embedded_scm_closed
1190 if (unsmob_context_mod ($2))
1193 parser->parser_error (@2, _ ("not a context mod"));
1194 $$ = Context_mod ().smobbed_copy ();
1199 optional_context_mod:
1203 | context_modification
1211 $$ = Context_mod ().smobbed_copy ();
1213 | context_mod_list context_mod {
1214 unsmob_context_mod ($1)->add_context_mod ($2);
1216 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1217 Context_mod *md = unsmob_context_mod ($2);
1219 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1221 | context_mod_list embedded_scm {
1222 Context_mod *md = unsmob_context_mod ($2);
1224 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1226 parser->parser_error (@2, _ ("not a context mod"));
1235 /* Music that can be parsed without lookahead */
1238 | complex_music_prefix closed_music
1240 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1247 | grouped_music_list
1251 simultaneous_music { $$ = $1; }
1252 | sequential_music { $$ = $1; }
1255 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1256 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1257 and this rule returns the reversed list of arguments. */
1259 function_arglist_skip:
1260 function_arglist_common
1261 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1263 $$ = scm_cons ($1, $3);
1264 } %prec FUNCTION_ARGLIST
1265 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1267 $$ = scm_cons ($1, $3);
1268 } %prec FUNCTION_ARGLIST
1269 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1271 $$ = scm_cons ($1, $3);
1272 } %prec FUNCTION_ARGLIST
1276 function_arglist_nonbackup:
1277 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1278 $$ = scm_cons ($4, $3);
1280 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1281 $$ = scm_cons ($4, $3);
1283 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1285 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1287 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1289 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1291 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1293 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1295 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1297 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1299 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1301 SCM n = scm_difference ($5, SCM_UNDEFINED);
1302 if (scm_is_true (scm_call_1 ($2, n)))
1303 $$ = scm_cons (n, $3);
1305 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1306 t->set_property ("digit", $5);
1307 $$ = t->unprotect ();
1308 if (scm_is_true (scm_call_1 ($2, $$)))
1309 $$ = scm_cons ($$, $3);
1311 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1315 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1317 $$ = check_scheme_arg (parser, @4,
1318 scm_difference ($5, SCM_UNDEFINED),
1321 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1323 $$ = check_scheme_arg (parser, @4,
1324 scm_difference ($5, SCM_UNDEFINED),
1330 function_arglist_keep:
1331 function_arglist_common
1332 | function_arglist_backup
1335 function_arglist_closed_keep:
1336 function_arglist_closed_common
1337 | function_arglist_backup
1340 function_arglist_backup:
1341 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1343 if (scm_is_true (scm_call_1 ($2, $4)))
1345 $$ = scm_cons ($4, $3);
1347 $$ = scm_cons (loc_on_music (@3, $1), $3);
1348 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1351 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1353 if (scm_is_true (scm_call_1 ($2, $4)))
1355 $$ = scm_cons ($4, $3);
1357 $$ = scm_cons (loc_on_music (@3, $1), $3);
1358 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1361 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1363 // There is no point interpreting a lyrics string as
1364 // an event, since we don't allow music possibly
1365 // followed by durations or postevent into closed
1366 // music, and we only accept closed music in optional
1367 // arguments at the moment. If this changes, more
1368 // complex schemes might become interesting here as
1369 // well: see how we do this at the mandatory argument
1371 if (scm_is_true (scm_call_1 ($2, $4)))
1372 $$ = scm_cons ($4, $3);
1374 $$ = scm_cons (loc_on_music (@3, $1), $3);
1375 MYBACKUP (LYRICS_STRING, $4, @4);
1378 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1380 if (scm_is_true (scm_call_1 ($2, $4)))
1383 MYREPARSE (@4, $2, UNSIGNED, $4);
1385 $$ = scm_cons (loc_on_music (@3, $1), $3);
1386 MYBACKUP (UNSIGNED, $4, @4);
1389 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1391 if (scm_is_true (scm_call_1 ($2, $4)))
1394 MYREPARSE (@4, $2, REAL, $4);
1396 $$ = scm_cons (loc_on_music (@3, $1), $3);
1397 MYBACKUP (REAL, $4, @4);
1400 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1402 if (scm_is_true (scm_call_1 ($2, $4)))
1404 $$ = scm_cons ($4, $3);
1406 $$ = scm_cons (loc_on_music (@3, $1), $3);
1407 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1410 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1412 if (scm_is_true (scm_call_1 ($2, $4)))
1414 $$ = scm_cons ($4, $3);
1416 $$ = scm_cons (loc_on_music (@3, $1), $3);
1417 MYBACKUP (FRACTION, $4, @4);
1420 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1422 SCM n = scm_difference ($5, SCM_UNDEFINED);
1423 if (scm_is_true (scm_call_1 ($2, n))) {
1425 MYREPARSE (@5, $2, REAL, n);
1427 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1428 t->set_property ("digit", $5);
1429 $$ = t->unprotect ();
1430 if (scm_is_true (scm_call_1 ($2, $$)))
1431 $$ = scm_cons ($$, $3);
1433 $$ = scm_cons (loc_on_music (@3, $1), $3);
1434 MYBACKUP (UNSIGNED, $5, @5);
1435 parser->lexer_->push_extra_token ('-');
1440 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1442 SCM n = scm_difference ($5, SCM_UNDEFINED);
1443 if (scm_is_true (scm_call_1 ($2, n))) {
1444 MYREPARSE (@5, $2, REAL, n);
1447 MYBACKUP (REAL, n, @5);
1450 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1452 SCM n = scm_difference ($5, SCM_UNDEFINED);
1453 if (scm_is_true (scm_call_1 ($2, n))) {
1454 $$ = scm_cons (n, $3);
1456 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1459 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1461 $$ = scm_cons ($4, $3);
1463 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1465 $$ = scm_cons ($4, $3);
1467 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1469 $$ = scm_cons ($1, $3);
1470 MYBACKUP(0, SCM_UNDEFINED, @3);
1472 | function_arglist_backup REPARSE embedded_scm_arg_closed
1474 $$ = check_scheme_arg (parser, @3,
1477 | function_arglist_backup REPARSE bare_number
1479 $$ = check_scheme_arg (parser, @3,
1482 | function_arglist_backup REPARSE fraction
1484 $$ = check_scheme_arg (parser, @3,
1490 function_arglist_common
1491 | function_arglist_nonbackup
1494 function_arglist_common:
1495 function_arglist_bare
1496 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1498 $$ = check_scheme_arg (parser, @3,
1501 | EXPECT_SCM function_arglist_closed_optional bare_number
1503 $$ = check_scheme_arg (parser, @3,
1506 | EXPECT_SCM function_arglist_closed_optional fraction
1508 $$ = check_scheme_arg (parser, @3,
1511 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1513 $$ = check_scheme_arg (parser, @3,
1516 | function_arglist_common_minus
1517 | function_arglist_common_lyric
1520 function_arglist_common_lyric:
1521 EXPECT_SCM function_arglist_optional lyric_element
1523 // We check how the predicate thinks about a lyrics
1524 // event or about a markup. If it accepts neither, we
1525 // backup the original token. Otherwise we commit to
1526 // taking the token. Depending on what the predicate
1527 // is willing to accept, we interpret as a string, as
1528 // a lyric event, or ambiguously (meaning that if
1529 // something looking like a duration or post event
1530 // follows, we take the event, otherwise the string).
1531 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1532 parser->default_duration_.smobbed_copy ());
1533 if (scm_is_true (scm_call_1 ($1, $3)))
1534 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1537 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1539 $$ = scm_cons ($3, $2);
1541 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1544 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1546 // This is going to flag a syntax error, we
1547 // know the predicate to be false.
1548 check_scheme_arg (parser, @3,
1552 | function_arglist_common_lyric REPARSE lyric_element_arg
1554 // This should never be false
1555 $$ = check_scheme_arg (parser, @3,
1560 function_arglist_common_minus:
1561 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1563 SCM n = scm_difference ($4, SCM_UNDEFINED);
1564 if (scm_is_true (scm_call_1 ($1, n))) {
1566 MYREPARSE (@4, $1, REAL, n);
1568 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1569 t->set_property ("digit", $4);
1570 $$ = t->unprotect ();
1571 if (scm_is_true (scm_call_1 ($1, $$)))
1572 $$ = scm_cons ($$, $2);
1574 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1578 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1581 SCM n = scm_difference ($4, SCM_UNDEFINED);
1582 MYREPARSE (@4, $1, REAL, n);
1584 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1586 SCM n = scm_difference ($4, SCM_UNDEFINED);
1587 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1589 | function_arglist_common_minus REPARSE bare_number
1591 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1595 function_arglist_closed:
1596 function_arglist_closed_common
1597 | function_arglist_nonbackup
1600 function_arglist_closed_common:
1601 function_arglist_bare
1602 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1604 $$ = check_scheme_arg (parser, @3,
1607 | EXPECT_SCM function_arglist_closed_optional bare_number
1609 $$ = check_scheme_arg (parser, @3,
1612 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1614 SCM n = scm_difference ($4, SCM_UNDEFINED);
1615 if (scm_is_true (scm_call_1 ($1, n))) {
1616 $$ = scm_cons (n, $2);
1618 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1619 t->set_property ("digit", $4);
1620 $$ = t->unprotect ();
1621 if (scm_is_true (scm_call_1 ($1, $$)))
1622 $$ = scm_cons ($$, $2);
1624 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1628 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1630 $$ = check_scheme_arg (parser, @3,
1631 scm_difference ($4, SCM_UNDEFINED),
1634 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1636 $$ = check_scheme_arg (parser, @3,
1637 scm_difference ($4, SCM_UNDEFINED),
1640 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1642 $$ = check_scheme_arg (parser, @3,
1645 | EXPECT_SCM function_arglist_closed_optional fraction
1647 $$ = check_scheme_arg (parser, @3,
1650 | EXPECT_SCM function_arglist_optional lyric_element
1652 $$ = check_scheme_arg (parser, @3,
1657 function_arglist_optional:
1658 function_arglist_keep %prec FUNCTION_ARGLIST
1659 | function_arglist_backup BACKUP
1660 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1662 $$ = scm_cons ($1, $3);
1664 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1666 $$ = scm_cons ($1, $3);
1670 function_arglist_closed_optional:
1671 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1672 | function_arglist_backup BACKUP
1673 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1675 $$ = scm_cons ($1, $3);
1677 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1679 $$ = scm_cons ($1, $3);
1683 embedded_scm_closed:
1685 | scm_function_call_closed
1688 embedded_scm_arg_closed:
1689 embedded_scm_bare_arg
1690 | scm_function_call_closed
1694 scm_function_call_closed:
1695 SCM_FUNCTION function_arglist_closed {
1696 $$ = MAKE_SYNTAX ("music-function", @$,
1698 } %prec FUNCTION_ARGLIST
1701 function_arglist_bare:
1702 EXPECT_NO_MORE_ARGS {
1705 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1706 $$ = scm_cons ($3, $2);
1708 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1709 $$ = scm_cons ($3, $2);
1711 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1712 $$ = scm_cons ($1, $3);
1714 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1715 $$ = scm_cons ($1, $3);
1717 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1718 $$ = scm_cons ($1, $3);
1722 music_function_call:
1723 MUSIC_FUNCTION function_arglist {
1724 $$ = MAKE_SYNTAX ("music-function", @$,
1731 /**/ { $$ = SCM_EOL; }
1732 | '=' simple_string {
1739 | repeated_music { $$ = $1; }
1740 | re_rhythmed_music { $$ = $1; }
1741 | complex_music_prefix music
1743 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1747 complex_music_prefix:
1748 CONTEXT simple_string optional_id optional_context_mod {
1749 Context_mod *ctxmod = unsmob_context_mod ($4);
1752 mods = ctxmod->get_mods ();
1753 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1755 | NEWCONTEXT simple_string optional_id optional_context_mod {
1756 Context_mod *ctxmod = unsmob_context_mod ($4);
1759 mods = ctxmod->get_mods ();
1760 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1765 mode_changing_head grouped_music_list {
1766 if ($1 == ly_symbol2scm ("chords"))
1768 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1774 parser->lexer_->pop_state ();
1776 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1777 Context_mod *ctxmod = unsmob_context_mod ($2);
1780 mods = ctxmod->get_mods ();
1781 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1782 if ($1 == ly_symbol2scm ("ChordNames"))
1784 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1786 parser->lexer_->pop_state ();
1792 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1793 parser->lexer_->push_note_state (alist_to_hashq (nn));
1795 $$ = ly_symbol2scm ("notes");
1799 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1800 parser->lexer_->push_note_state (alist_to_hashq (nn));
1802 $$ = ly_symbol2scm ("drums");
1805 parser->lexer_->push_figuredbass_state ();
1807 $$ = ly_symbol2scm ("figures");
1810 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1811 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1812 nn = parser->lexer_->lookup_identifier ("pitchnames");
1813 parser->lexer_->push_chord_state (alist_to_hashq (nn));
1814 $$ = ly_symbol2scm ("chords");
1818 { parser->lexer_->push_lyric_state ();
1819 $$ = ly_symbol2scm ("lyrics");
1823 mode_changing_head_with_context:
1825 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1826 parser->lexer_->push_note_state (alist_to_hashq (nn));
1828 $$ = ly_symbol2scm ("DrumStaff");
1831 parser->lexer_->push_figuredbass_state ();
1833 $$ = ly_symbol2scm ("FiguredBass");
1836 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1837 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1838 nn = parser->lexer_->lookup_identifier ("pitchnames");
1839 parser->lexer_->push_chord_state (alist_to_hashq (nn));
1840 $$ = ly_symbol2scm ("ChordNames");
1843 { parser->lexer_->push_lyric_state ();
1844 $$ = ly_symbol2scm ("Lyrics");
1849 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1852 /* Can also use music at the expensive of two S/Rs similar to
1853 \repeat \alternative */
1854 parser->lexer_->pop_state ();
1856 $$ = scm_cons ($3, SCM_EOL);
1858 | new_lyrics ADDLYRICS {
1859 parser->lexer_->push_lyric_state ();
1861 parser->lexer_->pop_state ();
1862 $$ = scm_cons ($4, $1);
1867 composite_music new_lyrics {
1868 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1870 | LYRICSTO simple_string {
1871 parser->lexer_->push_lyric_state ();
1873 parser->lexer_->pop_state ();
1874 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1879 CHANGE STRING '=' STRING {
1880 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1885 property_path_revved:
1886 embedded_scm_closed {
1887 $$ = scm_cons ($1, SCM_EOL);
1889 | property_path_revved embedded_scm_closed {
1890 $$ = scm_cons ($2, $1);
1895 property_path_revved {
1896 $$ = scm_reverse_x ($1, SCM_EOL);
1902 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1903 scm_string_to_symbol ($1), $3);
1905 | UNSET simple_string {
1906 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1907 scm_string_to_symbol ($2));
1909 | OVERRIDE simple_string property_path '=' scalar {
1910 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1911 scm_string_to_symbol ($2), $5),
1914 | REVERT simple_string embedded_scm {
1915 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1916 scm_string_to_symbol ($2), $3);
1921 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1922 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1924 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1925 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1926 | DENIES { $$ = ly_symbol2scm ("denies"); }
1928 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1929 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1930 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1931 | NAME { $$ = ly_symbol2scm ("context-name"); }
1935 property_operation { $$ = $1; }
1936 | context_def_mod STRING {
1937 $$ = scm_list_2 ($1, $2);
1939 | context_def_mod embedded_scm {
1940 if (ly_symbol2scm ("consists") != $1)
1943 parser->parser_error (@1, _ ("only \\consists takes non-string argument."));
1947 $$ = scm_list_2 ($1, $2);
1954 if (!is_regular_identifier ($1))
1956 @$.error (_("Grob name should be alphanumeric"));
1959 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1960 scm_string_to_symbol ($1));
1962 | simple_string '.' simple_string {
1963 $$ = scm_list_2 (scm_string_to_symbol ($1),
1964 scm_string_to_symbol ($3));
1968 simple_music_property_def:
1969 OVERRIDE context_prop_spec property_path '=' scalar {
1970 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1971 ly_symbol2scm ("OverrideProperty"),
1976 | REVERT context_prop_spec embedded_scm {
1977 $$ = scm_list_4 (scm_car ($2),
1978 ly_symbol2scm ("RevertProperty"),
1982 | SET context_prop_spec '=' scalar {
1983 $$ = scm_list_4 (scm_car ($2),
1984 ly_symbol2scm ("PropertySet"),
1988 | UNSET context_prop_spec {
1989 $$ = scm_list_3 (scm_car ($2),
1990 ly_symbol2scm ("PropertyUnset"),
1996 simple_music_property_def {
1997 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2005 | STRING_IDENTIFIER {
2008 | string '+' string {
2009 $$ = scm_string_append (scm_list_2 ($1, $3));
2013 simple_string: STRING {
2019 | STRING_IDENTIFIER {
2031 embedded_scm_arg_closed
2038 simple_element post_events {
2039 // Let the rhythmic music iterator sort this mess out.
2040 if (scm_is_pair ($2))
2041 unsmob_music ($1)->set_property ("articulations",
2042 scm_reverse_x ($2, SCM_EOL));
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 if (!SCM_UNBNDP ($2))
2107 $$ = scm_cons ($2, $1);
2112 pitch exclamations questions octave_check post_events
2119 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2120 n->set_property ("pitch", $1);
2122 n->set_property ("cautionary", SCM_BOOL_T);
2123 if (ex % 2 || q % 2)
2124 n->set_property ("force-accidental", SCM_BOOL_T);
2126 if (scm_is_pair (post)) {
2127 SCM arts = scm_reverse_x (post, SCM_EOL);
2128 n->set_property ("articulations", arts);
2130 if (scm_is_number (check))
2132 int q = scm_to_int (check);
2133 n->set_property ("absolute-octave", scm_from_int (q-1));
2136 $$ = n->unprotect ();
2138 | DRUM_PITCH post_events {
2139 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2140 n->set_property ("drum-type", $1);
2142 if (scm_is_pair ($2)) {
2143 SCM arts = scm_reverse_x ($2, SCM_EOL);
2144 n->set_property ("articulations", arts);
2146 $$ = n->unprotect ();
2148 | music_function_chord_body
2150 Music *m = unsmob_music ($1);
2152 while (m && m->is_mus_type ("music-wrapper-music")) {
2153 $$ = m->get_property ("element");
2154 m = unsmob_music ($$);
2157 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2158 parser->parser_error (@$, _ ("not a rhythmic event"));
2164 music_function_chord_body:
2169 // Event functions may only take closed arglists, otherwise it would
2170 // not be clear whether a following postevent should be associated
2171 // with the last argument of the event function or with the expression
2172 // for which the function call acts itself as event.
2174 music_function_event:
2175 MUSIC_FUNCTION function_arglist_closed {
2176 $$ = MAKE_SYNTAX ("music-function", @$,
2181 event_function_event:
2182 EVENT_FUNCTION function_arglist_closed {
2183 $$ = MAKE_SYNTAX ("music-function", @$,
2193 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2194 m->set_property ("span-direction", scm_from_int (START));
2195 $$ = m->unprotect();
2198 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2199 m->set_property ("span-direction", scm_from_int (STOP));
2200 $$ = m->unprotect ();
2203 $$ = MAKE_SYNTAX ("voice-separator", @$);
2206 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2208 Music *m = unsmob_music (pipe);
2213 $$ = m->unprotect ();
2216 $$ = MAKE_SYNTAX ("bar-check", @$);
2223 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2235 | post_events post_event {
2236 unsmob_music ($2)->set_spot (@2);
2237 $$ = scm_cons ($2, $$);
2241 post_event_nofinger:
2242 direction_less_event {
2245 | script_dir music_function_event {
2249 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2253 if (!parser->lexer_->is_lyric_state ())
2254 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2255 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2258 if (!parser->lexer_->is_lyric_state ())
2259 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2260 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2262 | script_dir direction_reqd_event {
2265 Music *m = unsmob_music ($2);
2266 m->set_property ("direction", scm_from_int ($1));
2270 | script_dir direction_less_event {
2273 Music *m = unsmob_music ($2);
2274 m->set_property ("direction", scm_from_int ($1));
2278 | string_number_event
2282 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2287 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2298 string_number_event:
2300 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2301 s->set_property ("string-number", scm_from_int ($1));
2302 $$ = s->unprotect ();
2306 direction_less_char:
2308 $$ = ly_symbol2scm ("bracketOpenSymbol");
2311 $$ = ly_symbol2scm ("bracketCloseSymbol");
2314 $$ = ly_symbol2scm ("tildeSymbol");
2317 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2320 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2323 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2326 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2329 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2332 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2335 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2339 direction_less_event:
2340 direction_less_char {
2341 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2343 if (unsmob_music (predefd))
2345 m = unsmob_music (predefd)->clone ();
2350 m = MY_MAKE_MUSIC ("Music", @$);
2352 $$ = m->unprotect ();
2354 | EVENT_IDENTIFIER {
2358 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2359 a->set_property ("tremolo-type", scm_from_int ($1));
2360 $$ = a->unprotect ();
2362 | event_function_event
2365 direction_reqd_event:
2369 | script_abbreviation {
2370 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2371 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2372 if (scm_is_string (s))
2373 a->set_property ("articulation-type", s);
2374 else parser->parser_error (@1, _ ("expecting string as script definition"));
2375 $$ = a->unprotect ();
2380 /**/ { $$ = SCM_EOL; }
2381 | '=' { $$ = scm_from_int (0); }
2382 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2383 | '=' sup_quotes { $$ = scm_from_int ($2); }
2408 | NOTENAME_PITCH sup_quotes {
2409 Pitch p = *unsmob_pitch ($1);
2410 p = p.transposed (Pitch ($2,0,0));
2411 $$ = p.smobbed_copy ();
2413 | NOTENAME_PITCH sub_quotes {
2414 Pitch p =* unsmob_pitch ($1);
2415 p = p.transposed (Pitch (-$2,0,0));
2416 $$ = p.smobbed_copy ();
2428 | TONICNAME_PITCH sup_quotes {
2429 Pitch p = *unsmob_pitch ($1);
2430 p = p.transposed (Pitch ($2,0,0));
2431 $$ = p.smobbed_copy ();
2433 | TONICNAME_PITCH sub_quotes {
2434 Pitch p = *unsmob_pitch ($1);
2436 p = p.transposed (Pitch (-$2,0,0));
2437 $$ = p.smobbed_copy ();
2448 pitch_also_in_chords:
2455 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2456 t->set_property ("text", $1);
2457 $$ = t->unprotect ();
2460 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2461 t->set_property ("text",
2462 make_simple_markup ($1));
2463 $$ = t->unprotect ();
2469 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2470 t->set_property ("digit", $1);
2471 $$ = t->unprotect ();
2475 script_abbreviation:
2477 $$ = scm_from_locale_string ("Hat");
2480 $$ = scm_from_locale_string ("Plus");
2483 $$ = scm_from_locale_string ("Dash");
2486 $$ = scm_from_locale_string ("Bar");
2489 $$ = scm_from_locale_string ("Larger");
2492 $$ = scm_from_locale_string ("Dot");
2495 $$ = scm_from_locale_string ("Underscore");
2502 | '-' { $$ = CENTER; }
2506 multiplied_duration {
2511 optional_notemode_duration:
2513 Duration dd = parser->default_duration_;
2514 $$ = dd.smobbed_copy ();
2516 | multiplied_duration {
2518 parser->default_duration_ = *unsmob_duration ($$);
2523 bare_unsigned dots {
2525 if (!is_duration ($1))
2526 parser->parser_error (@1, _f ("not a duration: %d", $1));
2530 $$ = Duration (len, $2).smobbed_copy ();
2532 | DURATION_IDENTIFIER dots {
2533 Duration *d = unsmob_duration ($1);
2534 Duration k (d->duration_log (), d->dot_count () + $2);
2535 k = k.compressed (d->factor ());
2541 multiplied_duration:
2545 | multiplied_duration '*' bare_unsigned {
2546 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2548 | multiplied_duration '*' FRACTION {
2549 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2551 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2556 FRACTION { $$ = $1; }
2557 | UNSIGNED '/' UNSIGNED {
2558 $$ = scm_cons ($1, $3);
2575 | ':' bare_unsigned {
2576 if (!is_duration ($2))
2577 parser->parser_error (@2, _f ("not a duration: %d", $2));
2583 UNSIGNED { $$ = $1; }
2584 | STRING { $$ = $1; }
2585 | full_markup { $$ = $1; }
2588 figured_bass_alteration:
2589 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2590 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2591 | '!' { $$ = scm_from_int (0); }
2596 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2597 $$ = bfr->unprotect ();
2600 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2601 $$ = bfr->self_scm ();
2603 if (scm_is_number ($1))
2604 bfr->set_property ("figure", $1);
2605 else if (Text_interface::is_markup ($1))
2606 bfr->set_property ("text", $1);
2612 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2614 | bass_figure figured_bass_alteration {
2615 Music *m = unsmob_music ($1);
2616 if (scm_to_double ($2)) {
2617 SCM salter = m->get_property ("alteration");
2618 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2619 m->set_property ("alteration",
2620 scm_sum (alter, $2));
2622 m->set_property ("alteration", scm_from_int (0));
2625 | bass_figure figured_bass_modification {
2626 Music *m = unsmob_music ($1);
2627 if ($2 == ly_symbol2scm ("plus"))
2629 m->set_property ("augmented", SCM_BOOL_T);
2631 else if ($2 == ly_symbol2scm ("slash"))
2633 m->set_property ("diminished", SCM_BOOL_T);
2635 else if ($2 == ly_symbol2scm ("exclamation"))
2637 m->set_property ("no-continuation", SCM_BOOL_T);
2639 else if ($2 == ly_symbol2scm ("backslash"))
2641 m->set_property ("augmented-slash", SCM_BOOL_T);
2647 figured_bass_modification:
2649 $$ = ly_symbol2scm ("plus");
2652 $$ = ly_symbol2scm ("exclamation");
2655 $$ = ly_symbol2scm ("slash");
2658 $$ = ly_symbol2scm ("backslash");
2668 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2676 | figure_list br_bass_figure {
2677 $$ = scm_cons ($2, $1);
2682 FIGURE_OPEN figure_list FIGURE_CLOSE {
2683 $$ = scm_reverse_x ($2, SCM_EOL);
2694 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2695 if (!parser->lexer_->is_note_state ())
2696 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2700 n = MY_MAKE_MUSIC ("RestEvent", @$);
2702 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2704 n->set_property ("pitch", $1);
2705 n->set_property ("duration", $5);
2707 if (scm_is_number ($4))
2709 int q = scm_to_int ($4);
2710 n->set_property ("absolute-octave", scm_from_int (q-1));
2714 n->set_property ("cautionary", SCM_BOOL_T);
2715 if ($2 % 2 || $3 % 2)
2716 n->set_property ("force-accidental", SCM_BOOL_T);
2718 $$ = n->unprotect ();
2720 | DRUM_PITCH optional_notemode_duration {
2721 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2722 n->set_property ("duration", $2);
2723 n->set_property ("drum-type", $1);
2725 $$ = n->unprotect ();
2727 | RESTNAME optional_notemode_duration {
2729 if (ly_scm2string ($1) == "s") {
2731 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2734 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2737 ev->set_property ("duration", $2);
2738 $$ = ev->unprotect ();
2742 simple_chord_elements:
2744 if (!parser->lexer_->is_chord_state ())
2745 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2748 | figure_spec optional_notemode_duration {
2749 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2751 unsmob_music (scm_car (s))->set_property ("duration", $2);
2768 | lyric_element multiplied_duration post_events {
2769 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2770 if (scm_is_pair ($3))
2771 unsmob_music ($$)->set_property
2772 ("articulations", scm_reverse_x ($3, SCM_EOL));
2774 | lyric_element post_event post_events {
2775 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2776 parser->default_duration_.smobbed_copy ());
2777 unsmob_music ($$)->set_property
2778 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2780 | LYRIC_ELEMENT optional_notemode_duration post_events {
2781 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2782 if (scm_is_pair ($3))
2783 unsmob_music ($$)->set_property
2784 ("articulations", scm_reverse_x ($3, SCM_EOL));
2789 lyric_element_music:
2790 lyric_element optional_notemode_duration post_events {
2791 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2792 if (scm_is_pair ($3))
2793 unsmob_music ($$)->set_property
2794 ("articulations", scm_reverse_x ($3, SCM_EOL));
2799 steno_tonic_pitch optional_notemode_duration {
2800 $$ = make_chord_elements ($1, $2, SCM_EOL);
2802 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2803 SCM its = scm_reverse_x ($4, SCM_EOL);
2804 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2812 | chord_items chord_item {
2813 $$ = scm_cons ($2, $$);
2819 $$ = ly_symbol2scm ("chord-colon");
2822 $$ = ly_symbol2scm ("chord-caret");
2824 | CHORD_SLASH steno_tonic_pitch {
2825 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2827 | CHORD_BASS steno_tonic_pitch {
2828 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2837 $$ = scm_reverse_x ($1, SCM_EOL);
2845 step_number { $$ = scm_cons ($1, SCM_EOL); }
2846 | step_numbers '.' step_number {
2847 $$ = scm_cons ($3, $$);
2853 $$ = make_chord_step ($1, 0);
2855 | bare_unsigned '+' {
2856 $$ = make_chord_step ($1, SHARP_ALTERATION);
2858 | bare_unsigned CHORD_MINUS {
2859 $$ = make_chord_step ($1, FLAT_ALTERATION);
2865 $$ = scm_from_int ($1);
2867 | bare_unsigned '~' bare_unsigned {
2868 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2875 TODO: should deprecate in favor of Scheme?
2879 number_expression '+' number_term {
2880 $$ = scm_sum ($1, $3);
2882 | number_expression '-' number_term {
2883 $$ = scm_difference ($1, $3);
2892 | number_factor '*' number_factor {
2893 $$ = scm_product ($1, $3);
2895 | number_factor '/' number_factor {
2896 $$ = scm_divide ($1, $3);
2901 '-' number_factor { /* %prec UNARY_MINUS */
2902 $$ = scm_difference ($2, SCM_UNDEFINED);
2910 | UNSIGNED NUMBER_IDENTIFIER {
2911 $$ = scm_product ($1, $2);
2913 | REAL NUMBER_IDENTIFIER {
2914 $$ = scm_product ($1, $2);
2926 $$ = scm_to_int ($1);
2937 | exclamations '!' { $$ ++; }
2942 | questions '?' { $$ ++; }
2946 This should be done more dynamically if possible.
2950 LYRIC_MARKUP_IDENTIFIER {
2954 { parser->lexer_->push_markup_state (); }
2957 parser->lexer_->pop_state ();
2962 MARKUPLIST_IDENTIFIER {
2966 { parser->lexer_->push_markup_state (); }
2969 parser->lexer_->pop_state ();
2978 { parser->lexer_->push_markup_state (); }
2981 parser->lexer_->pop_state ();
2987 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2989 | markup_head_1_list simple_markup {
2990 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3000 if (Text_interface::is_markup ($1))
3001 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3002 else if (Text_interface::is_markup_list ($1))
3003 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3005 parser->parser_error (@1, _ ("not a markup"));
3006 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3013 MARKUPLIST_IDENTIFIER {
3016 | markup_composed_list {
3019 | markup_braced_list {
3022 | markup_command_list {
3023 $$ = scm_list_1 ($1);
3025 | markup_scm MARKUPLIST_IDENTIFIER
3031 markup_composed_list:
3032 markup_head_1_list markup_braced_list {
3033 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3039 '{' markup_braced_list_body '}' {
3040 $$ = scm_reverse_x ($2, SCM_EOL);
3044 markup_braced_list_body:
3045 /* empty */ { $$ = SCM_EOL; }
3046 | markup_braced_list_body markup {
3047 $$ = scm_cons ($2, $1);
3049 | markup_braced_list_body markup_list {
3050 $$ = scm_reverse_x ($2, $1);
3054 markup_command_list:
3055 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3056 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3060 markup_command_basic_arguments:
3061 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3062 $$ = scm_cons ($3, $2);
3064 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3065 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3067 | EXPECT_NO_MORE_ARGS {
3072 markup_command_list_arguments:
3073 markup_command_basic_arguments { $$ = $1; }
3074 | EXPECT_MARKUP markup_command_list_arguments markup {
3075 $$ = scm_cons ($3, $2);
3080 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3081 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3086 markup_head_1_item {
3087 $$ = scm_list_1 ($1);
3089 | markup_head_1_list markup_head_1_item {
3090 $$ = scm_cons ($2, $1);
3096 $$ = make_simple_markup ($1);
3098 | MARKUP_IDENTIFIER {
3101 | LYRIC_MARKUP_IDENTIFIER {
3104 | STRING_IDENTIFIER {
3108 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3109 parser->lexer_->push_note_state (alist_to_hashq (nn));
3110 } '{' score_body '}' {
3112 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3114 parser->lexer_->pop_state ();
3116 | MARKUP_FUNCTION markup_command_basic_arguments {
3117 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3119 | markup_scm MARKUP_IDENTIFIER
3126 markup_head_1_list simple_markup {
3127 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3128 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3138 Lily_parser::set_yydebug (bool x)
3144 Lily_parser::do_yyparse ()
3155 It is a little strange to have this function in this file, but
3156 otherwise, we have to import music classes into the lexer.
3160 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3162 if (scm_is_string (sid)) {
3164 return STRING_IDENTIFIER;
3165 } else if (unsmob_book (sid)) {
3166 Book *book = unsmob_book (sid)->clone ();
3167 *destination = book->self_scm ();
3170 return BOOK_IDENTIFIER;
3171 } else if (scm_is_number (sid)) {
3173 return NUMBER_IDENTIFIER;
3174 } else if (unsmob_context_def (sid)) {
3175 Context_def *def= unsmob_context_def (sid)->clone ();
3177 *destination = def->self_scm ();
3180 return CONTEXT_DEF_IDENTIFIER;
3181 } else if (unsmob_context_mod (sid)) {
3182 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3184 return CONTEXT_MOD_IDENTIFIER;
3185 } else if (unsmob_score (sid)) {
3186 Score *score = new Score (*unsmob_score (sid));
3187 *destination = score->self_scm ();
3189 score->unprotect ();
3190 return SCORE_IDENTIFIER;
3191 } else if (Music *mus = unsmob_music (sid)) {
3192 mus = mus->clone ();
3193 *destination = mus->self_scm ();
3194 unsmob_music (*destination)->
3195 set_property ("origin", make_input (last_input_));
3197 bool is_event = mus->is_mus_type ("post-event");
3199 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3200 } else if (unsmob_pitch (sid)) {
3201 *destination = unsmob_pitch (sid)->smobbed_copy ();
3202 return PITCH_IDENTIFIER;
3203 } else if (unsmob_duration (sid)) {
3204 *destination = unsmob_duration (sid)->smobbed_copy ();
3205 return DURATION_IDENTIFIER;
3206 } else if (unsmob_output_def (sid)) {
3207 Output_def *p = unsmob_output_def (sid);
3210 *destination = p->self_scm ();
3212 return OUTPUT_DEF_IDENTIFIER;
3213 } else if (Text_interface::is_markup (sid)) {
3215 if (is_lyric_state ())
3216 return LYRIC_MARKUP_IDENTIFIER;
3217 return MARKUP_IDENTIFIER;
3218 } else if (Text_interface::is_markup_list (sid)) {
3220 return MARKUPLIST_IDENTIFIER;
3227 get_next_unique_context_id ()
3229 return scm_from_locale_string ("$uniqueContextId");
3234 get_next_unique_lyrics_context_id ()
3236 static int new_context_count;
3238 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3239 return scm_from_locale_string (s);
3242 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3243 SCM arg, SCM args, SCM pred)
3245 args = scm_cons (arg, args);
3246 if (scm_is_true (scm_call_1 (pred, arg)))
3248 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3249 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3250 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3254 SCM loc_on_music (Input loc, SCM arg)
3256 if (Music *m = unsmob_music (arg))
3260 return m->unprotect ();
3266 is_regular_identifier (SCM id)
3268 string str = ly_scm2string (id);
3269 char const *s = str.c_str ();
3278 v = v && isalnum (*s);
3285 make_music_with_input (SCM name, Input where)
3287 Music *m = make_music_by_name (name);
3288 m->set_spot (where);
3293 make_simple_markup (SCM a)
3301 return t && t == 1 << intlog2 (t);
3305 set_music_properties (Music *p, SCM a)
3307 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3308 p->set_property (scm_caar (k), scm_cdar (k));
3313 make_chord_step (int step, Rational alter)
3316 alter += FLAT_ALTERATION;
3320 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3321 return m.smobbed_copy ();
3326 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
3328 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3329 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
3333 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3335 Lily_lexer *lex = parser->lexer_;
3339 lex->prepare_for_next_token ();
3340 return lex->yylex ();