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_nonbackup_common
485 %type <scm> function_arglist_closed_nonbackup
486 %type <scm> function_arglist_skip
487 %type <scm> function_arglist_bare
488 %type <scm> function_arglist_closed
489 %type <scm> function_arglist_closed_optional
490 %type <scm> function_arglist_common
491 %type <scm> function_arglist_common_lyric
492 %type <scm> function_arglist_common_minus
493 %type <scm> function_arglist_closed_common
494 %type <scm> function_arglist_keep
495 %type <scm> function_arglist_closed_keep
496 %type <scm> identifier_init
498 %type <scm> lilypond_header
499 %type <scm> lilypond_header_body
500 %type <scm> lyric_element
501 %type <scm> lyric_element_arg
502 %type <scm> lyric_element_music
503 %type <scm> lyric_markup
505 %type <scm> markup_braced_list
506 %type <scm> markup_braced_list_body
507 %type <scm> markup_composed_list
508 %type <scm> markup_command_list
509 %type <scm> markup_command_list_arguments
510 %type <scm> markup_command_basic_arguments
511 %type <scm> markup_head_1_item
512 %type <scm> markup_head_1_list
513 %type <scm> markup_list
514 %type <scm> markup_top
515 %type <scm> maybe_notemode_duration
516 %type <scm> mode_changing_head
517 %type <scm> mode_changing_head_with_context
518 %type <scm> multiplied_duration
519 %type <scm> music_function_event
520 %type <scm> music_function_chord_body
521 %type <scm> new_chord
522 %type <scm> new_lyrics
523 %type <scm> number_expression
524 %type <scm> number_factor
525 %type <scm> number_term
526 %type <scm> octave_check
527 %type <scm> optional_context_mod
528 %type <scm> optional_id
529 %type <scm> optional_notemode_duration
531 %type <scm> pitch_also_in_chords
532 %type <scm> post_events
533 %type <scm> property_operation
534 %type <scm> property_path property_path_revved
536 %type <scm> scalar_closed
537 %type <scm> scm_function_call
538 %type <scm> scm_function_call_closed
539 %type <scm> script_abbreviation
540 %type <scm> simple_chord_elements
541 %type <scm> simple_markup
542 %type <scm> simple_string
543 %type <scm> steno_duration
544 %type <scm> steno_pitch
545 %type <scm> steno_tonic_pitch
546 %type <scm> step_number
547 %type <scm> step_numbers
549 %type <scm> tempo_range
551 %type <score> score_block
552 %type <score> score_body
557 /* We don't assign precedence to / and *, because we might need varied
558 prec levels in different prods */
567 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
568 parser->lexer_->push_note_state (alist_to_hashq (nn));
569 } embedded_lilypond {
570 parser->lexer_->pop_state ();
571 parser->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
575 lilypond: /* empty */ { }
576 | lilypond toplevel_expression {
578 | lilypond assignment {
581 parser->error_level_ = 1;
584 parser->error_level_ = 1;
591 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
595 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
596 scm_call_2 (proc, parser->self_scm (), book->self_scm ());
601 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
602 scm_call_2 (proc, parser->self_scm (), bookpart->self_scm ());
603 bookpart->unprotect ();
608 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
609 scm_call_2 (proc, parser->self_scm (), score->self_scm ());
613 Music *music = unsmob_music ($1);
614 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
615 scm_call_2 (proc, parser->self_scm (), music->self_scm ());
618 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
619 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
622 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
623 scm_call_2 (proc, parser->self_scm (), $1);
627 Output_def * od = $1;
629 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
630 id = ly_symbol2scm ("$defaultpaper");
631 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
632 id = ly_symbol2scm ("$defaultmidi");
633 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
634 id = ly_symbol2scm ("$defaultlayout");
636 parser->lexer_->set_identifier (id, od->self_scm ());
644 $$ = parser->lexer_->eval_scm ($1);
649 embedded_scm_bare_arg:
655 | context_modification
658 $$ = $1->self_scm ();
661 | context_def_spec_block
664 $$ = $1->self_scm ();
669 $$ = $1->self_scm ();
674 $$ = $1->self_scm ();
679 /* The generic version may end in music, or not */
687 embedded_scm_bare_arg
693 SCM_FUNCTION function_arglist {
694 $$ = MAKE_SYNTAX ("music-function", @$,
702 $$ = MAKE_SYNTAX ("void-music", @$);
705 | music music music_list {
706 $$ = MAKE_SYNTAX ("sequential-music", @$,
707 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
710 parser->error_level_ = 1;
712 | INVALID embedded_lilypond {
713 parser->error_level_ = 1;
718 lilypond_header_body:
720 $$ = get_header (parser);
721 parser->lexer_->add_scope ($$);
723 | lilypond_header_body assignment {
729 HEADER '{' lilypond_header_body '}' {
730 $$ = parser->lexer_->remove_scope ();
739 | LYRICS_STRING { $$ = $1; }
743 assignment_id '=' identifier_init {
744 parser->lexer_->set_identifier ($1, $3);
746 | assignment_id property_path '=' identifier_init {
747 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
748 parser->lexer_->set_identifier (path, $4);
751 TODO: devise standard for protection in parser.
753 The parser stack lives on the C-stack, which means that
754 all objects can be unprotected as soon as they're here.
764 $$ = $1->self_scm ();
768 $$ = $1->self_scm ();
772 $$ = $1->self_scm ();
776 $$ = $1->self_scm ();
779 | context_def_spec_block {
785 | post_event_nofinger {
788 | number_expression {
806 | context_modification {
811 context_def_spec_block:
812 CONTEXT '{' context_def_spec_body '}'
823 context_mod_embedded:
826 if (unsmob_music ($1)) {
827 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
828 $1 = scm_call_2 (proc, parser->self_scm (), $1);
830 if (unsmob_context_mod ($1))
833 parser->parser_error (@1, _ ("not a context mod"));
839 context_def_spec_body:
841 $$ = Context_def::make_scm ();
842 unsmob_context_def ($$)->origin ()->set_spot (@$);
844 | CONTEXT_DEF_IDENTIFIER {
846 unsmob_context_def ($$)->origin ()->set_spot (@$);
848 | context_def_spec_body context_mod {
849 unsmob_context_def ($$)->add_context_mod ($2);
851 | context_def_spec_body context_modification {
852 Context_def *td = unsmob_context_def ($$);
853 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
854 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
855 td->add_context_mod (scm_car (m));
858 | context_def_spec_body context_mod_embedded {
859 Context_def *td = unsmob_context_def ($$);
860 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
861 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
862 td->add_context_mod (scm_car (m));
870 BOOK '{' book_body '}' {
873 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
878 * Use 'handlers' like for toplevel-* stuff?
879 * grok \layout and \midi? */
883 init_papers (parser);
884 $$->origin ()->set_spot (@$);
885 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
886 $$->paper_->unprotect ();
887 push_paper (parser, $$->paper_);
888 $$->header_ = parser->lexer_->lookup_identifier ("$defaultheader");
889 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
892 $$ = unsmob_book ($1);
894 $$->origin ()->set_spot (@$);
895 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
897 | book_body paper_block {
900 set_paper (parser, $2);
902 | book_body bookpart_block {
904 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
905 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
906 bookpart->unprotect ();
908 | book_body score_block {
910 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
911 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
914 | book_body composite_music {
915 Music *music = unsmob_music ($2);
916 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
917 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
919 | book_body full_markup {
920 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
921 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
923 | book_body full_markup_list {
924 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
925 scm_call_2 (proc, $$->self_scm (), $2);
927 | book_body lilypond_header {
930 | book_body embedded_scm { }
933 $$->scores_ = SCM_EOL;
934 $$->bookparts_ = SCM_EOL;
939 BOOKPART '{' bookpart_body '}' {
941 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
948 $$->origin ()->set_spot (@$);
949 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
952 $$ = unsmob_book ($1);
954 $$->origin ()->set_spot (@$);
955 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
957 | bookpart_body paper_block {
961 | bookpart_body score_block {
963 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
964 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
967 | bookpart_body composite_music {
968 Music *music = unsmob_music ($2);
969 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
970 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
972 | bookpart_body full_markup {
973 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
974 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
976 | bookpart_body full_markup_list {
977 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
978 scm_call_2 (proc, $$->self_scm (), $2);
980 | bookpart_body lilypond_header {
983 | bookpart_body embedded_scm { }
984 | bookpart_body error {
986 $$->scores_ = SCM_EOL;
991 SCORE '{' score_body '}' {
999 SCM scorify = ly_lily_module_constant ("scorify-music");
1000 SCM score = scm_call_2 (scorify, m, parser->self_scm ());
1002 // pass ownernship to C++ again.
1003 $$ = unsmob_score (score);
1005 $$->origin ()->set_spot (@$);
1007 | SCORE_IDENTIFIER {
1008 $$ = unsmob_score ($1);
1010 $$->origin ()->set_spot (@$);
1012 | score_body lilypond_header {
1013 $$->set_header ($2);
1015 | score_body output_def {
1016 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
1018 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1023 $$->add_output_def ($2);
1027 | score_body error {
1028 $$->error_found_ = true;
1040 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1042 parser->parser_error (@1, _ ("need \\paper for paper block"));
1044 $$ = get_paper (parser);
1051 output_def_body '}' {
1054 parser->lexer_->remove_scope ();
1055 parser->lexer_->pop_state ();
1061 $$ = get_paper (parser);
1062 $$->input_origin_ = @$;
1063 parser->lexer_->add_scope ($$->scope_);
1066 Output_def *p = get_midi (parser);
1068 parser->lexer_->add_scope (p->scope_);
1071 Output_def *p = get_layout (parser);
1073 parser->lexer_->add_scope (p->scope_);
1078 output_def_head_with_mode_switch:
1080 parser->lexer_->push_initial_state ();
1086 output_def_head_with_mode_switch '{' {
1088 $$->input_origin_.set_spot (@$);
1090 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1093 Output_def *o = unsmob_output_def ($3);
1094 o->input_origin_.set_spot (@$);
1097 parser->lexer_->remove_scope ();
1098 parser->lexer_->add_scope (o->scope_);
1100 | output_def_body assignment {
1103 | output_def_body context_def_spec_block {
1104 assign_context_def ($$, $2);
1106 | output_def_body music_arg {
1107 SCM proc = parser->lexer_->lookup_identifier ("output-def-music-handler");
1108 scm_call_3 (proc, parser->self_scm (), $1->self_scm (), $2);
1110 | output_def_body error {
1116 TEMPO steno_duration '=' tempo_range {
1117 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1119 | TEMPO scalar_closed steno_duration '=' tempo_range {
1120 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1123 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1128 The representation of a list is reversed to have efficient append. */
1134 | music_list music {
1135 $$ = scm_cons ($2, $1);
1137 | music_list embedded_scm {
1140 | music_list error {
1141 Music *m = MY_MAKE_MUSIC("Music", @$);
1143 m->set_property ("error-found", SCM_BOOL_T);
1144 $$ = scm_cons (m->self_scm (), $1);
1145 m->unprotect (); /* UGH */
1152 $$ = scm_reverse_x ($2, SCM_EOL);
1157 | lyric_element_music
1163 if (unsmob_pitch ($1)) {
1164 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
1165 n->set_property ("pitch", $1);
1166 n->set_property ("duration",
1167 parser->default_duration_.smobbed_copy ());
1168 $$ = n->unprotect ();
1171 | composite_music %prec COMPOSITE
1176 | composite_music %prec COMPOSITE
1177 | lyric_element_music
1181 REPEAT simple_string unsigned_number music
1183 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1185 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1187 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1192 SEQUENTIAL braced_music_list {
1193 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1195 | braced_music_list {
1196 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1201 SIMULTANEOUS braced_music_list {
1202 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1204 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1205 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1211 | music_property_def
1215 context_modification:
1216 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1218 parser->lexer_->pop_state ();
1221 | WITH CONTEXT_MOD_IDENTIFIER
1225 | CONTEXT_MOD_IDENTIFIER
1229 | WITH embedded_scm_closed
1231 if (unsmob_context_mod ($2))
1234 parser->parser_error (@2, _ ("not a context mod"));
1235 $$ = Context_mod ().smobbed_copy ();
1240 optional_context_mod:
1244 | context_modification
1252 $$ = Context_mod ().smobbed_copy ();
1254 | context_mod_list context_mod {
1255 unsmob_context_mod ($1)->add_context_mod ($2);
1257 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1258 Context_mod *md = unsmob_context_mod ($2);
1260 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1262 | context_mod_list context_mod_embedded {
1263 unsmob_context_mod ($1)->add_context_mods
1264 (unsmob_context_mod ($2)->get_mods ());
1273 /* Music that can be parsed without lookahead */
1276 | complex_music_prefix closed_music
1278 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1285 | grouped_music_list
1289 simultaneous_music { $$ = $1; }
1290 | sequential_music { $$ = $1; }
1293 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1294 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1295 and this rule returns the reversed list of arguments. */
1297 function_arglist_skip:
1298 function_arglist_common
1299 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1301 $$ = scm_cons ($1, $3);
1302 } %prec FUNCTION_ARGLIST
1303 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1305 $$ = scm_cons ($1, $3);
1306 } %prec FUNCTION_ARGLIST
1307 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1309 $$ = scm_cons ($1, $3);
1310 } %prec FUNCTION_ARGLIST
1314 function_arglist_nonbackup_common:
1315 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1316 $$ = scm_cons ($4, $3);
1318 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1319 $$ = scm_cons ($4, $3);
1321 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1323 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1325 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1327 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1329 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1331 SCM n = scm_difference ($5, SCM_UNDEFINED);
1332 if (scm_is_true (scm_call_1 ($2, n)))
1333 $$ = scm_cons (n, $3);
1335 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1336 t->set_property ("digit", $5);
1337 $$ = t->unprotect ();
1338 if (scm_is_true (scm_call_1 ($2, $$)))
1339 $$ = scm_cons ($$, $3);
1341 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1345 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1347 $$ = check_scheme_arg (parser, @4,
1348 scm_difference ($5, SCM_UNDEFINED),
1351 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1353 $$ = check_scheme_arg (parser, @4,
1354 scm_difference ($5, SCM_UNDEFINED),
1359 function_arglist_closed_nonbackup:
1360 function_arglist_nonbackup_common
1361 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1363 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1365 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1367 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1371 function_arglist_nonbackup:
1372 function_arglist_nonbackup_common
1373 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1375 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1377 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1379 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1383 function_arglist_keep:
1384 function_arglist_common
1385 | function_arglist_backup
1388 function_arglist_closed_keep:
1389 function_arglist_closed_common
1390 | function_arglist_backup
1393 function_arglist_backup:
1394 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1396 if (scm_is_true (scm_call_1 ($2, $4)))
1398 $$ = scm_cons ($4, $3);
1400 $$ = scm_cons (loc_on_music (@3, $1), $3);
1401 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1404 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1406 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 (EVENT_IDENTIFIER, $4, @4);
1414 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1416 // There is no point interpreting a lyrics string as
1417 // an event, since we don't allow music possibly
1418 // followed by durations or postevent into closed
1419 // music, and we only accept closed music in optional
1420 // arguments at the moment. If this changes, more
1421 // complex schemes might become interesting here as
1422 // well: see how we do this at the mandatory argument
1424 if (scm_is_true (scm_call_1 ($2, $4)))
1425 $$ = scm_cons ($4, $3);
1427 $$ = scm_cons (loc_on_music (@3, $1), $3);
1428 MYBACKUP (LYRICS_STRING, $4, @4);
1431 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1433 if (scm_is_true (scm_call_1 ($2, $4)))
1436 MYREPARSE (@4, $2, UNSIGNED, $4);
1438 $$ = scm_cons (loc_on_music (@3, $1), $3);
1439 MYBACKUP (UNSIGNED, $4, @4);
1442 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1444 if (scm_is_true (scm_call_1 ($2, $4)))
1447 MYREPARSE (@4, $2, REAL, $4);
1449 $$ = scm_cons (loc_on_music (@3, $1), $3);
1450 MYBACKUP (REAL, $4, @4);
1453 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1455 if (scm_is_true (scm_call_1 ($2, $4)))
1457 $$ = scm_cons ($4, $3);
1459 $$ = scm_cons (loc_on_music (@3, $1), $3);
1460 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1463 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1465 if (scm_is_true (scm_call_1 ($2, $4)))
1467 $$ = scm_cons ($4, $3);
1469 $$ = scm_cons (loc_on_music (@3, $1), $3);
1470 MYBACKUP (FRACTION, $4, @4);
1473 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1475 SCM n = scm_difference ($5, SCM_UNDEFINED);
1476 if (scm_is_true (scm_call_1 ($2, n))) {
1478 MYREPARSE (@5, $2, REAL, n);
1480 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1481 t->set_property ("digit", $5);
1482 $$ = t->unprotect ();
1483 if (scm_is_true (scm_call_1 ($2, $$)))
1484 $$ = scm_cons ($$, $3);
1486 $$ = scm_cons (loc_on_music (@3, $1), $3);
1487 MYBACKUP (UNSIGNED, $5, @5);
1488 parser->lexer_->push_extra_token ('-');
1493 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1495 SCM n = scm_difference ($5, SCM_UNDEFINED);
1496 if (scm_is_true (scm_call_1 ($2, n))) {
1497 MYREPARSE (@5, $2, REAL, n);
1500 MYBACKUP (REAL, n, @5);
1503 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1505 SCM n = scm_difference ($5, SCM_UNDEFINED);
1506 if (scm_is_true (scm_call_1 ($2, n))) {
1507 $$ = scm_cons (n, $3);
1509 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1512 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1514 $$ = scm_cons ($4, $3);
1516 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1518 $$ = scm_cons ($4, $3);
1520 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1522 $$ = scm_cons ($1, $3);
1523 MYBACKUP(0, SCM_UNDEFINED, @3);
1525 | function_arglist_backup REPARSE embedded_scm_arg_closed
1527 $$ = check_scheme_arg (parser, @3,
1530 | function_arglist_backup REPARSE bare_number
1532 $$ = check_scheme_arg (parser, @3,
1535 | function_arglist_backup REPARSE fraction
1537 $$ = check_scheme_arg (parser, @3,
1543 function_arglist_common
1544 | function_arglist_nonbackup
1547 function_arglist_common:
1548 function_arglist_bare
1549 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1551 $$ = check_scheme_arg (parser, @3,
1554 | EXPECT_SCM function_arglist_closed_optional bare_number
1556 $$ = check_scheme_arg (parser, @3,
1559 | EXPECT_SCM function_arglist_closed_optional fraction
1561 $$ = check_scheme_arg (parser, @3,
1564 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1566 $$ = check_scheme_arg (parser, @3,
1569 | function_arglist_common_minus
1570 | function_arglist_common_lyric
1573 function_arglist_common_lyric:
1574 EXPECT_SCM function_arglist_optional lyric_element
1576 // We check how the predicate thinks about a lyrics
1577 // event or about a markup. If it accepts neither, we
1578 // backup the original token. Otherwise we commit to
1579 // taking the token. Depending on what the predicate
1580 // is willing to accept, we interpret as a string, as
1581 // a lyric event, or ambiguously (meaning that if
1582 // something looking like a duration or post event
1583 // follows, we take the event, otherwise the string).
1584 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1585 parser->default_duration_.smobbed_copy ());
1586 if (scm_is_true (scm_call_1 ($1, $3)))
1587 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1590 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1592 $$ = scm_cons ($3, $2);
1594 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1597 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1599 // This is going to flag a syntax error, we
1600 // know the predicate to be false.
1601 check_scheme_arg (parser, @3,
1605 | function_arglist_common_lyric REPARSE lyric_element_arg
1607 // This should never be false
1608 $$ = check_scheme_arg (parser, @3,
1613 function_arglist_common_minus:
1614 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1616 SCM n = scm_difference ($4, SCM_UNDEFINED);
1617 if (scm_is_true (scm_call_1 ($1, n))) {
1619 MYREPARSE (@4, $1, REAL, n);
1621 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1622 t->set_property ("digit", $4);
1623 $$ = t->unprotect ();
1624 if (scm_is_true (scm_call_1 ($1, $$)))
1625 $$ = scm_cons ($$, $2);
1627 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1631 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1634 SCM n = scm_difference ($4, SCM_UNDEFINED);
1635 MYREPARSE (@4, $1, REAL, n);
1637 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1639 SCM n = scm_difference ($4, SCM_UNDEFINED);
1640 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1642 | function_arglist_common_minus REPARSE bare_number
1644 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1648 function_arglist_closed:
1649 function_arglist_closed_common
1650 | function_arglist_closed_nonbackup
1653 function_arglist_closed_common:
1654 function_arglist_bare
1655 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1657 $$ = check_scheme_arg (parser, @3,
1660 | EXPECT_SCM function_arglist_closed_optional bare_number
1662 $$ = check_scheme_arg (parser, @3,
1665 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1667 SCM n = scm_difference ($4, SCM_UNDEFINED);
1668 if (scm_is_true (scm_call_1 ($1, n))) {
1669 $$ = scm_cons (n, $2);
1671 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1672 t->set_property ("digit", $4);
1673 $$ = t->unprotect ();
1674 if (scm_is_true (scm_call_1 ($1, $$)))
1675 $$ = scm_cons ($$, $2);
1677 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1681 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1683 $$ = check_scheme_arg (parser, @3,
1684 scm_difference ($4, SCM_UNDEFINED),
1687 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1689 $$ = check_scheme_arg (parser, @3,
1690 scm_difference ($4, SCM_UNDEFINED),
1693 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1695 $$ = check_scheme_arg (parser, @3,
1698 | EXPECT_SCM function_arglist_closed_optional fraction
1700 $$ = check_scheme_arg (parser, @3,
1703 | EXPECT_SCM function_arglist_optional lyric_element
1705 $$ = check_scheme_arg (parser, @3,
1710 function_arglist_optional:
1711 function_arglist_keep %prec FUNCTION_ARGLIST
1712 | function_arglist_backup BACKUP
1713 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1715 $$ = scm_cons ($1, $3);
1717 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1719 $$ = scm_cons ($1, $3);
1723 function_arglist_closed_optional:
1724 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1725 | function_arglist_backup BACKUP
1726 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1728 $$ = scm_cons ($1, $3);
1730 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1732 $$ = scm_cons ($1, $3);
1736 embedded_scm_closed:
1738 | scm_function_call_closed
1741 embedded_scm_arg_closed:
1742 embedded_scm_bare_arg
1743 | scm_function_call_closed
1747 scm_function_call_closed:
1748 SCM_FUNCTION function_arglist_closed {
1749 $$ = MAKE_SYNTAX ("music-function", @$,
1751 } %prec FUNCTION_ARGLIST
1754 function_arglist_bare:
1755 EXPECT_NO_MORE_ARGS {
1758 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1759 $$ = scm_cons ($3, $2);
1761 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1762 $$ = scm_cons ($3, $2);
1764 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1765 $$ = scm_cons ($1, $3);
1767 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1768 $$ = scm_cons ($1, $3);
1770 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1771 $$ = scm_cons ($1, $3);
1775 music_function_call:
1776 MUSIC_FUNCTION function_arglist {
1777 $$ = MAKE_SYNTAX ("music-function", @$,
1784 /**/ { $$ = SCM_EOL; }
1785 | '=' simple_string {
1792 | repeated_music { $$ = $1; }
1793 | re_rhythmed_music { $$ = $1; }
1794 | complex_music_prefix music
1796 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1800 complex_music_prefix:
1801 CONTEXT simple_string optional_id optional_context_mod {
1802 Context_mod *ctxmod = unsmob_context_mod ($4);
1805 mods = ctxmod->get_mods ();
1806 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1808 | NEWCONTEXT simple_string optional_id optional_context_mod {
1809 Context_mod *ctxmod = unsmob_context_mod ($4);
1812 mods = ctxmod->get_mods ();
1813 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1818 mode_changing_head grouped_music_list {
1819 if ($1 == ly_symbol2scm ("chords"))
1821 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1827 parser->lexer_->pop_state ();
1829 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1830 Context_mod *ctxmod = unsmob_context_mod ($2);
1833 mods = ctxmod->get_mods ();
1834 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1835 if ($1 == ly_symbol2scm ("ChordNames"))
1837 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1839 parser->lexer_->pop_state ();
1845 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1846 parser->lexer_->push_note_state (alist_to_hashq (nn));
1848 $$ = ly_symbol2scm ("notes");
1852 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1853 parser->lexer_->push_note_state (alist_to_hashq (nn));
1855 $$ = ly_symbol2scm ("drums");
1858 parser->lexer_->push_figuredbass_state ();
1860 $$ = ly_symbol2scm ("figures");
1863 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1864 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1865 nn = parser->lexer_->lookup_identifier ("pitchnames");
1866 parser->lexer_->push_chord_state (alist_to_hashq (nn));
1867 $$ = ly_symbol2scm ("chords");
1871 { parser->lexer_->push_lyric_state ();
1872 $$ = ly_symbol2scm ("lyrics");
1876 mode_changing_head_with_context:
1878 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1879 parser->lexer_->push_note_state (alist_to_hashq (nn));
1881 $$ = ly_symbol2scm ("DrumStaff");
1884 parser->lexer_->push_figuredbass_state ();
1886 $$ = ly_symbol2scm ("FiguredBass");
1889 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1890 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1891 nn = parser->lexer_->lookup_identifier ("pitchnames");
1892 parser->lexer_->push_chord_state (alist_to_hashq (nn));
1893 $$ = ly_symbol2scm ("ChordNames");
1896 { parser->lexer_->push_lyric_state ();
1897 $$ = ly_symbol2scm ("Lyrics");
1902 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1905 /* Can also use music at the expensive of two S/Rs similar to
1906 \repeat \alternative */
1907 parser->lexer_->pop_state ();
1909 $$ = scm_cons ($3, SCM_EOL);
1911 | new_lyrics ADDLYRICS {
1912 parser->lexer_->push_lyric_state ();
1914 parser->lexer_->pop_state ();
1915 $$ = scm_cons ($4, $1);
1920 composite_music new_lyrics {
1921 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1923 | LYRICSTO simple_string {
1924 parser->lexer_->push_lyric_state ();
1926 parser->lexer_->pop_state ();
1927 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1932 CHANGE STRING '=' STRING {
1933 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1938 property_path_revved:
1939 embedded_scm_closed {
1940 $$ = scm_cons ($1, SCM_EOL);
1942 | property_path_revved embedded_scm_closed {
1943 $$ = scm_cons ($2, $1);
1948 property_path_revved {
1949 $$ = scm_reverse_x ($1, SCM_EOL);
1955 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1956 scm_string_to_symbol ($1), $3);
1958 | UNSET simple_string {
1959 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1960 scm_string_to_symbol ($2));
1962 | OVERRIDE simple_string property_path '=' scalar {
1963 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1964 scm_string_to_symbol ($2), $5),
1967 | REVERT simple_string embedded_scm {
1968 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1969 scm_string_to_symbol ($2), $3);
1974 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1975 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1977 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1978 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1979 | DENIES { $$ = ly_symbol2scm ("denies"); }
1981 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1982 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1983 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1984 | NAME { $$ = ly_symbol2scm ("context-name"); }
1988 property_operation { $$ = $1; }
1989 | context_def_mod STRING {
1990 $$ = scm_list_2 ($1, $2);
1992 | context_def_mod embedded_scm
1994 if (!scm_is_string ($2)
1995 && ly_symbol2scm ("consists") != $1
1996 && ly_symbol2scm ("remove") != $1)
1999 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2003 $$ = scm_list_2 ($1, $2);
2010 if (!is_regular_identifier ($1))
2012 @$.error (_("Grob name should be alphanumeric"));
2015 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
2016 scm_string_to_symbol ($1));
2018 | simple_string '.' simple_string {
2019 $$ = scm_list_2 (scm_string_to_symbol ($1),
2020 scm_string_to_symbol ($3));
2024 simple_music_property_def:
2025 OVERRIDE context_prop_spec property_path '=' scalar {
2026 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
2027 ly_symbol2scm ("OverrideProperty"),
2032 | REVERT context_prop_spec embedded_scm {
2033 $$ = scm_list_4 (scm_car ($2),
2034 ly_symbol2scm ("RevertProperty"),
2038 | SET context_prop_spec '=' scalar {
2039 $$ = scm_list_4 (scm_car ($2),
2040 ly_symbol2scm ("PropertySet"),
2044 | UNSET context_prop_spec {
2045 $$ = scm_list_3 (scm_car ($2),
2046 ly_symbol2scm ("PropertyUnset"),
2052 simple_music_property_def {
2053 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2061 | STRING_IDENTIFIER {
2064 | string '+' string {
2065 $$ = scm_string_append (scm_list_2 ($1, $3));
2069 simple_string: STRING {
2075 | STRING_IDENTIFIER {
2088 embedded_scm_arg_closed
2096 simple_element post_events {
2097 // Let the rhythmic music iterator sort this mess out.
2098 if (scm_is_pair ($2)) {
2099 if (unsmob_pitch ($1)) {
2100 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
2101 n->set_property ("pitch", $1);
2102 n->set_property ("duration",
2103 parser->default_duration_.smobbed_copy ());
2104 $$ = n->unprotect ();
2106 unsmob_music ($$)->set_property ("articulations",
2107 scm_reverse_x ($2, SCM_EOL));
2110 | simple_chord_elements post_events {
2111 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2114 /* why is this giving wrong start location? -ns
2116 i.set_location (@1, @2);
2117 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2119 | CHORD_REPETITION optional_notemode_duration post_events {
2121 i.set_location (@1, @3);
2122 $$ = MAKE_SYNTAX ("repetition-chord", i,
2123 $2, scm_reverse_x ($3, SCM_EOL));
2125 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2127 i.set_location (@1, @3);
2128 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2129 scm_reverse_x ($3, SCM_EOL));
2132 | note_chord_element
2137 chord_body optional_notemode_duration post_events
2139 Music *m = unsmob_music ($1);
2140 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2141 SCM es = m->get_property ("elements");
2142 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2144 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2145 unsmob_music (scm_car (s))->set_property ("duration", dur);
2146 es = ly_append2 (es, postevs);
2148 m-> set_property ("elements", es);
2150 $$ = m->self_scm ();
2155 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2157 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2161 chord_body_elements:
2162 /* empty */ { $$ = SCM_EOL; }
2163 | chord_body_elements chord_body_element {
2164 if (!SCM_UNBNDP ($2))
2165 $$ = scm_cons ($2, $1);
2170 pitch exclamations questions octave_check post_events
2177 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2178 n->set_property ("pitch", $1);
2180 n->set_property ("cautionary", SCM_BOOL_T);
2181 if (ex % 2 || q % 2)
2182 n->set_property ("force-accidental", SCM_BOOL_T);
2184 if (scm_is_pair (post)) {
2185 SCM arts = scm_reverse_x (post, SCM_EOL);
2186 n->set_property ("articulations", arts);
2188 if (scm_is_number (check))
2190 int q = scm_to_int (check);
2191 n->set_property ("absolute-octave", scm_from_int (q-1));
2194 $$ = n->unprotect ();
2196 | DRUM_PITCH post_events {
2197 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2198 n->set_property ("drum-type", $1);
2200 if (scm_is_pair ($2)) {
2201 SCM arts = scm_reverse_x ($2, SCM_EOL);
2202 n->set_property ("articulations", arts);
2204 $$ = n->unprotect ();
2206 | music_function_chord_body
2208 Music *m = unsmob_music ($1);
2210 while (m && m->is_mus_type ("music-wrapper-music")) {
2211 $$ = m->get_property ("element");
2212 m = unsmob_music ($$);
2215 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2216 parser->parser_error (@$, _ ("not a rhythmic event"));
2222 music_function_chord_body:
2227 // Event functions may only take closed arglists, otherwise it would
2228 // not be clear whether a following postevent should be associated
2229 // with the last argument of the event function or with the expression
2230 // for which the function call acts itself as event.
2232 music_function_event:
2233 MUSIC_FUNCTION function_arglist_closed {
2234 $$ = MAKE_SYNTAX ("music-function", @$,
2239 event_function_event:
2240 EVENT_FUNCTION function_arglist_closed {
2241 $$ = MAKE_SYNTAX ("music-function", @$,
2251 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2252 m->set_property ("span-direction", scm_from_int (START));
2253 $$ = m->unprotect();
2256 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2257 m->set_property ("span-direction", scm_from_int (STOP));
2258 $$ = m->unprotect ();
2261 $$ = MAKE_SYNTAX ("voice-separator", @$);
2264 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2266 Music *m = unsmob_music (pipe);
2271 $$ = m->unprotect ();
2274 $$ = MAKE_SYNTAX ("bar-check", @$);
2281 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2293 | post_events post_event {
2294 unsmob_music ($2)->set_spot (@2);
2295 $$ = scm_cons ($2, $$);
2299 post_event_nofinger:
2300 direction_less_event {
2303 | script_dir music_function_event {
2307 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2311 if (!parser->lexer_->is_lyric_state ())
2312 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2313 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2316 if (!parser->lexer_->is_lyric_state ())
2317 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2318 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2320 | script_dir direction_reqd_event {
2323 Music *m = unsmob_music ($2);
2324 m->set_property ("direction", scm_from_int ($1));
2328 | script_dir direction_less_event {
2331 Music *m = unsmob_music ($2);
2332 m->set_property ("direction", scm_from_int ($1));
2336 | string_number_event
2340 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2345 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2356 string_number_event:
2358 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2359 s->set_property ("string-number", scm_from_int ($1));
2360 $$ = s->unprotect ();
2364 direction_less_char:
2366 $$ = ly_symbol2scm ("bracketOpenSymbol");
2369 $$ = ly_symbol2scm ("bracketCloseSymbol");
2372 $$ = ly_symbol2scm ("tildeSymbol");
2375 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2378 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2381 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2384 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2387 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2390 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2393 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2397 direction_less_event:
2398 direction_less_char {
2399 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2401 if (unsmob_music (predefd))
2403 m = unsmob_music (predefd)->clone ();
2408 m = MY_MAKE_MUSIC ("Music", @$);
2410 $$ = m->unprotect ();
2412 | EVENT_IDENTIFIER {
2416 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2417 a->set_property ("tremolo-type", scm_from_int ($1));
2418 $$ = a->unprotect ();
2420 | event_function_event
2423 direction_reqd_event:
2427 | script_abbreviation {
2428 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2429 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2430 if (scm_is_string (s))
2431 a->set_property ("articulation-type", s);
2432 else parser->parser_error (@1, _ ("expecting string as script definition"));
2433 $$ = a->unprotect ();
2438 /**/ { $$ = SCM_EOL; }
2439 | '=' { $$ = scm_from_int (0); }
2440 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2441 | '=' sup_quotes { $$ = scm_from_int ($2); }
2466 | NOTENAME_PITCH sup_quotes {
2467 Pitch p = *unsmob_pitch ($1);
2468 p = p.transposed (Pitch ($2,0,0));
2469 $$ = p.smobbed_copy ();
2471 | NOTENAME_PITCH sub_quotes {
2472 Pitch p =* unsmob_pitch ($1);
2473 p = p.transposed (Pitch (-$2,0,0));
2474 $$ = p.smobbed_copy ();
2486 | TONICNAME_PITCH sup_quotes {
2487 Pitch p = *unsmob_pitch ($1);
2488 p = p.transposed (Pitch ($2,0,0));
2489 $$ = p.smobbed_copy ();
2491 | TONICNAME_PITCH sub_quotes {
2492 Pitch p = *unsmob_pitch ($1);
2494 p = p.transposed (Pitch (-$2,0,0));
2495 $$ = p.smobbed_copy ();
2506 pitch_also_in_chords:
2513 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2514 t->set_property ("text", $1);
2515 $$ = t->unprotect ();
2518 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2519 t->set_property ("text",
2520 make_simple_markup ($1));
2521 $$ = t->unprotect ();
2527 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2528 t->set_property ("digit", $1);
2529 $$ = t->unprotect ();
2533 script_abbreviation:
2535 $$ = scm_from_locale_string ("Hat");
2538 $$ = scm_from_locale_string ("Plus");
2541 $$ = scm_from_locale_string ("Dash");
2544 $$ = scm_from_locale_string ("Bar");
2547 $$ = scm_from_locale_string ("Larger");
2550 $$ = scm_from_locale_string ("Dot");
2553 $$ = scm_from_locale_string ("Underscore");
2560 | '-' { $$ = CENTER; }
2564 multiplied_duration {
2569 maybe_notemode_duration:
2573 | multiplied_duration {
2575 parser->default_duration_ = *unsmob_duration ($$);
2580 optional_notemode_duration:
2581 maybe_notemode_duration
2583 if (SCM_UNBNDP ($$))
2584 $$ = parser->default_duration_.smobbed_copy ();
2589 bare_unsigned dots {
2591 if (!is_duration ($1))
2592 parser->parser_error (@1, _f ("not a duration: %d", $1));
2596 $$ = Duration (len, $2).smobbed_copy ();
2598 | DURATION_IDENTIFIER dots {
2599 Duration *d = unsmob_duration ($1);
2600 Duration k (d->duration_log (), d->dot_count () + $2);
2601 k = k.compressed (d->factor ());
2607 multiplied_duration:
2611 | multiplied_duration '*' bare_unsigned {
2612 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2614 | multiplied_duration '*' FRACTION {
2615 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2617 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2622 FRACTION { $$ = $1; }
2623 | UNSIGNED '/' UNSIGNED {
2624 $$ = scm_cons ($1, $3);
2641 | ':' bare_unsigned {
2642 if (!is_duration ($2))
2643 parser->parser_error (@2, _f ("not a duration: %d", $2));
2649 UNSIGNED { $$ = $1; }
2650 | STRING { $$ = $1; }
2651 | full_markup { $$ = $1; }
2654 figured_bass_alteration:
2655 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2656 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2657 | '!' { $$ = scm_from_int (0); }
2662 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2663 $$ = bfr->unprotect ();
2666 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2667 $$ = bfr->self_scm ();
2669 if (scm_is_number ($1))
2670 bfr->set_property ("figure", $1);
2671 else if (Text_interface::is_markup ($1))
2672 bfr->set_property ("text", $1);
2678 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2680 | bass_figure figured_bass_alteration {
2681 Music *m = unsmob_music ($1);
2682 if (scm_to_double ($2)) {
2683 SCM salter = m->get_property ("alteration");
2684 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2685 m->set_property ("alteration",
2686 scm_sum (alter, $2));
2688 m->set_property ("alteration", scm_from_int (0));
2691 | bass_figure figured_bass_modification {
2692 Music *m = unsmob_music ($1);
2693 if ($2 == ly_symbol2scm ("plus"))
2695 m->set_property ("augmented", SCM_BOOL_T);
2697 else if ($2 == ly_symbol2scm ("slash"))
2699 m->set_property ("diminished", SCM_BOOL_T);
2701 else if ($2 == ly_symbol2scm ("exclamation"))
2703 m->set_property ("no-continuation", SCM_BOOL_T);
2705 else if ($2 == ly_symbol2scm ("backslash"))
2707 m->set_property ("augmented-slash", SCM_BOOL_T);
2713 figured_bass_modification:
2715 $$ = ly_symbol2scm ("plus");
2718 $$ = ly_symbol2scm ("exclamation");
2721 $$ = ly_symbol2scm ("slash");
2724 $$ = ly_symbol2scm ("backslash");
2734 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2742 | figure_list br_bass_figure {
2743 $$ = scm_cons ($2, $1);
2748 FIGURE_OPEN figure_list FIGURE_CLOSE {
2749 $$ = scm_reverse_x ($2, SCM_EOL);
2760 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2761 if (!parser->lexer_->is_note_state ())
2762 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2763 if ($2 || $3 || scm_is_number ($4) || !SCM_UNBNDP ($5) || $6)
2767 n = MY_MAKE_MUSIC ("RestEvent", @$);
2769 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2771 n->set_property ("pitch", $1);
2772 if (SCM_UNBNDP ($5))
2773 n->set_property ("duration",
2774 parser->default_duration_.smobbed_copy ());
2776 n->set_property ("duration", $5);
2778 if (scm_is_number ($4))
2780 int q = scm_to_int ($4);
2781 n->set_property ("absolute-octave", scm_from_int (q-1));
2785 n->set_property ("cautionary", SCM_BOOL_T);
2786 if ($2 % 2 || $3 % 2)
2787 n->set_property ("force-accidental", SCM_BOOL_T);
2789 $$ = n->unprotect ();
2792 | DRUM_PITCH optional_notemode_duration {
2793 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2794 n->set_property ("duration", $2);
2795 n->set_property ("drum-type", $1);
2797 $$ = n->unprotect ();
2799 | RESTNAME optional_notemode_duration {
2801 if (ly_scm2string ($1) == "s") {
2803 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2806 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2809 ev->set_property ("duration", $2);
2810 $$ = ev->unprotect ();
2814 simple_chord_elements:
2816 if (!parser->lexer_->is_chord_state ())
2817 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2820 | figure_spec optional_notemode_duration {
2821 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2823 unsmob_music (scm_car (s))->set_property ("duration", $2);
2840 | lyric_element multiplied_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));
2846 | lyric_element post_event post_events {
2847 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2848 parser->default_duration_.smobbed_copy ());
2849 unsmob_music ($$)->set_property
2850 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2852 | LYRIC_ELEMENT optional_notemode_duration post_events {
2853 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2854 if (scm_is_pair ($3))
2855 unsmob_music ($$)->set_property
2856 ("articulations", scm_reverse_x ($3, SCM_EOL));
2861 lyric_element_music:
2862 lyric_element optional_notemode_duration post_events {
2863 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2864 if (scm_is_pair ($3))
2865 unsmob_music ($$)->set_property
2866 ("articulations", scm_reverse_x ($3, SCM_EOL));
2871 steno_tonic_pitch optional_notemode_duration {
2872 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2874 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2875 SCM its = scm_reverse_x ($4, SCM_EOL);
2876 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2884 | chord_items chord_item {
2885 $$ = scm_cons ($2, $$);
2891 $$ = ly_symbol2scm ("chord-colon");
2894 $$ = ly_symbol2scm ("chord-caret");
2896 | CHORD_SLASH steno_tonic_pitch {
2897 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2899 | CHORD_BASS steno_tonic_pitch {
2900 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2909 $$ = scm_reverse_x ($1, SCM_EOL);
2917 step_number { $$ = scm_cons ($1, SCM_EOL); }
2918 | step_numbers '.' step_number {
2919 $$ = scm_cons ($3, $$);
2925 $$ = make_chord_step ($1, 0);
2927 | bare_unsigned '+' {
2928 $$ = make_chord_step ($1, SHARP_ALTERATION);
2930 | bare_unsigned CHORD_MINUS {
2931 $$ = make_chord_step ($1, FLAT_ALTERATION);
2937 $$ = scm_from_int ($1);
2939 | bare_unsigned '~' bare_unsigned {
2940 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2947 TODO: should deprecate in favor of Scheme?
2951 number_expression '+' number_term {
2952 $$ = scm_sum ($1, $3);
2954 | number_expression '-' number_term {
2955 $$ = scm_difference ($1, $3);
2964 | number_factor '*' number_factor {
2965 $$ = scm_product ($1, $3);
2967 | number_factor '/' number_factor {
2968 $$ = scm_divide ($1, $3);
2973 '-' number_factor { /* %prec UNARY_MINUS */
2974 $$ = scm_difference ($2, SCM_UNDEFINED);
2982 | UNSIGNED NUMBER_IDENTIFIER {
2983 $$ = scm_product ($1, $2);
2985 | REAL NUMBER_IDENTIFIER {
2986 $$ = scm_product ($1, $2);
2998 $$ = scm_to_int ($1);
3009 | exclamations '!' { $$ ++; }
3014 | questions '?' { $$ ++; }
3018 This should be done more dynamically if possible.
3022 LYRIC_MARKUP_IDENTIFIER {
3026 { parser->lexer_->push_markup_state (); }
3029 parser->lexer_->pop_state ();
3034 MARKUPLIST_IDENTIFIER {
3038 { parser->lexer_->push_markup_state (); }
3041 parser->lexer_->pop_state ();
3050 { parser->lexer_->push_markup_state (); }
3053 parser->lexer_->pop_state ();
3059 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3061 | markup_head_1_list simple_markup {
3062 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3072 if (Text_interface::is_markup ($1))
3073 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3074 else if (Text_interface::is_markup_list ($1))
3075 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3077 parser->parser_error (@1, _ ("not a markup"));
3078 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3085 MARKUPLIST_IDENTIFIER {
3088 | markup_composed_list {
3091 | markup_braced_list {
3094 | markup_command_list {
3095 $$ = scm_list_1 ($1);
3097 | markup_scm MARKUPLIST_IDENTIFIER
3103 markup_composed_list:
3104 markup_head_1_list markup_braced_list {
3105 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3111 '{' markup_braced_list_body '}' {
3112 $$ = scm_reverse_x ($2, SCM_EOL);
3116 markup_braced_list_body:
3117 /* empty */ { $$ = SCM_EOL; }
3118 | markup_braced_list_body markup {
3119 $$ = scm_cons ($2, $1);
3121 | markup_braced_list_body markup_list {
3122 $$ = scm_reverse_x ($2, $1);
3126 markup_command_list:
3127 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3128 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3132 markup_command_basic_arguments:
3133 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3134 $$ = scm_cons ($3, $2);
3136 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3137 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3139 | EXPECT_NO_MORE_ARGS {
3144 markup_command_list_arguments:
3145 markup_command_basic_arguments { $$ = $1; }
3146 | EXPECT_MARKUP markup_command_list_arguments markup {
3147 $$ = scm_cons ($3, $2);
3152 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3153 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3158 markup_head_1_item {
3159 $$ = scm_list_1 ($1);
3161 | markup_head_1_list markup_head_1_item {
3162 $$ = scm_cons ($2, $1);
3168 $$ = make_simple_markup ($1);
3170 | MARKUP_IDENTIFIER {
3173 | LYRIC_MARKUP_IDENTIFIER {
3176 | STRING_IDENTIFIER {
3180 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3181 parser->lexer_->push_note_state (alist_to_hashq (nn));
3182 } '{' score_body '}' {
3184 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3186 parser->lexer_->pop_state ();
3188 | MARKUP_FUNCTION markup_command_basic_arguments {
3189 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3191 | markup_scm MARKUP_IDENTIFIER
3198 markup_head_1_list simple_markup {
3199 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3200 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3210 Lily_parser::set_yydebug (bool x)
3216 Lily_parser::do_yyparse ()
3227 It is a little strange to have this function in this file, but
3228 otherwise, we have to import music classes into the lexer.
3232 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3234 if (scm_is_string (sid)) {
3236 return STRING_IDENTIFIER;
3237 } else if (unsmob_book (sid)) {
3238 Book *book = unsmob_book (sid)->clone ();
3239 *destination = book->self_scm ();
3242 return BOOK_IDENTIFIER;
3243 } else if (scm_is_number (sid)) {
3245 return NUMBER_IDENTIFIER;
3246 } else if (unsmob_context_def (sid)) {
3247 Context_def *def= unsmob_context_def (sid)->clone ();
3249 *destination = def->self_scm ();
3252 return CONTEXT_DEF_IDENTIFIER;
3253 } else if (unsmob_context_mod (sid)) {
3254 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3256 return CONTEXT_MOD_IDENTIFIER;
3257 } else if (unsmob_score (sid)) {
3258 Score *score = new Score (*unsmob_score (sid));
3259 *destination = score->self_scm ();
3261 score->unprotect ();
3262 return SCORE_IDENTIFIER;
3263 } else if (Music *mus = unsmob_music (sid)) {
3264 mus = mus->clone ();
3265 *destination = mus->self_scm ();
3266 unsmob_music (*destination)->
3267 set_property ("origin", make_input (last_input_));
3269 bool is_event = mus->is_mus_type ("post-event");
3271 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3272 } else if (unsmob_pitch (sid)) {
3273 *destination = unsmob_pitch (sid)->smobbed_copy ();
3274 return PITCH_IDENTIFIER;
3275 } else if (unsmob_duration (sid)) {
3276 *destination = unsmob_duration (sid)->smobbed_copy ();
3277 return DURATION_IDENTIFIER;
3278 } else if (unsmob_output_def (sid)) {
3279 Output_def *p = unsmob_output_def (sid);
3282 *destination = p->self_scm ();
3284 return OUTPUT_DEF_IDENTIFIER;
3285 } else if (Text_interface::is_markup (sid)) {
3287 if (is_lyric_state ())
3288 return LYRIC_MARKUP_IDENTIFIER;
3289 return MARKUP_IDENTIFIER;
3290 } else if (Text_interface::is_markup_list (sid)) {
3292 return MARKUPLIST_IDENTIFIER;
3299 get_next_unique_context_id ()
3301 return scm_from_locale_string ("$uniqueContextId");
3306 get_next_unique_lyrics_context_id ()
3308 static int new_context_count;
3310 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3311 return scm_from_locale_string (s);
3314 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3315 SCM arg, SCM args, SCM pred)
3317 args = scm_cons (arg, args);
3318 if (scm_is_true (scm_call_1 (pred, arg)))
3320 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3321 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3322 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3326 SCM loc_on_music (Input loc, SCM arg)
3328 if (Music *m = unsmob_music (arg))
3332 return m->unprotect ();
3338 is_regular_identifier (SCM id)
3340 string str = ly_scm2string (id);
3341 char const *s = str.c_str ();
3350 v = v && isalnum (*s);
3357 make_music_with_input (SCM name, Input where)
3359 Music *m = make_music_by_name (name);
3360 m->set_spot (where);
3365 make_simple_markup (SCM a)
3373 return t && t == 1 << intlog2 (t);
3377 set_music_properties (Music *p, SCM a)
3379 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3380 p->set_property (scm_caar (k), scm_cdar (k));
3385 make_chord_step (int step, Rational alter)
3388 alter += FLAT_ALTERATION;
3392 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3393 return m.smobbed_copy ();
3398 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3400 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3401 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3402 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3404 unsmob_music (scm_car (s))->set_spot (loc);
3410 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3412 Lily_lexer *lex = parser->lexer_;
3416 lex->prepare_for_next_token ();
3417 return lex->yylex ();