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_arg
463 %type <scm> context_mod_embedded
464 %type <scm> context_mod_list
465 %type <scm> context_prop_spec
466 %type <scm> direction_less_char
467 %type <scm> duration_length
468 %type <scm> embedded_scm
469 %type <scm> embedded_scm_arg
470 %type <scm> embedded_scm_arg_closed
471 %type <scm> embedded_scm_bare
472 %type <scm> embedded_scm_bare_arg
473 %type <scm> embedded_scm_closed
474 %type <scm> event_function_event
475 %type <scm> figure_list
476 %type <scm> figure_spec
478 %type <scm> full_markup
479 %type <scm> full_markup_list
480 %type <scm> function_arglist
481 %type <scm> function_arglist_optional
482 %type <scm> function_arglist_backup
483 %type <scm> function_arglist_nonbackup
484 %type <scm> function_arglist_skip
485 %type <scm> function_arglist_bare
486 %type <scm> function_arglist_closed
487 %type <scm> function_arglist_closed_optional
488 %type <scm> function_arglist_common
489 %type <scm> function_arglist_common_lyric
490 %type <scm> function_arglist_common_minus
491 %type <scm> function_arglist_closed_common
492 %type <scm> function_arglist_keep
493 %type <scm> function_arglist_closed_keep
494 %type <scm> identifier_init
496 %type <scm> lilypond_header
497 %type <scm> lilypond_header_body
498 %type <scm> lyric_element
499 %type <scm> lyric_element_arg
500 %type <scm> lyric_element_music
501 %type <scm> lyric_markup
503 %type <scm> markup_braced_list
504 %type <scm> markup_braced_list_body
505 %type <scm> markup_composed_list
506 %type <scm> markup_command_list
507 %type <scm> markup_command_list_arguments
508 %type <scm> markup_command_basic_arguments
509 %type <scm> markup_head_1_item
510 %type <scm> markup_head_1_list
511 %type <scm> markup_list
512 %type <scm> markup_top
513 %type <scm> maybe_notemode_duration
514 %type <scm> mode_changing_head
515 %type <scm> mode_changing_head_with_context
516 %type <scm> multiplied_duration
517 %type <scm> music_function_event
518 %type <scm> music_function_chord_body
519 %type <scm> new_chord
520 %type <scm> new_lyrics
521 %type <scm> number_expression
522 %type <scm> number_factor
523 %type <scm> number_term
524 %type <scm> octave_check
525 %type <scm> optional_context_mod
526 %type <scm> optional_id
527 %type <scm> optional_notemode_duration
529 %type <scm> pitch_also_in_chords
530 %type <scm> post_events
531 %type <scm> property_operation
532 %type <scm> property_path property_path_revved
534 %type <scm> scalar_closed
535 %type <scm> scm_function_call
536 %type <scm> scm_function_call_closed
537 %type <scm> script_abbreviation
538 %type <scm> simple_chord_elements
539 %type <scm> simple_markup
540 %type <scm> simple_string
541 %type <scm> steno_duration
542 %type <scm> steno_pitch
543 %type <scm> steno_tonic_pitch
544 %type <scm> step_number
545 %type <scm> step_numbers
547 %type <scm> tempo_range
549 %type <score> score_block
550 %type <score> score_body
555 /* We don't assign precedence to / and *, because we might need varied
556 prec levels in different prods */
565 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
566 parser->lexer_->push_note_state (alist_to_hashq (nn));
567 } embedded_lilypond {
568 parser->lexer_->pop_state ();
569 parser->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
573 lilypond: /* empty */ { }
574 | lilypond toplevel_expression {
576 | lilypond assignment {
579 parser->error_level_ = 1;
582 parser->error_level_ = 1;
589 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
593 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
594 scm_call_2 (proc, parser->self_scm (), book->self_scm ());
599 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
600 scm_call_2 (proc, parser->self_scm (), bookpart->self_scm ());
601 bookpart->unprotect ();
606 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
607 scm_call_2 (proc, parser->self_scm (), score->self_scm ());
611 Music *music = unsmob_music ($1);
612 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
613 scm_call_2 (proc, parser->self_scm (), music->self_scm ());
616 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
617 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
620 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
621 scm_call_2 (proc, parser->self_scm (), $1);
625 Output_def * od = $1;
627 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
628 id = ly_symbol2scm ("$defaultpaper");
629 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
630 id = ly_symbol2scm ("$defaultmidi");
631 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
632 id = ly_symbol2scm ("$defaultlayout");
634 parser->lexer_->set_identifier (id, od->self_scm ());
642 $$ = parser->lexer_->eval_scm ($1);
647 embedded_scm_bare_arg:
653 | context_modification
656 $$ = $1->self_scm ();
659 | context_def_spec_block
662 $$ = $1->self_scm ();
667 $$ = $1->self_scm ();
672 $$ = $1->self_scm ();
677 /* The generic version may end in music, or not */
685 embedded_scm_bare_arg
691 SCM_FUNCTION function_arglist {
692 $$ = MAKE_SYNTAX ("music-function", @$,
700 $$ = MAKE_SYNTAX ("void-music", @$);
703 | music music music_list {
704 $$ = MAKE_SYNTAX ("sequential-music", @$,
705 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
708 parser->error_level_ = 1;
710 | INVALID embedded_lilypond {
711 parser->error_level_ = 1;
716 lilypond_header_body:
718 $$ = get_header (parser);
719 parser->lexer_->add_scope ($$);
721 | lilypond_header_body assignment {
727 HEADER '{' lilypond_header_body '}' {
728 $$ = parser->lexer_->remove_scope ();
737 | LYRICS_STRING { $$ = $1; }
741 assignment_id '=' identifier_init {
742 parser->lexer_->set_identifier ($1, $3);
744 | assignment_id property_path '=' identifier_init {
745 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
746 parser->lexer_->set_identifier (path, $4);
749 TODO: devise standard for protection in parser.
751 The parser stack lives on the C-stack, which means that
752 all objects can be unprotected as soon as they're here.
762 $$ = $1->self_scm ();
766 $$ = $1->self_scm ();
770 $$ = $1->self_scm ();
774 $$ = $1->self_scm ();
777 | context_def_spec_block {
783 | post_event_nofinger {
786 | number_expression {
804 | context_modification {
809 context_def_spec_block:
810 CONTEXT '{' context_def_spec_body '}'
821 context_mod_embedded:
824 if (unsmob_music ($1)) {
825 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
826 $1 = scm_call_2 (proc, parser->self_scm (), $1);
828 if (unsmob_context_mod ($1))
831 parser->parser_error (@1, _ ("not a context mod"));
837 context_def_spec_body:
839 $$ = Context_def::make_scm ();
840 unsmob_context_def ($$)->origin ()->set_spot (@$);
842 | CONTEXT_DEF_IDENTIFIER {
844 unsmob_context_def ($$)->origin ()->set_spot (@$);
846 | context_def_spec_body context_mod {
847 unsmob_context_def ($$)->add_context_mod ($2);
849 | context_def_spec_body context_modification {
850 Context_def *td = unsmob_context_def ($$);
851 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
852 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
853 td->add_context_mod (scm_car (m));
856 | context_def_spec_body context_mod_embedded {
857 Context_def *td = unsmob_context_def ($$);
858 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
859 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
860 td->add_context_mod (scm_car (m));
868 BOOK '{' book_body '}' {
871 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
876 * Use 'handlers' like for toplevel-* stuff?
877 * grok \layout and \midi? */
881 init_papers (parser);
882 $$->origin ()->set_spot (@$);
883 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
884 $$->paper_->unprotect ();
885 push_paper (parser, $$->paper_);
886 $$->header_ = parser->lexer_->lookup_identifier ("$defaultheader");
887 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
890 $$ = unsmob_book ($1);
892 $$->origin ()->set_spot (@$);
893 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
895 | book_body paper_block {
898 set_paper (parser, $2);
900 | book_body bookpart_block {
902 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
903 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
904 bookpart->unprotect ();
906 | book_body score_block {
908 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
909 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
912 | book_body composite_music {
913 Music *music = unsmob_music ($2);
914 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
915 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
917 | book_body full_markup {
918 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
919 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
921 | book_body full_markup_list {
922 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
923 scm_call_2 (proc, $$->self_scm (), $2);
925 | book_body lilypond_header {
928 | book_body embedded_scm { }
931 $$->scores_ = SCM_EOL;
932 $$->bookparts_ = SCM_EOL;
937 BOOKPART '{' bookpart_body '}' {
939 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
946 $$->origin ()->set_spot (@$);
947 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
950 $$ = unsmob_book ($1);
952 $$->origin ()->set_spot (@$);
953 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
955 | bookpart_body paper_block {
959 | bookpart_body score_block {
961 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
962 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
965 | bookpart_body composite_music {
966 Music *music = unsmob_music ($2);
967 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
968 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
970 | bookpart_body full_markup {
971 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
972 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
974 | bookpart_body full_markup_list {
975 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
976 scm_call_2 (proc, $$->self_scm (), $2);
978 | bookpart_body lilypond_header {
981 | bookpart_body embedded_scm { }
982 | bookpart_body error {
984 $$->scores_ = SCM_EOL;
989 SCORE '{' score_body '}' {
997 SCM scorify = ly_lily_module_constant ("scorify-music");
998 SCM score = scm_call_2 (scorify, m, parser->self_scm ());
1000 // pass ownernship to C++ again.
1001 $$ = unsmob_score (score);
1003 $$->origin ()->set_spot (@$);
1005 | SCORE_IDENTIFIER {
1006 $$ = unsmob_score ($1);
1008 $$->origin ()->set_spot (@$);
1010 | score_body lilypond_header {
1011 $$->set_header ($2);
1013 | score_body output_def {
1014 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
1016 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1021 $$->add_output_def ($2);
1025 | score_body error {
1026 $$->error_found_ = true;
1038 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1040 parser->parser_error (@1, _ ("need \\paper for paper block"));
1042 $$ = get_paper (parser);
1049 output_def_body '}' {
1052 parser->lexer_->remove_scope ();
1053 parser->lexer_->pop_state ();
1059 $$ = get_paper (parser);
1060 $$->input_origin_ = @$;
1061 parser->lexer_->add_scope ($$->scope_);
1064 Output_def *p = get_midi (parser);
1066 parser->lexer_->add_scope (p->scope_);
1069 Output_def *p = get_layout (parser);
1071 parser->lexer_->add_scope (p->scope_);
1076 output_def_head_with_mode_switch:
1078 parser->lexer_->push_initial_state ();
1084 output_def_head_with_mode_switch '{' {
1086 $$->input_origin_.set_spot (@$);
1088 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1091 Output_def *o = unsmob_output_def ($3);
1092 o->input_origin_.set_spot (@$);
1095 parser->lexer_->remove_scope ();
1096 parser->lexer_->add_scope (o->scope_);
1098 | output_def_body assignment {
1101 | output_def_body context_def_spec_block {
1102 assign_context_def ($$, $2);
1104 | output_def_body music_arg {
1105 SCM proc = parser->lexer_->lookup_identifier ("output-def-music-handler");
1106 scm_call_3 (proc, parser->self_scm (), $1->self_scm (), $2);
1108 | output_def_body error {
1114 TEMPO steno_duration '=' tempo_range {
1115 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1117 | TEMPO scalar_closed steno_duration '=' tempo_range {
1118 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1121 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1126 The representation of a list is reversed to have efficient append. */
1132 | music_list music {
1133 $$ = scm_cons ($2, $1);
1135 | music_list embedded_scm {
1138 | music_list error {
1139 Music *m = MY_MAKE_MUSIC("Music", @$);
1141 m->set_property ("error-found", SCM_BOOL_T);
1142 $$ = scm_cons (m->self_scm (), $1);
1143 m->unprotect (); /* UGH */
1150 $$ = scm_reverse_x ($2, SCM_EOL);
1155 | lyric_element_music
1161 if (unsmob_pitch ($1)) {
1162 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
1163 n->set_property ("pitch", $1);
1164 n->set_property ("duration",
1165 parser->default_duration_.smobbed_copy ());
1166 $$ = n->unprotect ();
1169 | composite_music %prec COMPOSITE
1174 | composite_music %prec COMPOSITE
1175 | lyric_element_music
1179 REPEAT simple_string unsigned_number music
1181 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1183 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1185 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1190 SEQUENTIAL braced_music_list {
1191 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1193 | braced_music_list {
1194 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1199 SIMULTANEOUS braced_music_list {
1200 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1202 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1203 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1209 | music_property_def
1213 context_modification:
1214 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1216 parser->lexer_->pop_state ();
1219 | WITH CONTEXT_MOD_IDENTIFIER
1223 | CONTEXT_MOD_IDENTIFIER
1227 | WITH embedded_scm_closed
1229 if (unsmob_context_mod ($2))
1232 parser->parser_error (@2, _ ("not a context mod"));
1233 $$ = Context_mod ().smobbed_copy ();
1238 optional_context_mod:
1242 | context_modification
1250 $$ = Context_mod ().smobbed_copy ();
1252 | context_mod_list context_mod {
1253 unsmob_context_mod ($1)->add_context_mod ($2);
1255 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1256 Context_mod *md = unsmob_context_mod ($2);
1258 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1260 | context_mod_list context_mod_embedded {
1261 unsmob_context_mod ($1)->add_context_mods
1262 (unsmob_context_mod ($2)->get_mods ());
1271 /* Music that can be parsed without lookahead */
1274 | complex_music_prefix closed_music
1276 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1283 | grouped_music_list
1287 simultaneous_music { $$ = $1; }
1288 | sequential_music { $$ = $1; }
1291 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1292 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1293 and this rule returns the reversed list of arguments. */
1295 function_arglist_skip:
1296 function_arglist_common
1297 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1299 $$ = scm_cons ($1, $3);
1300 } %prec FUNCTION_ARGLIST
1301 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1303 $$ = scm_cons ($1, $3);
1304 } %prec FUNCTION_ARGLIST
1305 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1307 $$ = scm_cons ($1, $3);
1308 } %prec FUNCTION_ARGLIST
1312 function_arglist_nonbackup:
1313 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1314 $$ = scm_cons ($4, $3);
1316 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1317 $$ = scm_cons ($4, $3);
1319 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1321 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1323 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1325 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1327 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1329 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1331 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1333 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1335 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1337 SCM n = scm_difference ($5, SCM_UNDEFINED);
1338 if (scm_is_true (scm_call_1 ($2, n)))
1339 $$ = scm_cons (n, $3);
1341 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1342 t->set_property ("digit", $5);
1343 $$ = t->unprotect ();
1344 if (scm_is_true (scm_call_1 ($2, $$)))
1345 $$ = scm_cons ($$, $3);
1347 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1351 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1353 $$ = check_scheme_arg (parser, @4,
1354 scm_difference ($5, SCM_UNDEFINED),
1357 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1359 $$ = check_scheme_arg (parser, @4,
1360 scm_difference ($5, SCM_UNDEFINED),
1366 function_arglist_keep:
1367 function_arglist_common
1368 | function_arglist_backup
1371 function_arglist_closed_keep:
1372 function_arglist_closed_common
1373 | function_arglist_backup
1376 function_arglist_backup:
1377 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1379 if (scm_is_true (scm_call_1 ($2, $4)))
1381 $$ = scm_cons ($4, $3);
1383 $$ = scm_cons (loc_on_music (@3, $1), $3);
1384 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1387 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1389 if (scm_is_true (scm_call_1 ($2, $4)))
1391 $$ = scm_cons ($4, $3);
1393 $$ = scm_cons (loc_on_music (@3, $1), $3);
1394 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1397 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1399 // There is no point interpreting a lyrics string as
1400 // an event, since we don't allow music possibly
1401 // followed by durations or postevent into closed
1402 // music, and we only accept closed music in optional
1403 // arguments at the moment. If this changes, more
1404 // complex schemes might become interesting here as
1405 // well: see how we do this at the mandatory argument
1407 if (scm_is_true (scm_call_1 ($2, $4)))
1408 $$ = scm_cons ($4, $3);
1410 $$ = scm_cons (loc_on_music (@3, $1), $3);
1411 MYBACKUP (LYRICS_STRING, $4, @4);
1414 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1416 if (scm_is_true (scm_call_1 ($2, $4)))
1419 MYREPARSE (@4, $2, UNSIGNED, $4);
1421 $$ = scm_cons (loc_on_music (@3, $1), $3);
1422 MYBACKUP (UNSIGNED, $4, @4);
1425 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1427 if (scm_is_true (scm_call_1 ($2, $4)))
1430 MYREPARSE (@4, $2, REAL, $4);
1432 $$ = scm_cons (loc_on_music (@3, $1), $3);
1433 MYBACKUP (REAL, $4, @4);
1436 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1438 if (scm_is_true (scm_call_1 ($2, $4)))
1440 $$ = scm_cons ($4, $3);
1442 $$ = scm_cons (loc_on_music (@3, $1), $3);
1443 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1446 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1448 if (scm_is_true (scm_call_1 ($2, $4)))
1450 $$ = scm_cons ($4, $3);
1452 $$ = scm_cons (loc_on_music (@3, $1), $3);
1453 MYBACKUP (FRACTION, $4, @4);
1456 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1458 SCM n = scm_difference ($5, SCM_UNDEFINED);
1459 if (scm_is_true (scm_call_1 ($2, n))) {
1461 MYREPARSE (@5, $2, REAL, n);
1463 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1464 t->set_property ("digit", $5);
1465 $$ = t->unprotect ();
1466 if (scm_is_true (scm_call_1 ($2, $$)))
1467 $$ = scm_cons ($$, $3);
1469 $$ = scm_cons (loc_on_music (@3, $1), $3);
1470 MYBACKUP (UNSIGNED, $5, @5);
1471 parser->lexer_->push_extra_token ('-');
1476 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1478 SCM n = scm_difference ($5, SCM_UNDEFINED);
1479 if (scm_is_true (scm_call_1 ($2, n))) {
1480 MYREPARSE (@5, $2, REAL, n);
1483 MYBACKUP (REAL, n, @5);
1486 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1488 SCM n = scm_difference ($5, SCM_UNDEFINED);
1489 if (scm_is_true (scm_call_1 ($2, n))) {
1490 $$ = scm_cons (n, $3);
1492 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1495 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1497 $$ = scm_cons ($4, $3);
1499 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1501 $$ = scm_cons ($4, $3);
1503 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1505 $$ = scm_cons ($1, $3);
1506 MYBACKUP(0, SCM_UNDEFINED, @3);
1508 | function_arglist_backup REPARSE embedded_scm_arg_closed
1510 $$ = check_scheme_arg (parser, @3,
1513 | function_arglist_backup REPARSE bare_number
1515 $$ = check_scheme_arg (parser, @3,
1518 | function_arglist_backup REPARSE fraction
1520 $$ = check_scheme_arg (parser, @3,
1526 function_arglist_common
1527 | function_arglist_nonbackup
1530 function_arglist_common:
1531 function_arglist_bare
1532 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1534 $$ = check_scheme_arg (parser, @3,
1537 | EXPECT_SCM function_arglist_closed_optional bare_number
1539 $$ = check_scheme_arg (parser, @3,
1542 | EXPECT_SCM function_arglist_closed_optional fraction
1544 $$ = check_scheme_arg (parser, @3,
1547 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1549 $$ = check_scheme_arg (parser, @3,
1552 | function_arglist_common_minus
1553 | function_arglist_common_lyric
1556 function_arglist_common_lyric:
1557 EXPECT_SCM function_arglist_optional lyric_element
1559 // We check how the predicate thinks about a lyrics
1560 // event or about a markup. If it accepts neither, we
1561 // backup the original token. Otherwise we commit to
1562 // taking the token. Depending on what the predicate
1563 // is willing to accept, we interpret as a string, as
1564 // a lyric event, or ambiguously (meaning that if
1565 // something looking like a duration or post event
1566 // follows, we take the event, otherwise the string).
1567 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1568 parser->default_duration_.smobbed_copy ());
1569 if (scm_is_true (scm_call_1 ($1, $3)))
1570 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1573 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1575 $$ = scm_cons ($3, $2);
1577 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1580 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1582 // This is going to flag a syntax error, we
1583 // know the predicate to be false.
1584 check_scheme_arg (parser, @3,
1588 | function_arglist_common_lyric REPARSE lyric_element_arg
1590 // This should never be false
1591 $$ = check_scheme_arg (parser, @3,
1596 function_arglist_common_minus:
1597 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1599 SCM n = scm_difference ($4, SCM_UNDEFINED);
1600 if (scm_is_true (scm_call_1 ($1, n))) {
1602 MYREPARSE (@4, $1, REAL, n);
1604 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1605 t->set_property ("digit", $4);
1606 $$ = t->unprotect ();
1607 if (scm_is_true (scm_call_1 ($1, $$)))
1608 $$ = scm_cons ($$, $2);
1610 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1614 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1617 SCM n = scm_difference ($4, SCM_UNDEFINED);
1618 MYREPARSE (@4, $1, REAL, n);
1620 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1622 SCM n = scm_difference ($4, SCM_UNDEFINED);
1623 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1625 | function_arglist_common_minus REPARSE bare_number
1627 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1631 function_arglist_closed:
1632 function_arglist_closed_common
1633 | function_arglist_nonbackup
1636 function_arglist_closed_common:
1637 function_arglist_bare
1638 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1640 $$ = check_scheme_arg (parser, @3,
1643 | EXPECT_SCM function_arglist_closed_optional bare_number
1645 $$ = check_scheme_arg (parser, @3,
1648 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1650 SCM n = scm_difference ($4, SCM_UNDEFINED);
1651 if (scm_is_true (scm_call_1 ($1, n))) {
1652 $$ = scm_cons (n, $2);
1654 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1655 t->set_property ("digit", $4);
1656 $$ = t->unprotect ();
1657 if (scm_is_true (scm_call_1 ($1, $$)))
1658 $$ = scm_cons ($$, $2);
1660 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1664 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1666 $$ = check_scheme_arg (parser, @3,
1667 scm_difference ($4, SCM_UNDEFINED),
1670 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1672 $$ = check_scheme_arg (parser, @3,
1673 scm_difference ($4, SCM_UNDEFINED),
1676 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1678 $$ = check_scheme_arg (parser, @3,
1681 | EXPECT_SCM function_arglist_closed_optional fraction
1683 $$ = check_scheme_arg (parser, @3,
1686 | EXPECT_SCM function_arglist_optional lyric_element
1688 $$ = check_scheme_arg (parser, @3,
1693 function_arglist_optional:
1694 function_arglist_keep %prec FUNCTION_ARGLIST
1695 | function_arglist_backup BACKUP
1696 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1698 $$ = scm_cons ($1, $3);
1700 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1702 $$ = scm_cons ($1, $3);
1706 function_arglist_closed_optional:
1707 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1708 | function_arglist_backup BACKUP
1709 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1711 $$ = scm_cons ($1, $3);
1713 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1715 $$ = scm_cons ($1, $3);
1719 embedded_scm_closed:
1721 | scm_function_call_closed
1724 embedded_scm_arg_closed:
1725 embedded_scm_bare_arg
1726 | scm_function_call_closed
1730 scm_function_call_closed:
1731 SCM_FUNCTION function_arglist_closed {
1732 $$ = MAKE_SYNTAX ("music-function", @$,
1734 } %prec FUNCTION_ARGLIST
1737 function_arglist_bare:
1738 EXPECT_NO_MORE_ARGS {
1741 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1742 $$ = scm_cons ($3, $2);
1744 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1745 $$ = scm_cons ($3, $2);
1747 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1748 $$ = scm_cons ($1, $3);
1750 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1751 $$ = scm_cons ($1, $3);
1753 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1754 $$ = scm_cons ($1, $3);
1758 music_function_call:
1759 MUSIC_FUNCTION function_arglist {
1760 $$ = MAKE_SYNTAX ("music-function", @$,
1767 /**/ { $$ = SCM_EOL; }
1768 | '=' simple_string {
1775 | repeated_music { $$ = $1; }
1776 | re_rhythmed_music { $$ = $1; }
1777 | complex_music_prefix music
1779 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1783 complex_music_prefix:
1784 CONTEXT simple_string optional_id optional_context_mod {
1785 Context_mod *ctxmod = unsmob_context_mod ($4);
1788 mods = ctxmod->get_mods ();
1789 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1791 | NEWCONTEXT simple_string optional_id optional_context_mod {
1792 Context_mod *ctxmod = unsmob_context_mod ($4);
1795 mods = ctxmod->get_mods ();
1796 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1801 mode_changing_head grouped_music_list {
1802 if ($1 == ly_symbol2scm ("chords"))
1804 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1810 parser->lexer_->pop_state ();
1812 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1813 Context_mod *ctxmod = unsmob_context_mod ($2);
1816 mods = ctxmod->get_mods ();
1817 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1818 if ($1 == ly_symbol2scm ("ChordNames"))
1820 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1822 parser->lexer_->pop_state ();
1828 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1829 parser->lexer_->push_note_state (alist_to_hashq (nn));
1831 $$ = ly_symbol2scm ("notes");
1835 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1836 parser->lexer_->push_note_state (alist_to_hashq (nn));
1838 $$ = ly_symbol2scm ("drums");
1841 parser->lexer_->push_figuredbass_state ();
1843 $$ = ly_symbol2scm ("figures");
1846 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1847 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1848 nn = parser->lexer_->lookup_identifier ("pitchnames");
1849 parser->lexer_->push_chord_state (alist_to_hashq (nn));
1850 $$ = ly_symbol2scm ("chords");
1854 { parser->lexer_->push_lyric_state ();
1855 $$ = ly_symbol2scm ("lyrics");
1859 mode_changing_head_with_context:
1861 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1862 parser->lexer_->push_note_state (alist_to_hashq (nn));
1864 $$ = ly_symbol2scm ("DrumStaff");
1867 parser->lexer_->push_figuredbass_state ();
1869 $$ = ly_symbol2scm ("FiguredBass");
1872 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1873 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1874 nn = parser->lexer_->lookup_identifier ("pitchnames");
1875 parser->lexer_->push_chord_state (alist_to_hashq (nn));
1876 $$ = ly_symbol2scm ("ChordNames");
1879 { parser->lexer_->push_lyric_state ();
1880 $$ = ly_symbol2scm ("Lyrics");
1885 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1888 /* Can also use music at the expensive of two S/Rs similar to
1889 \repeat \alternative */
1890 parser->lexer_->pop_state ();
1892 $$ = scm_cons ($3, SCM_EOL);
1894 | new_lyrics ADDLYRICS {
1895 parser->lexer_->push_lyric_state ();
1897 parser->lexer_->pop_state ();
1898 $$ = scm_cons ($4, $1);
1903 composite_music new_lyrics {
1904 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1906 | LYRICSTO simple_string {
1907 parser->lexer_->push_lyric_state ();
1909 parser->lexer_->pop_state ();
1910 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1915 CHANGE STRING '=' STRING {
1916 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1921 property_path_revved:
1922 embedded_scm_closed {
1923 $$ = scm_cons ($1, SCM_EOL);
1925 | property_path_revved embedded_scm_closed {
1926 $$ = scm_cons ($2, $1);
1931 property_path_revved {
1932 $$ = scm_reverse_x ($1, SCM_EOL);
1938 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1939 scm_string_to_symbol ($1), $3);
1941 | UNSET simple_string {
1942 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1943 scm_string_to_symbol ($2));
1945 | OVERRIDE simple_string property_path '=' scalar {
1946 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1947 scm_string_to_symbol ($2), $5),
1950 | REVERT simple_string embedded_scm {
1951 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1952 scm_string_to_symbol ($2), $3);
1957 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1958 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1960 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1961 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1962 | DENIES { $$ = ly_symbol2scm ("denies"); }
1964 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1965 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1966 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1967 | NAME { $$ = ly_symbol2scm ("context-name"); }
1971 property_operation { $$ = $1; }
1972 | context_def_mod STRING {
1973 $$ = scm_list_2 ($1, $2);
1975 | context_def_mod embedded_scm
1977 if (!scm_is_string ($2)
1978 && ly_symbol2scm ("consists") != $1
1979 && ly_symbol2scm ("remove") != $1)
1982 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
1986 $$ = scm_list_2 ($1, $2);
1993 if (!is_regular_identifier ($1))
1995 @$.error (_("Grob name should be alphanumeric"));
1998 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1999 scm_string_to_symbol ($1));
2001 | simple_string '.' simple_string {
2002 $$ = scm_list_2 (scm_string_to_symbol ($1),
2003 scm_string_to_symbol ($3));
2007 simple_music_property_def:
2008 OVERRIDE context_prop_spec property_path '=' scalar {
2009 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
2010 ly_symbol2scm ("OverrideProperty"),
2015 | REVERT context_prop_spec embedded_scm {
2016 $$ = scm_list_4 (scm_car ($2),
2017 ly_symbol2scm ("RevertProperty"),
2021 | SET context_prop_spec '=' scalar {
2022 $$ = scm_list_4 (scm_car ($2),
2023 ly_symbol2scm ("PropertySet"),
2027 | UNSET context_prop_spec {
2028 $$ = scm_list_3 (scm_car ($2),
2029 ly_symbol2scm ("PropertyUnset"),
2035 simple_music_property_def {
2036 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2044 | STRING_IDENTIFIER {
2047 | string '+' string {
2048 $$ = scm_string_append (scm_list_2 ($1, $3));
2052 simple_string: STRING {
2058 | STRING_IDENTIFIER {
2071 embedded_scm_arg_closed
2079 simple_element post_events {
2080 // Let the rhythmic music iterator sort this mess out.
2081 if (scm_is_pair ($2)) {
2082 if (unsmob_pitch ($1)) {
2083 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
2084 n->set_property ("pitch", $1);
2085 n->set_property ("duration",
2086 parser->default_duration_.smobbed_copy ());
2087 $$ = n->unprotect ();
2089 unsmob_music ($$)->set_property ("articulations",
2090 scm_reverse_x ($2, SCM_EOL));
2093 | simple_chord_elements post_events {
2094 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2097 /* why is this giving wrong start location? -ns
2099 i.set_location (@1, @2);
2100 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2102 | CHORD_REPETITION optional_notemode_duration post_events {
2104 i.set_location (@1, @3);
2105 $$ = MAKE_SYNTAX ("repetition-chord", i,
2106 $2, scm_reverse_x ($3, SCM_EOL));
2108 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2110 i.set_location (@1, @3);
2111 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2112 scm_reverse_x ($3, SCM_EOL));
2115 | note_chord_element
2120 chord_body optional_notemode_duration post_events
2122 Music *m = unsmob_music ($1);
2123 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2124 SCM es = m->get_property ("elements");
2125 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2127 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2128 unsmob_music (scm_car (s))->set_property ("duration", dur);
2129 es = ly_append2 (es, postevs);
2131 m-> set_property ("elements", es);
2133 $$ = m->self_scm ();
2138 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2140 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2144 chord_body_elements:
2145 /* empty */ { $$ = SCM_EOL; }
2146 | chord_body_elements chord_body_element {
2147 if (!SCM_UNBNDP ($2))
2148 $$ = scm_cons ($2, $1);
2153 pitch exclamations questions octave_check post_events
2160 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2161 n->set_property ("pitch", $1);
2163 n->set_property ("cautionary", SCM_BOOL_T);
2164 if (ex % 2 || q % 2)
2165 n->set_property ("force-accidental", SCM_BOOL_T);
2167 if (scm_is_pair (post)) {
2168 SCM arts = scm_reverse_x (post, SCM_EOL);
2169 n->set_property ("articulations", arts);
2171 if (scm_is_number (check))
2173 int q = scm_to_int (check);
2174 n->set_property ("absolute-octave", scm_from_int (q-1));
2177 $$ = n->unprotect ();
2179 | DRUM_PITCH post_events {
2180 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2181 n->set_property ("drum-type", $1);
2183 if (scm_is_pair ($2)) {
2184 SCM arts = scm_reverse_x ($2, SCM_EOL);
2185 n->set_property ("articulations", arts);
2187 $$ = n->unprotect ();
2189 | music_function_chord_body
2191 Music *m = unsmob_music ($1);
2193 while (m && m->is_mus_type ("music-wrapper-music")) {
2194 $$ = m->get_property ("element");
2195 m = unsmob_music ($$);
2198 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2199 parser->parser_error (@$, _ ("not a rhythmic event"));
2205 music_function_chord_body:
2210 // Event functions may only take closed arglists, otherwise it would
2211 // not be clear whether a following postevent should be associated
2212 // with the last argument of the event function or with the expression
2213 // for which the function call acts itself as event.
2215 music_function_event:
2216 MUSIC_FUNCTION function_arglist_closed {
2217 $$ = MAKE_SYNTAX ("music-function", @$,
2222 event_function_event:
2223 EVENT_FUNCTION function_arglist_closed {
2224 $$ = MAKE_SYNTAX ("music-function", @$,
2234 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2235 m->set_property ("span-direction", scm_from_int (START));
2236 $$ = m->unprotect();
2239 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2240 m->set_property ("span-direction", scm_from_int (STOP));
2241 $$ = m->unprotect ();
2244 $$ = MAKE_SYNTAX ("voice-separator", @$);
2247 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2249 Music *m = unsmob_music (pipe);
2254 $$ = m->unprotect ();
2257 $$ = MAKE_SYNTAX ("bar-check", @$);
2264 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2276 | post_events post_event {
2277 unsmob_music ($2)->set_spot (@2);
2278 $$ = scm_cons ($2, $$);
2282 post_event_nofinger:
2283 direction_less_event {
2286 | script_dir music_function_event {
2290 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2294 if (!parser->lexer_->is_lyric_state ())
2295 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2296 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2299 if (!parser->lexer_->is_lyric_state ())
2300 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2301 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2303 | script_dir direction_reqd_event {
2306 Music *m = unsmob_music ($2);
2307 m->set_property ("direction", scm_from_int ($1));
2311 | script_dir direction_less_event {
2314 Music *m = unsmob_music ($2);
2315 m->set_property ("direction", scm_from_int ($1));
2319 | string_number_event
2323 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2328 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2339 string_number_event:
2341 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2342 s->set_property ("string-number", scm_from_int ($1));
2343 $$ = s->unprotect ();
2347 direction_less_char:
2349 $$ = ly_symbol2scm ("bracketOpenSymbol");
2352 $$ = ly_symbol2scm ("bracketCloseSymbol");
2355 $$ = ly_symbol2scm ("tildeSymbol");
2358 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2361 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2364 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2367 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2370 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2373 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2376 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2380 direction_less_event:
2381 direction_less_char {
2382 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2384 if (unsmob_music (predefd))
2386 m = unsmob_music (predefd)->clone ();
2391 m = MY_MAKE_MUSIC ("Music", @$);
2393 $$ = m->unprotect ();
2395 | EVENT_IDENTIFIER {
2399 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2400 a->set_property ("tremolo-type", scm_from_int ($1));
2401 $$ = a->unprotect ();
2403 | event_function_event
2406 direction_reqd_event:
2410 | script_abbreviation {
2411 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2412 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2413 if (scm_is_string (s))
2414 a->set_property ("articulation-type", s);
2415 else parser->parser_error (@1, _ ("expecting string as script definition"));
2416 $$ = a->unprotect ();
2421 /**/ { $$ = SCM_EOL; }
2422 | '=' { $$ = scm_from_int (0); }
2423 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2424 | '=' sup_quotes { $$ = scm_from_int ($2); }
2449 | NOTENAME_PITCH sup_quotes {
2450 Pitch p = *unsmob_pitch ($1);
2451 p = p.transposed (Pitch ($2,0,0));
2452 $$ = p.smobbed_copy ();
2454 | NOTENAME_PITCH sub_quotes {
2455 Pitch p =* unsmob_pitch ($1);
2456 p = p.transposed (Pitch (-$2,0,0));
2457 $$ = p.smobbed_copy ();
2469 | TONICNAME_PITCH sup_quotes {
2470 Pitch p = *unsmob_pitch ($1);
2471 p = p.transposed (Pitch ($2,0,0));
2472 $$ = p.smobbed_copy ();
2474 | TONICNAME_PITCH sub_quotes {
2475 Pitch p = *unsmob_pitch ($1);
2477 p = p.transposed (Pitch (-$2,0,0));
2478 $$ = p.smobbed_copy ();
2489 pitch_also_in_chords:
2496 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2497 t->set_property ("text", $1);
2498 $$ = t->unprotect ();
2501 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2502 t->set_property ("text",
2503 make_simple_markup ($1));
2504 $$ = t->unprotect ();
2510 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2511 t->set_property ("digit", $1);
2512 $$ = t->unprotect ();
2516 script_abbreviation:
2518 $$ = scm_from_locale_string ("Hat");
2521 $$ = scm_from_locale_string ("Plus");
2524 $$ = scm_from_locale_string ("Dash");
2527 $$ = scm_from_locale_string ("Bar");
2530 $$ = scm_from_locale_string ("Larger");
2533 $$ = scm_from_locale_string ("Dot");
2536 $$ = scm_from_locale_string ("Underscore");
2543 | '-' { $$ = CENTER; }
2547 multiplied_duration {
2552 maybe_notemode_duration:
2556 | multiplied_duration {
2558 parser->default_duration_ = *unsmob_duration ($$);
2563 optional_notemode_duration:
2564 maybe_notemode_duration
2566 if (SCM_UNBNDP ($$))
2567 $$ = parser->default_duration_.smobbed_copy ();
2572 bare_unsigned dots {
2574 if (!is_duration ($1))
2575 parser->parser_error (@1, _f ("not a duration: %d", $1));
2579 $$ = Duration (len, $2).smobbed_copy ();
2581 | DURATION_IDENTIFIER dots {
2582 Duration *d = unsmob_duration ($1);
2583 Duration k (d->duration_log (), d->dot_count () + $2);
2584 k = k.compressed (d->factor ());
2590 multiplied_duration:
2594 | multiplied_duration '*' bare_unsigned {
2595 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2597 | multiplied_duration '*' FRACTION {
2598 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2600 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2605 FRACTION { $$ = $1; }
2606 | UNSIGNED '/' UNSIGNED {
2607 $$ = scm_cons ($1, $3);
2624 | ':' bare_unsigned {
2625 if (!is_duration ($2))
2626 parser->parser_error (@2, _f ("not a duration: %d", $2));
2632 UNSIGNED { $$ = $1; }
2633 | STRING { $$ = $1; }
2634 | full_markup { $$ = $1; }
2637 figured_bass_alteration:
2638 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2639 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2640 | '!' { $$ = scm_from_int (0); }
2645 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2646 $$ = bfr->unprotect ();
2649 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2650 $$ = bfr->self_scm ();
2652 if (scm_is_number ($1))
2653 bfr->set_property ("figure", $1);
2654 else if (Text_interface::is_markup ($1))
2655 bfr->set_property ("text", $1);
2661 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2663 | bass_figure figured_bass_alteration {
2664 Music *m = unsmob_music ($1);
2665 if (scm_to_double ($2)) {
2666 SCM salter = m->get_property ("alteration");
2667 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2668 m->set_property ("alteration",
2669 scm_sum (alter, $2));
2671 m->set_property ("alteration", scm_from_int (0));
2674 | bass_figure figured_bass_modification {
2675 Music *m = unsmob_music ($1);
2676 if ($2 == ly_symbol2scm ("plus"))
2678 m->set_property ("augmented", SCM_BOOL_T);
2680 else if ($2 == ly_symbol2scm ("slash"))
2682 m->set_property ("diminished", SCM_BOOL_T);
2684 else if ($2 == ly_symbol2scm ("exclamation"))
2686 m->set_property ("no-continuation", SCM_BOOL_T);
2688 else if ($2 == ly_symbol2scm ("backslash"))
2690 m->set_property ("augmented-slash", SCM_BOOL_T);
2696 figured_bass_modification:
2698 $$ = ly_symbol2scm ("plus");
2701 $$ = ly_symbol2scm ("exclamation");
2704 $$ = ly_symbol2scm ("slash");
2707 $$ = ly_symbol2scm ("backslash");
2717 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2725 | figure_list br_bass_figure {
2726 $$ = scm_cons ($2, $1);
2731 FIGURE_OPEN figure_list FIGURE_CLOSE {
2732 $$ = scm_reverse_x ($2, SCM_EOL);
2743 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2744 if (!parser->lexer_->is_note_state ())
2745 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2746 if ($2 || $3 || scm_is_number ($4) || !SCM_UNBNDP ($5) || $6)
2750 n = MY_MAKE_MUSIC ("RestEvent", @$);
2752 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2754 n->set_property ("pitch", $1);
2755 if (SCM_UNBNDP ($5))
2756 n->set_property ("duration",
2757 parser->default_duration_.smobbed_copy ());
2759 n->set_property ("duration", $5);
2761 if (scm_is_number ($4))
2763 int q = scm_to_int ($4);
2764 n->set_property ("absolute-octave", scm_from_int (q-1));
2768 n->set_property ("cautionary", SCM_BOOL_T);
2769 if ($2 % 2 || $3 % 2)
2770 n->set_property ("force-accidental", SCM_BOOL_T);
2772 $$ = n->unprotect ();
2775 | DRUM_PITCH optional_notemode_duration {
2776 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2777 n->set_property ("duration", $2);
2778 n->set_property ("drum-type", $1);
2780 $$ = n->unprotect ();
2782 | RESTNAME optional_notemode_duration {
2784 if (ly_scm2string ($1) == "s") {
2786 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2789 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2792 ev->set_property ("duration", $2);
2793 $$ = ev->unprotect ();
2797 simple_chord_elements:
2799 if (!parser->lexer_->is_chord_state ())
2800 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2803 | figure_spec optional_notemode_duration {
2804 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2806 unsmob_music (scm_car (s))->set_property ("duration", $2);
2823 | lyric_element multiplied_duration post_events {
2824 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2825 if (scm_is_pair ($3))
2826 unsmob_music ($$)->set_property
2827 ("articulations", scm_reverse_x ($3, SCM_EOL));
2829 | lyric_element post_event post_events {
2830 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2831 parser->default_duration_.smobbed_copy ());
2832 unsmob_music ($$)->set_property
2833 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2835 | LYRIC_ELEMENT optional_notemode_duration post_events {
2836 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2837 if (scm_is_pair ($3))
2838 unsmob_music ($$)->set_property
2839 ("articulations", scm_reverse_x ($3, SCM_EOL));
2844 lyric_element_music:
2845 lyric_element optional_notemode_duration post_events {
2846 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2847 if (scm_is_pair ($3))
2848 unsmob_music ($$)->set_property
2849 ("articulations", scm_reverse_x ($3, SCM_EOL));
2854 steno_tonic_pitch optional_notemode_duration {
2855 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2857 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2858 SCM its = scm_reverse_x ($4, SCM_EOL);
2859 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2867 | chord_items chord_item {
2868 $$ = scm_cons ($2, $$);
2874 $$ = ly_symbol2scm ("chord-colon");
2877 $$ = ly_symbol2scm ("chord-caret");
2879 | CHORD_SLASH steno_tonic_pitch {
2880 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2882 | CHORD_BASS steno_tonic_pitch {
2883 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2892 $$ = scm_reverse_x ($1, SCM_EOL);
2900 step_number { $$ = scm_cons ($1, SCM_EOL); }
2901 | step_numbers '.' step_number {
2902 $$ = scm_cons ($3, $$);
2908 $$ = make_chord_step ($1, 0);
2910 | bare_unsigned '+' {
2911 $$ = make_chord_step ($1, SHARP_ALTERATION);
2913 | bare_unsigned CHORD_MINUS {
2914 $$ = make_chord_step ($1, FLAT_ALTERATION);
2920 $$ = scm_from_int ($1);
2922 | bare_unsigned '~' bare_unsigned {
2923 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2930 TODO: should deprecate in favor of Scheme?
2934 number_expression '+' number_term {
2935 $$ = scm_sum ($1, $3);
2937 | number_expression '-' number_term {
2938 $$ = scm_difference ($1, $3);
2947 | number_factor '*' number_factor {
2948 $$ = scm_product ($1, $3);
2950 | number_factor '/' number_factor {
2951 $$ = scm_divide ($1, $3);
2956 '-' number_factor { /* %prec UNARY_MINUS */
2957 $$ = scm_difference ($2, SCM_UNDEFINED);
2965 | UNSIGNED NUMBER_IDENTIFIER {
2966 $$ = scm_product ($1, $2);
2968 | REAL NUMBER_IDENTIFIER {
2969 $$ = scm_product ($1, $2);
2981 $$ = scm_to_int ($1);
2992 | exclamations '!' { $$ ++; }
2997 | questions '?' { $$ ++; }
3001 This should be done more dynamically if possible.
3005 LYRIC_MARKUP_IDENTIFIER {
3009 { parser->lexer_->push_markup_state (); }
3012 parser->lexer_->pop_state ();
3017 MARKUPLIST_IDENTIFIER {
3021 { parser->lexer_->push_markup_state (); }
3024 parser->lexer_->pop_state ();
3033 { parser->lexer_->push_markup_state (); }
3036 parser->lexer_->pop_state ();
3042 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3044 | markup_head_1_list simple_markup {
3045 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3055 if (Text_interface::is_markup ($1))
3056 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3057 else if (Text_interface::is_markup_list ($1))
3058 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3060 parser->parser_error (@1, _ ("not a markup"));
3061 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3068 MARKUPLIST_IDENTIFIER {
3071 | markup_composed_list {
3074 | markup_braced_list {
3077 | markup_command_list {
3078 $$ = scm_list_1 ($1);
3080 | markup_scm MARKUPLIST_IDENTIFIER
3086 markup_composed_list:
3087 markup_head_1_list markup_braced_list {
3088 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3094 '{' markup_braced_list_body '}' {
3095 $$ = scm_reverse_x ($2, SCM_EOL);
3099 markup_braced_list_body:
3100 /* empty */ { $$ = SCM_EOL; }
3101 | markup_braced_list_body markup {
3102 $$ = scm_cons ($2, $1);
3104 | markup_braced_list_body markup_list {
3105 $$ = scm_reverse_x ($2, $1);
3109 markup_command_list:
3110 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3111 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3115 markup_command_basic_arguments:
3116 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3117 $$ = scm_cons ($3, $2);
3119 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3120 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3122 | EXPECT_NO_MORE_ARGS {
3127 markup_command_list_arguments:
3128 markup_command_basic_arguments { $$ = $1; }
3129 | EXPECT_MARKUP markup_command_list_arguments markup {
3130 $$ = scm_cons ($3, $2);
3135 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3136 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3141 markup_head_1_item {
3142 $$ = scm_list_1 ($1);
3144 | markup_head_1_list markup_head_1_item {
3145 $$ = scm_cons ($2, $1);
3151 $$ = make_simple_markup ($1);
3153 | MARKUP_IDENTIFIER {
3156 | LYRIC_MARKUP_IDENTIFIER {
3159 | STRING_IDENTIFIER {
3163 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3164 parser->lexer_->push_note_state (alist_to_hashq (nn));
3165 } '{' score_body '}' {
3167 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3169 parser->lexer_->pop_state ();
3171 | MARKUP_FUNCTION markup_command_basic_arguments {
3172 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3174 | markup_scm MARKUP_IDENTIFIER
3181 markup_head_1_list simple_markup {
3182 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3183 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3193 Lily_parser::set_yydebug (bool x)
3199 Lily_parser::do_yyparse ()
3210 It is a little strange to have this function in this file, but
3211 otherwise, we have to import music classes into the lexer.
3215 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3217 if (scm_is_string (sid)) {
3219 return STRING_IDENTIFIER;
3220 } else if (unsmob_book (sid)) {
3221 Book *book = unsmob_book (sid)->clone ();
3222 *destination = book->self_scm ();
3225 return BOOK_IDENTIFIER;
3226 } else if (scm_is_number (sid)) {
3228 return NUMBER_IDENTIFIER;
3229 } else if (unsmob_context_def (sid)) {
3230 Context_def *def= unsmob_context_def (sid)->clone ();
3232 *destination = def->self_scm ();
3235 return CONTEXT_DEF_IDENTIFIER;
3236 } else if (unsmob_context_mod (sid)) {
3237 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3239 return CONTEXT_MOD_IDENTIFIER;
3240 } else if (unsmob_score (sid)) {
3241 Score *score = new Score (*unsmob_score (sid));
3242 *destination = score->self_scm ();
3244 score->unprotect ();
3245 return SCORE_IDENTIFIER;
3246 } else if (Music *mus = unsmob_music (sid)) {
3247 mus = mus->clone ();
3248 *destination = mus->self_scm ();
3249 unsmob_music (*destination)->
3250 set_property ("origin", make_input (last_input_));
3252 bool is_event = mus->is_mus_type ("post-event");
3254 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3255 } else if (unsmob_pitch (sid)) {
3256 *destination = unsmob_pitch (sid)->smobbed_copy ();
3257 return PITCH_IDENTIFIER;
3258 } else if (unsmob_duration (sid)) {
3259 *destination = unsmob_duration (sid)->smobbed_copy ();
3260 return DURATION_IDENTIFIER;
3261 } else if (unsmob_output_def (sid)) {
3262 Output_def *p = unsmob_output_def (sid);
3265 *destination = p->self_scm ();
3267 return OUTPUT_DEF_IDENTIFIER;
3268 } else if (Text_interface::is_markup (sid)) {
3270 if (is_lyric_state ())
3271 return LYRIC_MARKUP_IDENTIFIER;
3272 return MARKUP_IDENTIFIER;
3273 } else if (Text_interface::is_markup_list (sid)) {
3275 return MARKUPLIST_IDENTIFIER;
3282 get_next_unique_context_id ()
3284 return scm_from_locale_string ("$uniqueContextId");
3289 get_next_unique_lyrics_context_id ()
3291 static int new_context_count;
3293 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3294 return scm_from_locale_string (s);
3297 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3298 SCM arg, SCM args, SCM pred)
3300 args = scm_cons (arg, args);
3301 if (scm_is_true (scm_call_1 (pred, arg)))
3303 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3304 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3305 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3309 SCM loc_on_music (Input loc, SCM arg)
3311 if (Music *m = unsmob_music (arg))
3315 return m->unprotect ();
3321 is_regular_identifier (SCM id)
3323 string str = ly_scm2string (id);
3324 char const *s = str.c_str ();
3333 v = v && isalnum (*s);
3340 make_music_with_input (SCM name, Input where)
3342 Music *m = make_music_by_name (name);
3343 m->set_spot (where);
3348 make_simple_markup (SCM a)
3356 return t && t == 1 << intlog2 (t);
3360 set_music_properties (Music *p, SCM a)
3362 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3363 p->set_property (scm_caar (k), scm_cdar (k));
3368 make_chord_step (int step, Rational alter)
3371 alter += FLAT_ALTERATION;
3375 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3376 return m.smobbed_copy ();
3381 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3383 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3384 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3385 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3387 unsmob_music (scm_car (s))->set_spot (loc);
3393 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3395 Lily_lexer *lex = parser->lexer_;
3399 lex->prepare_for_next_token ();
3400 return lex->yylex ();