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 {
801 | context_modification {
806 context_def_spec_block:
807 CONTEXT '{' context_def_spec_body '}'
818 context_mod_embedded:
821 if (unsmob_music ($1)) {
822 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
823 $1 = scm_call_2 (proc, parser->self_scm (), $1);
825 if (unsmob_context_mod ($1))
828 parser->parser_error (@1, _ ("not a context mod"));
834 context_def_spec_body:
836 $$ = Context_def::make_scm ();
837 unsmob_context_def ($$)->origin ()->set_spot (@$);
839 | CONTEXT_DEF_IDENTIFIER {
841 unsmob_context_def ($$)->origin ()->set_spot (@$);
843 | context_def_spec_body context_mod {
844 unsmob_context_def ($$)->add_context_mod ($2);
846 | context_def_spec_body context_modification {
847 Context_def *td = unsmob_context_def ($$);
848 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
849 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
850 td->add_context_mod (scm_car (m));
853 | context_def_spec_body context_mod_embedded {
854 Context_def *td = unsmob_context_def ($$);
855 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
856 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
857 td->add_context_mod (scm_car (m));
865 BOOK '{' book_body '}' {
868 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
873 * Use 'handlers' like for toplevel-* stuff?
874 * grok \layout and \midi? */
878 init_papers (parser);
879 $$->origin ()->set_spot (@$);
880 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
881 $$->paper_->unprotect ();
882 push_paper (parser, $$->paper_);
883 $$->header_ = parser->lexer_->lookup_identifier ("$defaultheader");
884 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
887 $$ = unsmob_book ($1);
889 $$->origin ()->set_spot (@$);
890 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
892 | book_body paper_block {
895 set_paper (parser, $2);
897 | book_body bookpart_block {
899 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
900 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
901 bookpart->unprotect ();
903 | book_body score_block {
905 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
906 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
909 | book_body composite_music {
910 Music *music = unsmob_music ($2);
911 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
912 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
914 | book_body full_markup {
915 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
916 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
918 | book_body full_markup_list {
919 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
920 scm_call_2 (proc, $$->self_scm (), $2);
922 | book_body lilypond_header {
925 | book_body embedded_scm { }
928 $$->scores_ = SCM_EOL;
929 $$->bookparts_ = SCM_EOL;
934 BOOKPART '{' bookpart_body '}' {
936 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
943 $$->origin ()->set_spot (@$);
944 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
947 $$ = unsmob_book ($1);
949 $$->origin ()->set_spot (@$);
950 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
952 | bookpart_body paper_block {
956 | bookpart_body score_block {
958 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
959 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
962 | bookpart_body composite_music {
963 Music *music = unsmob_music ($2);
964 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
965 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
967 | bookpart_body full_markup {
968 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
969 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
971 | bookpart_body full_markup_list {
972 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
973 scm_call_2 (proc, $$->self_scm (), $2);
975 | bookpart_body lilypond_header {
978 | bookpart_body embedded_scm { }
979 | bookpart_body error {
981 $$->scores_ = SCM_EOL;
986 SCORE '{' score_body '}' {
994 SCM scorify = ly_lily_module_constant ("scorify-music");
995 SCM score = scm_call_2 (scorify, m, parser->self_scm ());
997 // pass ownernship to C++ again.
998 $$ = unsmob_score (score);
1000 $$->origin ()->set_spot (@$);
1002 | SCORE_IDENTIFIER {
1003 $$ = unsmob_score ($1);
1005 $$->origin ()->set_spot (@$);
1007 | score_body lilypond_header {
1008 $$->set_header ($2);
1010 | score_body output_def {
1011 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
1013 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1018 $$->add_output_def ($2);
1022 | score_body error {
1023 $$->error_found_ = true;
1035 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1037 parser->parser_error (@1, _ ("need \\paper for paper block"));
1039 $$ = get_paper (parser);
1046 output_def_body '}' {
1049 parser->lexer_->remove_scope ();
1050 parser->lexer_->pop_state ();
1056 $$ = get_paper (parser);
1057 $$->input_origin_ = @$;
1058 parser->lexer_->add_scope ($$->scope_);
1061 Output_def *p = get_midi (parser);
1063 parser->lexer_->add_scope (p->scope_);
1066 Output_def *p = get_layout (parser);
1068 parser->lexer_->add_scope (p->scope_);
1073 output_def_head_with_mode_switch:
1075 parser->lexer_->push_initial_state ();
1081 output_def_head_with_mode_switch '{' {
1083 $$->input_origin_.set_spot (@$);
1085 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1088 Output_def *o = unsmob_output_def ($3);
1089 o->input_origin_.set_spot (@$);
1092 parser->lexer_->remove_scope ();
1093 parser->lexer_->add_scope (o->scope_);
1095 | output_def_body assignment {
1098 | output_def_body context_def_spec_block {
1099 assign_context_def ($$, $2);
1101 | output_def_body music_arg {
1102 SCM proc = parser->lexer_->lookup_identifier ("output-def-music-handler");
1103 scm_call_3 (proc, parser->self_scm (), $1->self_scm (), $2);
1105 | output_def_body error {
1111 TEMPO steno_duration '=' tempo_range {
1112 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1114 | TEMPO scalar_closed steno_duration '=' tempo_range {
1115 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1118 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1123 The representation of a list is reversed to have efficient append. */
1129 | music_list music {
1130 $$ = scm_cons ($2, $1);
1132 | music_list embedded_scm {
1135 | music_list error {
1136 Music *m = MY_MAKE_MUSIC("Music", @$);
1138 m->set_property ("error-found", SCM_BOOL_T);
1139 $$ = scm_cons (m->self_scm (), $1);
1140 m->unprotect (); /* UGH */
1147 $$ = scm_reverse_x ($2, SCM_EOL);
1152 | lyric_element_music
1158 if (unsmob_pitch ($1)) {
1159 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
1160 n->set_property ("pitch", $1);
1161 n->set_property ("duration",
1162 parser->default_duration_.smobbed_copy ());
1163 $$ = n->unprotect ();
1166 | composite_music %prec COMPOSITE
1171 | composite_music %prec COMPOSITE
1172 | lyric_element_music
1176 REPEAT simple_string unsigned_number music
1178 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1180 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1182 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1187 SEQUENTIAL braced_music_list {
1188 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1190 | braced_music_list {
1191 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1196 SIMULTANEOUS braced_music_list {
1197 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1199 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1200 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1206 | music_property_def
1210 context_modification:
1211 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1213 parser->lexer_->pop_state ();
1216 | WITH CONTEXT_MOD_IDENTIFIER
1220 | CONTEXT_MOD_IDENTIFIER
1224 | WITH embedded_scm_closed
1226 if (unsmob_context_mod ($2))
1229 parser->parser_error (@2, _ ("not a context mod"));
1230 $$ = Context_mod ().smobbed_copy ();
1235 optional_context_mod:
1239 | context_modification
1247 $$ = Context_mod ().smobbed_copy ();
1249 | context_mod_list context_mod {
1250 unsmob_context_mod ($1)->add_context_mod ($2);
1252 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1253 Context_mod *md = unsmob_context_mod ($2);
1255 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1257 | context_mod_list context_mod_embedded {
1258 unsmob_context_mod ($1)->add_context_mods
1259 (unsmob_context_mod ($2)->get_mods ());
1268 /* Music that can be parsed without lookahead */
1271 | complex_music_prefix closed_music
1273 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1280 | grouped_music_list
1284 simultaneous_music { $$ = $1; }
1285 | sequential_music { $$ = $1; }
1288 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1289 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1290 and this rule returns the reversed list of arguments. */
1292 function_arglist_skip:
1293 function_arglist_common
1294 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1296 $$ = scm_cons ($1, $3);
1297 } %prec FUNCTION_ARGLIST
1298 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1300 $$ = scm_cons ($1, $3);
1301 } %prec FUNCTION_ARGLIST
1302 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1304 $$ = scm_cons ($1, $3);
1305 } %prec FUNCTION_ARGLIST
1309 function_arglist_nonbackup:
1310 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1311 $$ = scm_cons ($4, $3);
1313 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1314 $$ = scm_cons ($4, $3);
1316 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1318 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1320 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1322 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1324 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1326 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1328 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1330 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1332 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1334 SCM n = scm_difference ($5, SCM_UNDEFINED);
1335 if (scm_is_true (scm_call_1 ($2, n)))
1336 $$ = scm_cons (n, $3);
1338 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1339 t->set_property ("digit", $5);
1340 $$ = t->unprotect ();
1341 if (scm_is_true (scm_call_1 ($2, $$)))
1342 $$ = scm_cons ($$, $3);
1344 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1348 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1350 $$ = check_scheme_arg (parser, @4,
1351 scm_difference ($5, SCM_UNDEFINED),
1354 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1356 $$ = check_scheme_arg (parser, @4,
1357 scm_difference ($5, SCM_UNDEFINED),
1363 function_arglist_keep:
1364 function_arglist_common
1365 | function_arglist_backup
1368 function_arglist_closed_keep:
1369 function_arglist_closed_common
1370 | function_arglist_backup
1373 function_arglist_backup:
1374 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1376 if (scm_is_true (scm_call_1 ($2, $4)))
1378 $$ = scm_cons ($4, $3);
1380 $$ = scm_cons (loc_on_music (@3, $1), $3);
1381 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1384 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1386 if (scm_is_true (scm_call_1 ($2, $4)))
1388 $$ = scm_cons ($4, $3);
1390 $$ = scm_cons (loc_on_music (@3, $1), $3);
1391 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1394 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1396 // There is no point interpreting a lyrics string as
1397 // an event, since we don't allow music possibly
1398 // followed by durations or postevent into closed
1399 // music, and we only accept closed music in optional
1400 // arguments at the moment. If this changes, more
1401 // complex schemes might become interesting here as
1402 // well: see how we do this at the mandatory argument
1404 if (scm_is_true (scm_call_1 ($2, $4)))
1405 $$ = scm_cons ($4, $3);
1407 $$ = scm_cons (loc_on_music (@3, $1), $3);
1408 MYBACKUP (LYRICS_STRING, $4, @4);
1411 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1413 if (scm_is_true (scm_call_1 ($2, $4)))
1416 MYREPARSE (@4, $2, UNSIGNED, $4);
1418 $$ = scm_cons (loc_on_music (@3, $1), $3);
1419 MYBACKUP (UNSIGNED, $4, @4);
1422 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1424 if (scm_is_true (scm_call_1 ($2, $4)))
1427 MYREPARSE (@4, $2, REAL, $4);
1429 $$ = scm_cons (loc_on_music (@3, $1), $3);
1430 MYBACKUP (REAL, $4, @4);
1433 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1435 if (scm_is_true (scm_call_1 ($2, $4)))
1437 $$ = scm_cons ($4, $3);
1439 $$ = scm_cons (loc_on_music (@3, $1), $3);
1440 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1443 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1445 if (scm_is_true (scm_call_1 ($2, $4)))
1447 $$ = scm_cons ($4, $3);
1449 $$ = scm_cons (loc_on_music (@3, $1), $3);
1450 MYBACKUP (FRACTION, $4, @4);
1453 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1455 SCM n = scm_difference ($5, SCM_UNDEFINED);
1456 if (scm_is_true (scm_call_1 ($2, n))) {
1458 MYREPARSE (@5, $2, REAL, n);
1460 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1461 t->set_property ("digit", $5);
1462 $$ = t->unprotect ();
1463 if (scm_is_true (scm_call_1 ($2, $$)))
1464 $$ = scm_cons ($$, $3);
1466 $$ = scm_cons (loc_on_music (@3, $1), $3);
1467 MYBACKUP (UNSIGNED, $5, @5);
1468 parser->lexer_->push_extra_token ('-');
1473 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1475 SCM n = scm_difference ($5, SCM_UNDEFINED);
1476 if (scm_is_true (scm_call_1 ($2, n))) {
1477 MYREPARSE (@5, $2, REAL, n);
1480 MYBACKUP (REAL, n, @5);
1483 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1485 SCM n = scm_difference ($5, SCM_UNDEFINED);
1486 if (scm_is_true (scm_call_1 ($2, n))) {
1487 $$ = scm_cons (n, $3);
1489 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1492 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1494 $$ = scm_cons ($4, $3);
1496 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1498 $$ = scm_cons ($4, $3);
1500 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1502 $$ = scm_cons ($1, $3);
1503 MYBACKUP(0, SCM_UNDEFINED, @3);
1505 | function_arglist_backup REPARSE embedded_scm_arg_closed
1507 $$ = check_scheme_arg (parser, @3,
1510 | function_arglist_backup REPARSE bare_number
1512 $$ = check_scheme_arg (parser, @3,
1515 | function_arglist_backup REPARSE fraction
1517 $$ = check_scheme_arg (parser, @3,
1523 function_arglist_common
1524 | function_arglist_nonbackup
1527 function_arglist_common:
1528 function_arglist_bare
1529 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1531 $$ = check_scheme_arg (parser, @3,
1534 | EXPECT_SCM function_arglist_closed_optional bare_number
1536 $$ = check_scheme_arg (parser, @3,
1539 | EXPECT_SCM function_arglist_closed_optional fraction
1541 $$ = check_scheme_arg (parser, @3,
1544 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1546 $$ = check_scheme_arg (parser, @3,
1549 | function_arglist_common_minus
1550 | function_arglist_common_lyric
1553 function_arglist_common_lyric:
1554 EXPECT_SCM function_arglist_optional lyric_element
1556 // We check how the predicate thinks about a lyrics
1557 // event or about a markup. If it accepts neither, we
1558 // backup the original token. Otherwise we commit to
1559 // taking the token. Depending on what the predicate
1560 // is willing to accept, we interpret as a string, as
1561 // a lyric event, or ambiguously (meaning that if
1562 // something looking like a duration or post event
1563 // follows, we take the event, otherwise the string).
1564 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1565 parser->default_duration_.smobbed_copy ());
1566 if (scm_is_true (scm_call_1 ($1, $3)))
1567 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1570 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1572 $$ = scm_cons ($3, $2);
1574 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1577 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1579 // This is going to flag a syntax error, we
1580 // know the predicate to be false.
1581 check_scheme_arg (parser, @3,
1585 | function_arglist_common_lyric REPARSE lyric_element_arg
1587 // This should never be false
1588 $$ = check_scheme_arg (parser, @3,
1593 function_arglist_common_minus:
1594 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1596 SCM n = scm_difference ($4, SCM_UNDEFINED);
1597 if (scm_is_true (scm_call_1 ($1, n))) {
1599 MYREPARSE (@4, $1, REAL, n);
1601 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1602 t->set_property ("digit", $4);
1603 $$ = t->unprotect ();
1604 if (scm_is_true (scm_call_1 ($1, $$)))
1605 $$ = scm_cons ($$, $2);
1607 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1611 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1614 SCM n = scm_difference ($4, SCM_UNDEFINED);
1615 MYREPARSE (@4, $1, REAL, n);
1617 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1619 SCM n = scm_difference ($4, SCM_UNDEFINED);
1620 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1622 | function_arglist_common_minus REPARSE bare_number
1624 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1628 function_arglist_closed:
1629 function_arglist_closed_common
1630 | function_arglist_nonbackup
1633 function_arglist_closed_common:
1634 function_arglist_bare
1635 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1637 $$ = check_scheme_arg (parser, @3,
1640 | EXPECT_SCM function_arglist_closed_optional bare_number
1642 $$ = check_scheme_arg (parser, @3,
1645 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1647 SCM n = scm_difference ($4, SCM_UNDEFINED);
1648 if (scm_is_true (scm_call_1 ($1, n))) {
1649 $$ = scm_cons (n, $2);
1651 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1652 t->set_property ("digit", $4);
1653 $$ = t->unprotect ();
1654 if (scm_is_true (scm_call_1 ($1, $$)))
1655 $$ = scm_cons ($$, $2);
1657 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1661 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1663 $$ = check_scheme_arg (parser, @3,
1664 scm_difference ($4, SCM_UNDEFINED),
1667 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1669 $$ = check_scheme_arg (parser, @3,
1670 scm_difference ($4, SCM_UNDEFINED),
1673 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1675 $$ = check_scheme_arg (parser, @3,
1678 | EXPECT_SCM function_arglist_closed_optional fraction
1680 $$ = check_scheme_arg (parser, @3,
1683 | EXPECT_SCM function_arglist_optional lyric_element
1685 $$ = check_scheme_arg (parser, @3,
1690 function_arglist_optional:
1691 function_arglist_keep %prec FUNCTION_ARGLIST
1692 | function_arglist_backup BACKUP
1693 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1695 $$ = scm_cons ($1, $3);
1697 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1699 $$ = scm_cons ($1, $3);
1703 function_arglist_closed_optional:
1704 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1705 | function_arglist_backup BACKUP
1706 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1708 $$ = scm_cons ($1, $3);
1710 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1712 $$ = scm_cons ($1, $3);
1716 embedded_scm_closed:
1718 | scm_function_call_closed
1721 embedded_scm_arg_closed:
1722 embedded_scm_bare_arg
1723 | scm_function_call_closed
1727 scm_function_call_closed:
1728 SCM_FUNCTION function_arglist_closed {
1729 $$ = MAKE_SYNTAX ("music-function", @$,
1731 } %prec FUNCTION_ARGLIST
1734 function_arglist_bare:
1735 EXPECT_NO_MORE_ARGS {
1738 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1739 $$ = scm_cons ($3, $2);
1741 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1742 $$ = scm_cons ($3, $2);
1744 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1745 $$ = scm_cons ($1, $3);
1747 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1748 $$ = scm_cons ($1, $3);
1750 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1751 $$ = scm_cons ($1, $3);
1755 music_function_call:
1756 MUSIC_FUNCTION function_arglist {
1757 $$ = MAKE_SYNTAX ("music-function", @$,
1764 /**/ { $$ = SCM_EOL; }
1765 | '=' simple_string {
1772 | repeated_music { $$ = $1; }
1773 | re_rhythmed_music { $$ = $1; }
1774 | complex_music_prefix music
1776 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1780 complex_music_prefix:
1781 CONTEXT simple_string optional_id optional_context_mod {
1782 Context_mod *ctxmod = unsmob_context_mod ($4);
1785 mods = ctxmod->get_mods ();
1786 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1788 | NEWCONTEXT simple_string optional_id optional_context_mod {
1789 Context_mod *ctxmod = unsmob_context_mod ($4);
1792 mods = ctxmod->get_mods ();
1793 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1798 mode_changing_head grouped_music_list {
1799 if ($1 == ly_symbol2scm ("chords"))
1801 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1807 parser->lexer_->pop_state ();
1809 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1810 Context_mod *ctxmod = unsmob_context_mod ($2);
1813 mods = ctxmod->get_mods ();
1814 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1815 if ($1 == ly_symbol2scm ("ChordNames"))
1817 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1819 parser->lexer_->pop_state ();
1825 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1826 parser->lexer_->push_note_state (alist_to_hashq (nn));
1828 $$ = ly_symbol2scm ("notes");
1832 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1833 parser->lexer_->push_note_state (alist_to_hashq (nn));
1835 $$ = ly_symbol2scm ("drums");
1838 parser->lexer_->push_figuredbass_state ();
1840 $$ = ly_symbol2scm ("figures");
1843 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1844 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1845 nn = parser->lexer_->lookup_identifier ("pitchnames");
1846 parser->lexer_->push_chord_state (alist_to_hashq (nn));
1847 $$ = ly_symbol2scm ("chords");
1851 { parser->lexer_->push_lyric_state ();
1852 $$ = ly_symbol2scm ("lyrics");
1856 mode_changing_head_with_context:
1858 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1859 parser->lexer_->push_note_state (alist_to_hashq (nn));
1861 $$ = ly_symbol2scm ("DrumStaff");
1864 parser->lexer_->push_figuredbass_state ();
1866 $$ = ly_symbol2scm ("FiguredBass");
1869 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1870 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1871 nn = parser->lexer_->lookup_identifier ("pitchnames");
1872 parser->lexer_->push_chord_state (alist_to_hashq (nn));
1873 $$ = ly_symbol2scm ("ChordNames");
1876 { parser->lexer_->push_lyric_state ();
1877 $$ = ly_symbol2scm ("Lyrics");
1882 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1885 /* Can also use music at the expensive of two S/Rs similar to
1886 \repeat \alternative */
1887 parser->lexer_->pop_state ();
1889 $$ = scm_cons ($3, SCM_EOL);
1891 | new_lyrics ADDLYRICS {
1892 parser->lexer_->push_lyric_state ();
1894 parser->lexer_->pop_state ();
1895 $$ = scm_cons ($4, $1);
1900 composite_music new_lyrics {
1901 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1903 | LYRICSTO simple_string {
1904 parser->lexer_->push_lyric_state ();
1906 parser->lexer_->pop_state ();
1907 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1912 CHANGE STRING '=' STRING {
1913 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1918 property_path_revved:
1919 embedded_scm_closed {
1920 $$ = scm_cons ($1, SCM_EOL);
1922 | property_path_revved embedded_scm_closed {
1923 $$ = scm_cons ($2, $1);
1928 property_path_revved {
1929 $$ = scm_reverse_x ($1, SCM_EOL);
1935 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1936 scm_string_to_symbol ($1), $3);
1938 | UNSET simple_string {
1939 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1940 scm_string_to_symbol ($2));
1942 | OVERRIDE simple_string property_path '=' scalar {
1943 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1944 scm_string_to_symbol ($2), $5),
1947 | REVERT simple_string embedded_scm {
1948 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1949 scm_string_to_symbol ($2), $3);
1954 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1955 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1957 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1958 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1959 | DENIES { $$ = ly_symbol2scm ("denies"); }
1961 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1962 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1963 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1964 | NAME { $$ = ly_symbol2scm ("context-name"); }
1968 property_operation { $$ = $1; }
1969 | context_def_mod STRING {
1970 $$ = scm_list_2 ($1, $2);
1972 | context_def_mod embedded_scm
1974 if (!scm_is_string ($2)
1975 && ly_symbol2scm ("consists") != $1
1976 && ly_symbol2scm ("remove") != $1)
1979 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
1983 $$ = scm_list_2 ($1, $2);
1990 if (!is_regular_identifier ($1))
1992 @$.error (_("Grob name should be alphanumeric"));
1995 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1996 scm_string_to_symbol ($1));
1998 | simple_string '.' simple_string {
1999 $$ = scm_list_2 (scm_string_to_symbol ($1),
2000 scm_string_to_symbol ($3));
2004 simple_music_property_def:
2005 OVERRIDE context_prop_spec property_path '=' scalar {
2006 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
2007 ly_symbol2scm ("OverrideProperty"),
2012 | REVERT context_prop_spec embedded_scm {
2013 $$ = scm_list_4 (scm_car ($2),
2014 ly_symbol2scm ("RevertProperty"),
2018 | SET context_prop_spec '=' scalar {
2019 $$ = scm_list_4 (scm_car ($2),
2020 ly_symbol2scm ("PropertySet"),
2024 | UNSET context_prop_spec {
2025 $$ = scm_list_3 (scm_car ($2),
2026 ly_symbol2scm ("PropertyUnset"),
2032 simple_music_property_def {
2033 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2041 | STRING_IDENTIFIER {
2044 | string '+' string {
2045 $$ = scm_string_append (scm_list_2 ($1, $3));
2049 simple_string: STRING {
2055 | STRING_IDENTIFIER {
2067 embedded_scm_arg_closed
2074 simple_element post_events {
2075 // Let the rhythmic music iterator sort this mess out.
2076 if (scm_is_pair ($2)) {
2077 if (unsmob_pitch ($1)) {
2078 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
2079 n->set_property ("pitch", $1);
2080 n->set_property ("duration",
2081 parser->default_duration_.smobbed_copy ());
2082 $$ = n->unprotect ();
2084 unsmob_music ($$)->set_property ("articulations",
2085 scm_reverse_x ($2, SCM_EOL));
2088 | simple_chord_elements post_events {
2089 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2092 /* why is this giving wrong start location? -ns
2094 i.set_location (@1, @2);
2095 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2097 | CHORD_REPETITION optional_notemode_duration post_events {
2099 i.set_location (@1, @3);
2100 $$ = MAKE_SYNTAX ("repetition-chord", i,
2101 $2, scm_reverse_x ($3, SCM_EOL));
2103 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2105 i.set_location (@1, @3);
2106 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2107 scm_reverse_x ($3, SCM_EOL));
2110 | note_chord_element
2115 chord_body optional_notemode_duration post_events
2117 Music *m = unsmob_music ($1);
2118 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2119 SCM es = m->get_property ("elements");
2120 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2122 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2123 unsmob_music (scm_car (s))->set_property ("duration", dur);
2124 es = ly_append2 (es, postevs);
2126 m-> set_property ("elements", es);
2128 $$ = m->self_scm ();
2133 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2135 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2139 chord_body_elements:
2140 /* empty */ { $$ = SCM_EOL; }
2141 | chord_body_elements chord_body_element {
2142 if (!SCM_UNBNDP ($2))
2143 $$ = scm_cons ($2, $1);
2148 pitch exclamations questions octave_check post_events
2155 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2156 n->set_property ("pitch", $1);
2158 n->set_property ("cautionary", SCM_BOOL_T);
2159 if (ex % 2 || q % 2)
2160 n->set_property ("force-accidental", SCM_BOOL_T);
2162 if (scm_is_pair (post)) {
2163 SCM arts = scm_reverse_x (post, SCM_EOL);
2164 n->set_property ("articulations", arts);
2166 if (scm_is_number (check))
2168 int q = scm_to_int (check);
2169 n->set_property ("absolute-octave", scm_from_int (q-1));
2172 $$ = n->unprotect ();
2174 | DRUM_PITCH post_events {
2175 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2176 n->set_property ("drum-type", $1);
2178 if (scm_is_pair ($2)) {
2179 SCM arts = scm_reverse_x ($2, SCM_EOL);
2180 n->set_property ("articulations", arts);
2182 $$ = n->unprotect ();
2184 | music_function_chord_body
2186 Music *m = unsmob_music ($1);
2188 while (m && m->is_mus_type ("music-wrapper-music")) {
2189 $$ = m->get_property ("element");
2190 m = unsmob_music ($$);
2193 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2194 parser->parser_error (@$, _ ("not a rhythmic event"));
2200 music_function_chord_body:
2205 // Event functions may only take closed arglists, otherwise it would
2206 // not be clear whether a following postevent should be associated
2207 // with the last argument of the event function or with the expression
2208 // for which the function call acts itself as event.
2210 music_function_event:
2211 MUSIC_FUNCTION function_arglist_closed {
2212 $$ = MAKE_SYNTAX ("music-function", @$,
2217 event_function_event:
2218 EVENT_FUNCTION function_arglist_closed {
2219 $$ = MAKE_SYNTAX ("music-function", @$,
2229 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2230 m->set_property ("span-direction", scm_from_int (START));
2231 $$ = m->unprotect();
2234 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2235 m->set_property ("span-direction", scm_from_int (STOP));
2236 $$ = m->unprotect ();
2239 $$ = MAKE_SYNTAX ("voice-separator", @$);
2242 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2244 Music *m = unsmob_music (pipe);
2249 $$ = m->unprotect ();
2252 $$ = MAKE_SYNTAX ("bar-check", @$);
2259 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2271 | post_events post_event {
2272 unsmob_music ($2)->set_spot (@2);
2273 $$ = scm_cons ($2, $$);
2277 post_event_nofinger:
2278 direction_less_event {
2281 | script_dir music_function_event {
2285 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2289 if (!parser->lexer_->is_lyric_state ())
2290 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2291 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2294 if (!parser->lexer_->is_lyric_state ())
2295 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2296 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2298 | script_dir direction_reqd_event {
2301 Music *m = unsmob_music ($2);
2302 m->set_property ("direction", scm_from_int ($1));
2306 | script_dir direction_less_event {
2309 Music *m = unsmob_music ($2);
2310 m->set_property ("direction", scm_from_int ($1));
2314 | string_number_event
2318 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2323 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2334 string_number_event:
2336 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2337 s->set_property ("string-number", scm_from_int ($1));
2338 $$ = s->unprotect ();
2342 direction_less_char:
2344 $$ = ly_symbol2scm ("bracketOpenSymbol");
2347 $$ = ly_symbol2scm ("bracketCloseSymbol");
2350 $$ = ly_symbol2scm ("tildeSymbol");
2353 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2356 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2359 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2362 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2365 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2368 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2371 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2375 direction_less_event:
2376 direction_less_char {
2377 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2379 if (unsmob_music (predefd))
2381 m = unsmob_music (predefd)->clone ();
2386 m = MY_MAKE_MUSIC ("Music", @$);
2388 $$ = m->unprotect ();
2390 | EVENT_IDENTIFIER {
2394 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2395 a->set_property ("tremolo-type", scm_from_int ($1));
2396 $$ = a->unprotect ();
2398 | event_function_event
2401 direction_reqd_event:
2405 | script_abbreviation {
2406 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2407 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2408 if (scm_is_string (s))
2409 a->set_property ("articulation-type", s);
2410 else parser->parser_error (@1, _ ("expecting string as script definition"));
2411 $$ = a->unprotect ();
2416 /**/ { $$ = SCM_EOL; }
2417 | '=' { $$ = scm_from_int (0); }
2418 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2419 | '=' sup_quotes { $$ = scm_from_int ($2); }
2444 | NOTENAME_PITCH sup_quotes {
2445 Pitch p = *unsmob_pitch ($1);
2446 p = p.transposed (Pitch ($2,0,0));
2447 $$ = p.smobbed_copy ();
2449 | NOTENAME_PITCH sub_quotes {
2450 Pitch p =* unsmob_pitch ($1);
2451 p = p.transposed (Pitch (-$2,0,0));
2452 $$ = p.smobbed_copy ();
2464 | TONICNAME_PITCH sup_quotes {
2465 Pitch p = *unsmob_pitch ($1);
2466 p = p.transposed (Pitch ($2,0,0));
2467 $$ = p.smobbed_copy ();
2469 | TONICNAME_PITCH sub_quotes {
2470 Pitch p = *unsmob_pitch ($1);
2472 p = p.transposed (Pitch (-$2,0,0));
2473 $$ = p.smobbed_copy ();
2484 pitch_also_in_chords:
2491 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2492 t->set_property ("text", $1);
2493 $$ = t->unprotect ();
2496 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2497 t->set_property ("text",
2498 make_simple_markup ($1));
2499 $$ = t->unprotect ();
2505 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2506 t->set_property ("digit", $1);
2507 $$ = t->unprotect ();
2511 script_abbreviation:
2513 $$ = scm_from_locale_string ("Hat");
2516 $$ = scm_from_locale_string ("Plus");
2519 $$ = scm_from_locale_string ("Dash");
2522 $$ = scm_from_locale_string ("Bar");
2525 $$ = scm_from_locale_string ("Larger");
2528 $$ = scm_from_locale_string ("Dot");
2531 $$ = scm_from_locale_string ("Underscore");
2538 | '-' { $$ = CENTER; }
2542 multiplied_duration {
2547 maybe_notemode_duration:
2551 | multiplied_duration {
2553 parser->default_duration_ = *unsmob_duration ($$);
2558 optional_notemode_duration:
2559 maybe_notemode_duration
2561 if (SCM_UNBNDP ($$))
2562 $$ = parser->default_duration_.smobbed_copy ();
2567 bare_unsigned dots {
2569 if (!is_duration ($1))
2570 parser->parser_error (@1, _f ("not a duration: %d", $1));
2574 $$ = Duration (len, $2).smobbed_copy ();
2576 | DURATION_IDENTIFIER dots {
2577 Duration *d = unsmob_duration ($1);
2578 Duration k (d->duration_log (), d->dot_count () + $2);
2579 k = k.compressed (d->factor ());
2585 multiplied_duration:
2589 | multiplied_duration '*' bare_unsigned {
2590 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2592 | multiplied_duration '*' FRACTION {
2593 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2595 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2600 FRACTION { $$ = $1; }
2601 | UNSIGNED '/' UNSIGNED {
2602 $$ = scm_cons ($1, $3);
2619 | ':' bare_unsigned {
2620 if (!is_duration ($2))
2621 parser->parser_error (@2, _f ("not a duration: %d", $2));
2627 UNSIGNED { $$ = $1; }
2628 | STRING { $$ = $1; }
2629 | full_markup { $$ = $1; }
2632 figured_bass_alteration:
2633 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2634 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2635 | '!' { $$ = scm_from_int (0); }
2640 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2641 $$ = bfr->unprotect ();
2644 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2645 $$ = bfr->self_scm ();
2647 if (scm_is_number ($1))
2648 bfr->set_property ("figure", $1);
2649 else if (Text_interface::is_markup ($1))
2650 bfr->set_property ("text", $1);
2656 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2658 | bass_figure figured_bass_alteration {
2659 Music *m = unsmob_music ($1);
2660 if (scm_to_double ($2)) {
2661 SCM salter = m->get_property ("alteration");
2662 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2663 m->set_property ("alteration",
2664 scm_sum (alter, $2));
2666 m->set_property ("alteration", scm_from_int (0));
2669 | bass_figure figured_bass_modification {
2670 Music *m = unsmob_music ($1);
2671 if ($2 == ly_symbol2scm ("plus"))
2673 m->set_property ("augmented", SCM_BOOL_T);
2675 else if ($2 == ly_symbol2scm ("slash"))
2677 m->set_property ("diminished", SCM_BOOL_T);
2679 else if ($2 == ly_symbol2scm ("exclamation"))
2681 m->set_property ("no-continuation", SCM_BOOL_T);
2683 else if ($2 == ly_symbol2scm ("backslash"))
2685 m->set_property ("augmented-slash", SCM_BOOL_T);
2691 figured_bass_modification:
2693 $$ = ly_symbol2scm ("plus");
2696 $$ = ly_symbol2scm ("exclamation");
2699 $$ = ly_symbol2scm ("slash");
2702 $$ = ly_symbol2scm ("backslash");
2712 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2720 | figure_list br_bass_figure {
2721 $$ = scm_cons ($2, $1);
2726 FIGURE_OPEN figure_list FIGURE_CLOSE {
2727 $$ = scm_reverse_x ($2, SCM_EOL);
2738 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2739 if (!parser->lexer_->is_note_state ())
2740 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2741 if ($2 || $3 || scm_is_number ($4) || !SCM_UNBNDP ($5) || $6)
2745 n = MY_MAKE_MUSIC ("RestEvent", @$);
2747 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2749 n->set_property ("pitch", $1);
2750 if (SCM_UNBNDP ($5))
2751 n->set_property ("duration",
2752 parser->default_duration_.smobbed_copy ());
2754 n->set_property ("duration", $5);
2756 if (scm_is_number ($4))
2758 int q = scm_to_int ($4);
2759 n->set_property ("absolute-octave", scm_from_int (q-1));
2763 n->set_property ("cautionary", SCM_BOOL_T);
2764 if ($2 % 2 || $3 % 2)
2765 n->set_property ("force-accidental", SCM_BOOL_T);
2767 $$ = n->unprotect ();
2770 | DRUM_PITCH optional_notemode_duration {
2771 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2772 n->set_property ("duration", $2);
2773 n->set_property ("drum-type", $1);
2775 $$ = n->unprotect ();
2777 | RESTNAME optional_notemode_duration {
2779 if (ly_scm2string ($1) == "s") {
2781 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2784 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2787 ev->set_property ("duration", $2);
2788 $$ = ev->unprotect ();
2792 simple_chord_elements:
2794 if (!parser->lexer_->is_chord_state ())
2795 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2798 | figure_spec optional_notemode_duration {
2799 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2801 unsmob_music (scm_car (s))->set_property ("duration", $2);
2818 | lyric_element multiplied_duration post_events {
2819 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2820 if (scm_is_pair ($3))
2821 unsmob_music ($$)->set_property
2822 ("articulations", scm_reverse_x ($3, SCM_EOL));
2824 | lyric_element post_event post_events {
2825 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2826 parser->default_duration_.smobbed_copy ());
2827 unsmob_music ($$)->set_property
2828 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2830 | LYRIC_ELEMENT optional_notemode_duration post_events {
2831 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2832 if (scm_is_pair ($3))
2833 unsmob_music ($$)->set_property
2834 ("articulations", scm_reverse_x ($3, SCM_EOL));
2839 lyric_element_music:
2840 lyric_element optional_notemode_duration post_events {
2841 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2842 if (scm_is_pair ($3))
2843 unsmob_music ($$)->set_property
2844 ("articulations", scm_reverse_x ($3, SCM_EOL));
2849 steno_tonic_pitch optional_notemode_duration {
2850 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2852 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2853 SCM its = scm_reverse_x ($4, SCM_EOL);
2854 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2862 | chord_items chord_item {
2863 $$ = scm_cons ($2, $$);
2869 $$ = ly_symbol2scm ("chord-colon");
2872 $$ = ly_symbol2scm ("chord-caret");
2874 | CHORD_SLASH steno_tonic_pitch {
2875 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2877 | CHORD_BASS steno_tonic_pitch {
2878 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2887 $$ = scm_reverse_x ($1, SCM_EOL);
2895 step_number { $$ = scm_cons ($1, SCM_EOL); }
2896 | step_numbers '.' step_number {
2897 $$ = scm_cons ($3, $$);
2903 $$ = make_chord_step ($1, 0);
2905 | bare_unsigned '+' {
2906 $$ = make_chord_step ($1, SHARP_ALTERATION);
2908 | bare_unsigned CHORD_MINUS {
2909 $$ = make_chord_step ($1, FLAT_ALTERATION);
2915 $$ = scm_from_int ($1);
2917 | bare_unsigned '~' bare_unsigned {
2918 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2925 TODO: should deprecate in favor of Scheme?
2929 number_expression '+' number_term {
2930 $$ = scm_sum ($1, $3);
2932 | number_expression '-' number_term {
2933 $$ = scm_difference ($1, $3);
2942 | number_factor '*' number_factor {
2943 $$ = scm_product ($1, $3);
2945 | number_factor '/' number_factor {
2946 $$ = scm_divide ($1, $3);
2951 '-' number_factor { /* %prec UNARY_MINUS */
2952 $$ = scm_difference ($2, SCM_UNDEFINED);
2960 | UNSIGNED NUMBER_IDENTIFIER {
2961 $$ = scm_product ($1, $2);
2963 | REAL NUMBER_IDENTIFIER {
2964 $$ = scm_product ($1, $2);
2976 $$ = scm_to_int ($1);
2987 | exclamations '!' { $$ ++; }
2992 | questions '?' { $$ ++; }
2996 This should be done more dynamically if possible.
3000 LYRIC_MARKUP_IDENTIFIER {
3004 { parser->lexer_->push_markup_state (); }
3007 parser->lexer_->pop_state ();
3012 MARKUPLIST_IDENTIFIER {
3016 { parser->lexer_->push_markup_state (); }
3019 parser->lexer_->pop_state ();
3028 { parser->lexer_->push_markup_state (); }
3031 parser->lexer_->pop_state ();
3037 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3039 | markup_head_1_list simple_markup {
3040 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3050 if (Text_interface::is_markup ($1))
3051 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3052 else if (Text_interface::is_markup_list ($1))
3053 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3055 parser->parser_error (@1, _ ("not a markup"));
3056 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3063 MARKUPLIST_IDENTIFIER {
3066 | markup_composed_list {
3069 | markup_braced_list {
3072 | markup_command_list {
3073 $$ = scm_list_1 ($1);
3075 | markup_scm MARKUPLIST_IDENTIFIER
3081 markup_composed_list:
3082 markup_head_1_list markup_braced_list {
3083 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3089 '{' markup_braced_list_body '}' {
3090 $$ = scm_reverse_x ($2, SCM_EOL);
3094 markup_braced_list_body:
3095 /* empty */ { $$ = SCM_EOL; }
3096 | markup_braced_list_body markup {
3097 $$ = scm_cons ($2, $1);
3099 | markup_braced_list_body markup_list {
3100 $$ = scm_reverse_x ($2, $1);
3104 markup_command_list:
3105 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3106 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3110 markup_command_basic_arguments:
3111 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3112 $$ = scm_cons ($3, $2);
3114 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3115 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3117 | EXPECT_NO_MORE_ARGS {
3122 markup_command_list_arguments:
3123 markup_command_basic_arguments { $$ = $1; }
3124 | EXPECT_MARKUP markup_command_list_arguments markup {
3125 $$ = scm_cons ($3, $2);
3130 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3131 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3136 markup_head_1_item {
3137 $$ = scm_list_1 ($1);
3139 | markup_head_1_list markup_head_1_item {
3140 $$ = scm_cons ($2, $1);
3146 $$ = make_simple_markup ($1);
3148 | MARKUP_IDENTIFIER {
3151 | LYRIC_MARKUP_IDENTIFIER {
3154 | STRING_IDENTIFIER {
3158 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3159 parser->lexer_->push_note_state (alist_to_hashq (nn));
3160 } '{' score_body '}' {
3162 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3164 parser->lexer_->pop_state ();
3166 | MARKUP_FUNCTION markup_command_basic_arguments {
3167 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3169 | markup_scm MARKUP_IDENTIFIER
3176 markup_head_1_list simple_markup {
3177 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3178 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3188 Lily_parser::set_yydebug (bool x)
3194 Lily_parser::do_yyparse ()
3205 It is a little strange to have this function in this file, but
3206 otherwise, we have to import music classes into the lexer.
3210 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3212 if (scm_is_string (sid)) {
3214 return STRING_IDENTIFIER;
3215 } else if (unsmob_book (sid)) {
3216 Book *book = unsmob_book (sid)->clone ();
3217 *destination = book->self_scm ();
3220 return BOOK_IDENTIFIER;
3221 } else if (scm_is_number (sid)) {
3223 return NUMBER_IDENTIFIER;
3224 } else if (unsmob_context_def (sid)) {
3225 Context_def *def= unsmob_context_def (sid)->clone ();
3227 *destination = def->self_scm ();
3230 return CONTEXT_DEF_IDENTIFIER;
3231 } else if (unsmob_context_mod (sid)) {
3232 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3234 return CONTEXT_MOD_IDENTIFIER;
3235 } else if (unsmob_score (sid)) {
3236 Score *score = new Score (*unsmob_score (sid));
3237 *destination = score->self_scm ();
3239 score->unprotect ();
3240 return SCORE_IDENTIFIER;
3241 } else if (Music *mus = unsmob_music (sid)) {
3242 mus = mus->clone ();
3243 *destination = mus->self_scm ();
3244 unsmob_music (*destination)->
3245 set_property ("origin", make_input (last_input_));
3247 bool is_event = mus->is_mus_type ("post-event");
3249 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3250 } else if (unsmob_pitch (sid)) {
3251 *destination = unsmob_pitch (sid)->smobbed_copy ();
3252 return PITCH_IDENTIFIER;
3253 } else if (unsmob_duration (sid)) {
3254 *destination = unsmob_duration (sid)->smobbed_copy ();
3255 return DURATION_IDENTIFIER;
3256 } else if (unsmob_output_def (sid)) {
3257 Output_def *p = unsmob_output_def (sid);
3260 *destination = p->self_scm ();
3262 return OUTPUT_DEF_IDENTIFIER;
3263 } else if (Text_interface::is_markup (sid)) {
3265 if (is_lyric_state ())
3266 return LYRIC_MARKUP_IDENTIFIER;
3267 return MARKUP_IDENTIFIER;
3268 } else if (Text_interface::is_markup_list (sid)) {
3270 return MARKUPLIST_IDENTIFIER;
3277 get_next_unique_context_id ()
3279 return scm_from_locale_string ("$uniqueContextId");
3284 get_next_unique_lyrics_context_id ()
3286 static int new_context_count;
3288 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3289 return scm_from_locale_string (s);
3292 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3293 SCM arg, SCM args, SCM pred)
3295 args = scm_cons (arg, args);
3296 if (scm_is_true (scm_call_1 (pred, arg)))
3298 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3299 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3300 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3304 SCM loc_on_music (Input loc, SCM arg)
3306 if (Music *m = unsmob_music (arg))
3310 return m->unprotect ();
3316 is_regular_identifier (SCM id)
3318 string str = ly_scm2string (id);
3319 char const *s = str.c_str ();
3328 v = v && isalnum (*s);
3335 make_music_with_input (SCM name, Input where)
3337 Music *m = make_music_by_name (name);
3338 m->set_spot (where);
3343 make_simple_markup (SCM a)
3351 return t && t == 1 << intlog2 (t);
3355 set_music_properties (Music *p, SCM a)
3357 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3358 p->set_property (scm_caar (k), scm_cdar (k));
3363 make_chord_step (int step, Rational alter)
3366 alter += FLAT_ALTERATION;
3370 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3371 return m.smobbed_copy ();
3376 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3378 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3379 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3380 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3382 unsmob_music (scm_car (s))->set_spot (loc);
3388 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3390 Lily_lexer *lex = parser->lexer_;
3394 lex->prepare_for_next_token ();
3395 return lex->yylex ();