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.
32 #define yyerror Lily_parser::parser_error
34 /* We use custom location type: Input objects */
36 #define YYLLOC_DEFAULT(Current,Rhs,N) \
37 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
42 %parse-param {Lily_parser *parser}
43 %lex-param {Lily_parser *parser}
47 /* We use SCMs to do strings, because it saves us the trouble of
48 deleting them. Let's hope that a stack overflow doesn't trigger a move
49 of the parse stack onto the heap. */
55 /* The above precedences tackle the shift/reduce problem
58 \repeat .. \alternative
60 \repeat { \repeat .. \alternative }
64 \repeat { \repeat } \alternative
70 /* ADDLYRICS needs to have lower precedence than argument scanning,
71 * or we won't be able to tell music apart from closed_music without
72 * lookahead in the context of function calls.
77 /* \default is only applied after exhausting function arguments */
79 %nonassoc FUNCTION_ARGLIST
81 /* expressions with units are permitted into argument lists */
83 %right PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
84 UNSIGNED REAL DURATION_IDENTIFIER ':'
86 /* The above are the symbols that can start optional function arguments
87 that are recognized in the grammar rather than by predicate
90 %nonassoc NUMBER_IDENTIFIER '/'
92 /* Number-unit expressions, where permitted, are concatenated into
93 * function arguments, just like fractions and tremoli. Tremoli must
94 * not have higher precedence than UNSIGNED, or Lilypond will not
95 * join ':' with a following optional number.
108 %{ // -*-Fundamental-*-
113 * The rules for who is protecting what are very shady. Uniformise
116 * There are too many lexical modes?
127 #include "context-def.hh"
128 #include "context-mod.hh"
129 #include "dimensions.hh"
130 #include "file-path.hh"
132 #include "international.hh"
133 #include "lily-guile.hh"
134 #include "lily-lexer.hh"
135 #include "lily-parser.hh"
139 #include "output-def.hh"
140 #include "paper-book.hh"
141 #include "scm-hash.hh"
143 #include "text-interface.hh"
147 Lily_parser::parser_error (Input const *i, Lily_parser *parser, string s)
149 parser->parser_error (*i, s);
152 #define MYBACKUP(Token, Value, Location) \
154 if (yychar == YYEMPTY) \
157 parser->lexer_->push_extra_token (Token, Value); \
158 parser->lexer_->push_extra_token (BACKUP); \
160 parser->parser_error \
161 (Location, _("Too much lookahead")); \
166 #define MYREPARSE(Location, Pred, Token, Value) \
168 if (yychar == YYEMPTY) \
170 parser->lexer_->push_extra_token (Token, Value); \
171 parser->lexer_->push_extra_token (REPARSE, \
174 parser->parser_error \
175 (Location, _("Too much lookahead")); \
184 Output_def *outputdef;
193 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
196 - Don't use lily module, create a new module instead.
197 - delay application of the function
199 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
200 scm_apply_0 (proc, args)
201 /* Syntactic Sugar. */
202 #define MAKE_SYNTAX(name, location, ...) \
203 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (location) , ##__VA_ARGS__, SCM_UNDEFINED))
204 #define START_MAKE_SYNTAX(name, ...) \
205 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
206 #define FINISH_MAKE_SYNTAX(start, location, ...) \
207 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)))))
209 SCM get_next_unique_context_id ();
210 SCM get_next_unique_lyrics_context_id ();
217 #define _(x) gettext (x)
221 static Music *make_music_with_input (SCM name, Input where);
222 SCM check_scheme_arg (Lily_parser *parser, Input loc,
223 SCM arg, SCM args, SCM pred);
224 SCM loc_on_music (Input loc, SCM arg);
225 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
226 SCM make_chord_step (int step, Rational alter);
227 SCM make_simple_markup (SCM a);
228 bool is_duration (int t);
229 bool is_regular_identifier (SCM id);
230 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
231 void set_music_properties (Music *p, SCM a);
235 /* The third option is an alias that will be used to display the
236 syntax error. Bison CVS now correctly handles backslash escapes.
238 FIXME: Bison needs to translate some of these, eg, STRING.
242 /* Keyword tokens with plain escaped name. */
243 %token END_OF_FILE 0 "end of input"
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> music_embedded
409 %type <scm> music_or_context_def
410 %type <scm> complex_music
411 %type <scm> complex_music_prefix
412 %type <scm> mode_changed_music
413 %type <scm> repeated_music
414 %type <scm> sequential_music
415 %type <scm> simple_music
416 %type <scm> simultaneous_music
417 %type <scm> chord_body
418 %type <scm> chord_body_element
419 %type <scm> command_element
420 %type <scm> command_event
421 %type <scm> context_modification
422 %type <scm> context_change
423 %type <scm> direction_less_event
424 %type <scm> direction_reqd_event
425 %type <scm> embedded_lilypond
426 %type <scm> event_chord
427 %type <scm> fingering
428 %type <scm> gen_text_def
429 %type <scm> music_property_def
430 %type <scm> note_chord_element
431 %type <scm> post_event
432 %type <scm> post_event_nofinger
433 %type <scm> re_rhythmed_music
434 %type <scm> simple_element
435 %type <scm> simple_music_property_def
436 %type <scm> start_symbol
437 %type <scm> string_number_event
438 %type <scm> tempo_event
440 %type <outputdef> output_def_body
441 %type <outputdef> output_def_head
442 %type <outputdef> output_def_head_with_mode_switch
443 %type <outputdef> output_def
444 %type <outputdef> paper_block
446 %type <scm> music_function_call
447 %type <scm> music_list
448 %type <scm> assignment_id
449 %type <scm> bare_number
450 %type <scm> bare_number_closed
451 %type <scm> unsigned_number
452 %type <scm> bass_figure
453 %type <scm> figured_bass_modification
454 %type <scm> br_bass_figure
455 %type <scm> bass_number
456 %type <scm> chord_body_elements
457 %type <scm> chord_item
458 %type <scm> chord_items
459 %type <scm> chord_separator
460 %type <scm> context_def_mod
461 %type <scm> context_def_spec_block
462 %type <scm> context_def_spec_body
463 %type <scm> context_mod
464 %type <scm> context_mod_arg
465 %type <scm> context_mod_embedded
466 %type <scm> context_mod_list
467 %type <scm> context_prop_spec
468 %type <scm> direction_less_char
469 %type <scm> duration_length
470 %type <scm> embedded_scm
471 %type <scm> embedded_scm_arg
472 %type <scm> embedded_scm_arg_closed
473 %type <scm> embedded_scm_bare
474 %type <scm> embedded_scm_bare_arg
475 %type <scm> embedded_scm_closed
476 %type <scm> event_function_event
477 %type <scm> figure_list
478 %type <scm> figure_spec
479 %type <scm> full_markup
480 %type <scm> full_markup_list
481 %type <scm> function_arglist
482 %type <scm> function_arglist_optional
483 %type <scm> function_arglist_backup
484 %type <scm> function_arglist_nonbackup
485 %type <scm> function_arglist_nonbackup_common
486 %type <scm> function_arglist_closed_nonbackup
487 %type <scm> function_arglist_skip
488 %type <scm> function_arglist_bare
489 %type <scm> function_arglist_closed
490 %type <scm> function_arglist_closed_optional
491 %type <scm> function_arglist_common
492 %type <scm> function_arglist_common_lyric
493 %type <scm> function_arglist_common_minus
494 %type <scm> function_arglist_closed_common
495 %type <scm> function_arglist_keep
496 %type <scm> function_arglist_closed_keep
497 %type <scm> identifier_init
499 %type <scm> lilypond_header
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_call_closed
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 (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_->add_scope (get_header (parser));
593 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
597 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
598 scm_call_2 (proc, parser->self_scm (), book->self_scm ());
603 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
604 scm_call_2 (proc, parser->self_scm (), bookpart->self_scm ());
605 bookpart->unprotect ();
610 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
611 scm_call_2 (proc, parser->self_scm (), score->self_scm ());
615 Music *music = unsmob_music ($1);
616 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
617 scm_call_2 (proc, parser->self_scm (), music->self_scm ());
620 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
621 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
624 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
625 scm_call_2 (proc, parser->self_scm (), $1);
629 Output_def * od = $1;
631 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
632 id = ly_symbol2scm ("$defaultpaper");
633 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
634 id = ly_symbol2scm ("$defaultmidi");
635 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
636 id = ly_symbol2scm ("$defaultlayout");
638 parser->lexer_->set_identifier (id, od->self_scm ());
646 $$ = parser->lexer_->eval_scm_token ($1);
651 embedded_scm_bare_arg:
657 | context_modification
660 $$ = $1->self_scm ();
663 | context_def_spec_block
666 $$ = $1->self_scm ();
671 $$ = $1->self_scm ();
676 $$ = $1->self_scm ();
681 /* The generic version may end in music, or not */
689 embedded_scm_bare_arg
695 SCM_FUNCTION function_arglist {
696 $$ = MAKE_SYNTAX ("music-function", @$,
704 $$ = MAKE_SYNTAX ("void-music", @$);
707 | music_embedded music_embedded music_list {
708 $3 = scm_reverse_x ($3, SCM_EOL);
709 if (unsmob_music ($2))
710 $3 = scm_cons ($2, $3);
711 if (unsmob_music ($1))
712 $3 = scm_cons ($1, $3);
713 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
716 parser->error_level_ = 1;
718 | INVALID embedded_lilypond {
719 parser->error_level_ = 1;
724 lilypond_header_body:
726 | lilypond_header_body assignment {
732 HEADER '{' lilypond_header_body '}' {
733 $$ = parser->lexer_->remove_scope ();
742 | LYRICS_STRING { $$ = $1; }
746 assignment_id '=' identifier_init {
747 parser->lexer_->set_identifier ($1, $3);
749 | assignment_id property_path '=' identifier_init {
750 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
751 parser->lexer_->set_identifier (path, $4);
754 TODO: devise standard for protection in parser.
756 The parser stack lives on the C-stack, which means that
757 all objects can be unprotected as soon as they're here.
767 $$ = $1->self_scm ();
771 $$ = $1->self_scm ();
775 $$ = $1->self_scm ();
779 $$ = $1->self_scm ();
782 | context_def_spec_block {
788 | post_event_nofinger {
791 | number_expression {
809 | context_modification {
814 context_def_spec_block:
815 CONTEXT '{' context_def_spec_body '}'
826 context_mod_embedded:
829 if (unsmob_music ($1)) {
830 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
831 $1 = scm_call_2 (proc, parser->self_scm (), $1);
833 if (unsmob_context_mod ($1))
836 parser->parser_error (@1, _ ("not a context mod"));
842 context_def_spec_body:
844 $$ = Context_def::make_scm ();
845 unsmob_context_def ($$)->origin ()->set_spot (@$);
847 | CONTEXT_DEF_IDENTIFIER {
849 unsmob_context_def ($$)->origin ()->set_spot (@$);
851 | context_def_spec_body context_mod {
852 unsmob_context_def ($$)->add_context_mod ($2);
854 | context_def_spec_body context_modification {
855 Context_def *td = unsmob_context_def ($$);
856 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
857 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
858 td->add_context_mod (scm_car (m));
861 | context_def_spec_body context_mod_embedded {
862 Context_def *td = unsmob_context_def ($$);
863 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
864 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
865 td->add_context_mod (scm_car (m));
873 BOOK '{' book_body '}' {
876 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
881 * Use 'handlers' like for toplevel-* stuff?
882 * grok \layout and \midi? */
886 init_papers (parser);
887 $$->origin ()->set_spot (@$);
888 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
889 $$->paper_->unprotect ();
890 push_paper (parser, $$->paper_);
891 $$->header_ = get_header (parser);
892 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
895 $$ = unsmob_book ($1);
897 $$->origin ()->set_spot (@$);
898 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
900 | book_body paper_block {
903 set_paper (parser, $2);
905 | book_body bookpart_block {
907 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
908 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
909 bookpart->unprotect ();
911 | book_body score_block {
913 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
914 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
917 | book_body composite_music {
918 Music *music = unsmob_music ($2);
919 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
920 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
922 | book_body full_markup {
923 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
924 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
926 | book_body full_markup_list {
927 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
928 scm_call_2 (proc, $$->self_scm (), $2);
932 parser->lexer_->add_scope ($1->header_);
934 | book_body embedded_scm { }
937 $$->scores_ = SCM_EOL;
938 $$->bookparts_ = SCM_EOL;
943 BOOKPART '{' bookpart_body '}' {
945 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
952 $$->origin ()->set_spot (@$);
953 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
956 $$ = unsmob_book ($1);
958 $$->origin ()->set_spot (@$);
959 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
961 | bookpart_body paper_block {
965 | bookpart_body score_block {
967 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
968 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
971 | bookpart_body composite_music {
972 Music *music = unsmob_music ($2);
973 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
974 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
976 | bookpart_body full_markup {
977 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
978 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
980 | bookpart_body full_markup_list {
981 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
982 scm_call_2 (proc, $$->self_scm (), $2);
986 if (!ly_is_module ($1->header_))
987 $1->header_ = ly_make_module (false);
988 parser->lexer_->add_scope ($1->header_);
990 | bookpart_body embedded_scm { }
991 | bookpart_body error {
993 $$->scores_ = SCM_EOL;
998 SCORE '{' score_body '}' {
1006 SCM scorify = ly_lily_module_constant ("scorify-music");
1007 SCM score = scm_call_2 (scorify, m, parser->self_scm ());
1009 // pass ownernship to C++ again.
1010 $$ = unsmob_score (score);
1012 $$->origin ()->set_spot (@$);
1014 | SCORE_IDENTIFIER {
1015 $$ = unsmob_score ($1);
1017 $$->origin ()->set_spot (@$);
1021 if (!ly_is_module ($1->get_header ()))
1022 $1->set_header (ly_make_module (false));
1023 parser->lexer_->add_scope ($1->get_header ());
1025 | score_body output_def {
1026 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
1028 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1033 $$->add_output_def ($2);
1037 | score_body error {
1038 $$->error_found_ = true;
1050 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1052 parser->parser_error (@1, _ ("need \\paper for paper block"));
1054 $$ = get_paper (parser);
1061 output_def_body '}' {
1064 parser->lexer_->remove_scope ();
1065 parser->lexer_->pop_state ();
1071 $$ = get_paper (parser);
1072 $$->input_origin_ = @$;
1073 parser->lexer_->add_scope ($$->scope_);
1076 Output_def *p = get_midi (parser);
1078 parser->lexer_->add_scope (p->scope_);
1081 Output_def *p = get_layout (parser);
1083 parser->lexer_->add_scope (p->scope_);
1088 output_def_head_with_mode_switch:
1090 parser->lexer_->push_initial_state ();
1095 // We need this weird nonterminal because both music as well as a
1096 // context definition can start with \context and the difference is
1097 // only apparent after looking at the next token. If it is '{', there
1098 // is still time to escape from notes mode.
1100 music_or_context_def:
1103 parser->lexer_->pop_state ();
1107 parser->lexer_->pop_state ();
1108 } '{' context_def_spec_body '}'
1115 output_def_head_with_mode_switch '{' {
1117 $$->input_origin_.set_spot (@$);
1119 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1122 Output_def *o = unsmob_output_def ($3);
1123 o->input_origin_.set_spot (@$);
1126 parser->lexer_->remove_scope ();
1127 parser->lexer_->add_scope (o->scope_);
1129 | output_def_body assignment {
1134 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1135 parser->lexer_->push_note_state (nn);
1136 } music_or_context_def
1138 if (unsmob_context_def ($3))
1139 assign_context_def ($$, $3);
1142 SCM proc = parser->lexer_->lookup_identifier
1143 ("output-def-music-handler");
1144 scm_call_3 (proc, parser->self_scm (),
1145 $1->self_scm (), $3);
1148 | output_def_body error {
1154 TEMPO steno_duration '=' tempo_range {
1155 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1157 | TEMPO scalar_closed steno_duration '=' tempo_range {
1158 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1161 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1166 The representation of a list is reversed to have efficient append. */
1172 | music_list music_embedded {
1173 if (unsmob_music ($2))
1174 $$ = scm_cons ($2, $1);
1176 | music_list error {
1177 Music *m = MY_MAKE_MUSIC("Music", @$);
1179 m->set_property ("error-found", SCM_BOOL_T);
1180 $$ = scm_cons (m->self_scm (), $1);
1181 m->unprotect (); /* UGH */
1188 $$ = scm_reverse_x ($2, SCM_EOL);
1193 | lyric_element_music
1200 if (unsmob_music ($1)
1201 || scm_is_eq ($1, SCM_UNSPECIFIED))
1205 @$.warning (_ ("Ignoring non-music expression"));
1206 $$ = SCM_UNSPECIFIED;
1214 if (unsmob_pitch ($1)) {
1215 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
1216 n->set_property ("pitch", $1);
1217 n->set_property ("duration",
1218 parser->default_duration_.smobbed_copy ());
1219 $$ = n->unprotect ();
1222 | composite_music %prec COMPOSITE
1227 | composite_music %prec COMPOSITE
1228 | lyric_element_music
1232 REPEAT simple_string unsigned_number music
1234 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1236 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1238 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1243 SEQUENTIAL braced_music_list {
1244 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1246 | braced_music_list {
1247 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1252 SIMULTANEOUS braced_music_list {
1253 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1255 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1256 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1262 | music_property_def
1266 context_modification:
1267 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1269 parser->lexer_->pop_state ();
1272 | WITH CONTEXT_MOD_IDENTIFIER
1276 | CONTEXT_MOD_IDENTIFIER
1280 | WITH embedded_scm_closed
1282 if (unsmob_context_mod ($2))
1285 parser->parser_error (@2, _ ("not a context mod"));
1286 $$ = Context_mod ().smobbed_copy ();
1291 optional_context_mod:
1295 | context_modification
1303 $$ = Context_mod ().smobbed_copy ();
1305 | context_mod_list context_mod {
1306 unsmob_context_mod ($1)->add_context_mod ($2);
1308 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1309 Context_mod *md = unsmob_context_mod ($2);
1311 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1313 | context_mod_list context_mod_embedded {
1314 unsmob_context_mod ($1)->add_context_mods
1315 (unsmob_context_mod ($2)->get_mods ());
1324 /* Music that can be parsed without lookahead */
1327 | complex_music_prefix closed_music
1329 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1331 | music_function_call_closed
1337 | grouped_music_list
1341 simultaneous_music { $$ = $1; }
1342 | sequential_music { $$ = $1; }
1345 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1346 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1347 and this rule returns the reversed list of arguments. */
1349 function_arglist_skip:
1350 function_arglist_common
1351 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1353 $$ = scm_cons ($1, $3);
1354 } %prec FUNCTION_ARGLIST
1355 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1357 $$ = scm_cons ($1, $3);
1358 } %prec FUNCTION_ARGLIST
1359 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1361 $$ = scm_cons ($1, $3);
1362 } %prec FUNCTION_ARGLIST
1366 function_arglist_nonbackup_common:
1367 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1368 $$ = scm_cons ($4, $3);
1370 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1371 $$ = scm_cons ($4, $3);
1373 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1375 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1377 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1379 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1381 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1383 SCM n = scm_difference ($5, SCM_UNDEFINED);
1384 if (scm_is_true (scm_call_1 ($2, n)))
1385 $$ = scm_cons (n, $3);
1387 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1388 t->set_property ("digit", $5);
1389 $$ = t->unprotect ();
1390 if (scm_is_true (scm_call_1 ($2, $$)))
1391 $$ = scm_cons ($$, $3);
1393 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1397 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1399 $$ = check_scheme_arg (parser, @4,
1400 scm_difference ($5, SCM_UNDEFINED),
1403 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1405 $$ = check_scheme_arg (parser, @4,
1406 scm_difference ($5, SCM_UNDEFINED),
1411 function_arglist_closed_nonbackup:
1412 function_arglist_nonbackup_common
1413 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1415 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1417 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1419 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1423 function_arglist_nonbackup:
1424 function_arglist_nonbackup_common
1425 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1427 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1429 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1431 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1435 function_arglist_keep:
1436 function_arglist_common
1437 | function_arglist_backup
1440 function_arglist_closed_keep:
1441 function_arglist_closed_common
1442 | function_arglist_backup
1445 function_arglist_backup:
1446 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1448 if (scm_is_true (scm_call_1 ($2, $4)))
1450 $$ = scm_cons ($4, $3);
1452 $$ = scm_cons (loc_on_music (@3, $1), $3);
1453 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1456 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1458 if (scm_is_true (scm_call_1 ($2, $4)))
1460 $$ = scm_cons ($4, $3);
1462 $$ = scm_cons (loc_on_music (@3, $1), $3);
1463 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1466 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1468 // There is no point interpreting a lyrics string as
1469 // an event, since we don't allow music possibly
1470 // followed by durations or postevent into closed
1471 // music, and we only accept closed music in optional
1472 // arguments at the moment. If this changes, more
1473 // complex schemes might become interesting here as
1474 // well: see how we do this at the mandatory argument
1476 if (scm_is_true (scm_call_1 ($2, $4)))
1477 $$ = scm_cons ($4, $3);
1479 $$ = scm_cons (loc_on_music (@3, $1), $3);
1480 MYBACKUP (LYRICS_STRING, $4, @4);
1483 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1485 if (scm_is_true (scm_call_1 ($2, $4)))
1488 MYREPARSE (@4, $2, UNSIGNED, $4);
1490 $$ = scm_cons (loc_on_music (@3, $1), $3);
1491 MYBACKUP (UNSIGNED, $4, @4);
1494 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1496 if (scm_is_true (scm_call_1 ($2, $4)))
1499 MYREPARSE (@4, $2, REAL, $4);
1501 $$ = scm_cons (loc_on_music (@3, $1), $3);
1502 MYBACKUP (REAL, $4, @4);
1505 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1507 if (scm_is_true (scm_call_1 ($2, $4)))
1509 $$ = scm_cons ($4, $3);
1511 $$ = scm_cons (loc_on_music (@3, $1), $3);
1512 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1515 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1517 if (scm_is_true (scm_call_1 ($2, $4)))
1519 $$ = scm_cons ($4, $3);
1521 $$ = scm_cons (loc_on_music (@3, $1), $3);
1522 MYBACKUP (FRACTION, $4, @4);
1525 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1527 SCM n = scm_difference ($5, SCM_UNDEFINED);
1528 if (scm_is_true (scm_call_1 ($2, n))) {
1530 MYREPARSE (@5, $2, REAL, n);
1532 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1533 t->set_property ("digit", $5);
1534 $$ = t->unprotect ();
1535 if (scm_is_true (scm_call_1 ($2, $$)))
1536 $$ = scm_cons ($$, $3);
1538 $$ = scm_cons (loc_on_music (@3, $1), $3);
1539 MYBACKUP (UNSIGNED, $5, @5);
1540 parser->lexer_->push_extra_token ('-');
1545 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1547 SCM n = scm_difference ($5, SCM_UNDEFINED);
1548 if (scm_is_true (scm_call_1 ($2, n))) {
1549 MYREPARSE (@5, $2, REAL, n);
1552 MYBACKUP (REAL, n, @5);
1555 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1557 SCM n = scm_difference ($5, SCM_UNDEFINED);
1558 if (scm_is_true (scm_call_1 ($2, n))) {
1559 $$ = scm_cons (n, $3);
1561 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1564 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1566 $$ = scm_cons ($4, $3);
1568 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1570 $$ = scm_cons ($4, $3);
1572 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1574 $$ = scm_cons ($1, $3);
1575 MYBACKUP(0, SCM_UNDEFINED, @3);
1577 | function_arglist_backup REPARSE embedded_scm_arg_closed
1579 $$ = check_scheme_arg (parser, @3,
1582 | function_arglist_backup REPARSE bare_number
1584 $$ = check_scheme_arg (parser, @3,
1590 function_arglist_common
1591 | function_arglist_nonbackup
1594 function_arglist_common:
1595 function_arglist_bare
1596 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1598 $$ = check_scheme_arg (parser, @3,
1601 | EXPECT_SCM function_arglist_closed_optional bare_number
1603 $$ = check_scheme_arg (parser, @3,
1606 | EXPECT_SCM function_arglist_closed_optional FRACTION
1608 $$ = check_scheme_arg (parser, @3,
1611 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1613 $$ = check_scheme_arg (parser, @3,
1616 | function_arglist_common_minus
1617 | function_arglist_common_lyric
1620 function_arglist_common_lyric:
1621 EXPECT_SCM function_arglist_optional lyric_element
1623 // We check how the predicate thinks about a lyrics
1624 // event or about a markup. If it accepts neither, we
1625 // backup the original token. Otherwise we commit to
1626 // taking the token. Depending on what the predicate
1627 // is willing to accept, we interpret as a string, as
1628 // a lyric event, or ambiguously (meaning that if
1629 // something looking like a duration or post event
1630 // follows, we take the event, otherwise the string).
1631 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1632 parser->default_duration_.smobbed_copy ());
1633 if (scm_is_true (scm_call_1 ($1, $3)))
1634 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1637 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1639 $$ = scm_cons ($3, $2);
1641 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1644 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1646 // This is going to flag a syntax error, we
1647 // know the predicate to be false.
1648 check_scheme_arg (parser, @3,
1652 | function_arglist_common_lyric REPARSE lyric_element_arg
1654 // This should never be false
1655 $$ = check_scheme_arg (parser, @3,
1660 function_arglist_common_minus:
1661 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1663 SCM n = scm_difference ($4, SCM_UNDEFINED);
1664 if (scm_is_true (scm_call_1 ($1, n))) {
1666 MYREPARSE (@4, $1, REAL, n);
1668 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1669 t->set_property ("digit", $4);
1670 $$ = t->unprotect ();
1671 if (scm_is_true (scm_call_1 ($1, $$)))
1672 $$ = scm_cons ($$, $2);
1674 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1678 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1681 SCM n = scm_difference ($4, SCM_UNDEFINED);
1682 MYREPARSE (@4, $1, REAL, n);
1684 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1686 SCM n = scm_difference ($4, SCM_UNDEFINED);
1687 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1689 | function_arglist_common_minus REPARSE bare_number
1691 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1695 function_arglist_closed:
1696 function_arglist_closed_common
1697 | function_arglist_closed_nonbackup
1700 function_arglist_closed_common:
1701 function_arglist_bare
1702 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1704 $$ = check_scheme_arg (parser, @3,
1707 | EXPECT_SCM function_arglist_closed_optional bare_number
1709 $$ = check_scheme_arg (parser, @3,
1712 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1714 SCM n = scm_difference ($4, SCM_UNDEFINED);
1715 if (scm_is_true (scm_call_1 ($1, n))) {
1716 $$ = scm_cons (n, $2);
1718 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1719 t->set_property ("digit", $4);
1720 $$ = t->unprotect ();
1721 if (scm_is_true (scm_call_1 ($1, $$)))
1722 $$ = scm_cons ($$, $2);
1724 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1728 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1730 $$ = check_scheme_arg (parser, @3,
1731 scm_difference ($4, SCM_UNDEFINED),
1734 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1736 $$ = check_scheme_arg (parser, @3,
1737 scm_difference ($4, SCM_UNDEFINED),
1740 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1742 $$ = check_scheme_arg (parser, @3,
1745 | EXPECT_SCM function_arglist_closed_optional FRACTION
1747 $$ = check_scheme_arg (parser, @3,
1750 | EXPECT_SCM function_arglist_optional lyric_element
1752 $$ = check_scheme_arg (parser, @3,
1757 function_arglist_optional:
1758 function_arglist_keep %prec FUNCTION_ARGLIST
1759 | function_arglist_backup BACKUP
1760 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1762 $$ = scm_cons ($1, $3);
1764 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1766 $$ = scm_cons ($1, $3);
1770 function_arglist_closed_optional:
1771 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1772 | function_arglist_backup BACKUP
1773 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1775 $$ = scm_cons ($1, $3);
1777 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1779 $$ = scm_cons ($1, $3);
1783 embedded_scm_closed:
1785 | scm_function_call_closed
1788 embedded_scm_arg_closed:
1789 embedded_scm_bare_arg
1790 | scm_function_call_closed
1794 scm_function_call_closed:
1795 SCM_FUNCTION function_arglist_closed {
1796 $$ = MAKE_SYNTAX ("music-function", @$,
1798 } %prec FUNCTION_ARGLIST
1801 function_arglist_bare:
1802 EXPECT_NO_MORE_ARGS {
1805 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1806 $$ = scm_cons ($3, $2);
1808 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1809 $$ = scm_cons ($3, $2);
1811 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1812 $$ = scm_cons ($1, $3);
1814 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1815 $$ = scm_cons ($1, $3);
1817 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1818 $$ = scm_cons ($1, $3);
1822 music_function_call:
1823 MUSIC_FUNCTION function_arglist {
1824 $$ = MAKE_SYNTAX ("music-function", @$,
1831 /**/ { $$ = SCM_EOL; }
1832 | '=' simple_string {
1839 | repeated_music { $$ = $1; }
1840 | re_rhythmed_music { $$ = $1; }
1841 | complex_music_prefix music
1843 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1847 complex_music_prefix:
1848 CONTEXT simple_string optional_id optional_context_mod {
1849 Context_mod *ctxmod = unsmob_context_mod ($4);
1852 mods = ctxmod->get_mods ();
1853 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1855 | NEWCONTEXT simple_string optional_id optional_context_mod {
1856 Context_mod *ctxmod = unsmob_context_mod ($4);
1859 mods = ctxmod->get_mods ();
1860 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1865 mode_changing_head grouped_music_list {
1866 if ($1 == ly_symbol2scm ("chords"))
1868 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1874 parser->lexer_->pop_state ();
1876 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1877 Context_mod *ctxmod = unsmob_context_mod ($2);
1880 mods = ctxmod->get_mods ();
1881 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1882 if ($1 == ly_symbol2scm ("ChordNames"))
1884 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1886 parser->lexer_->pop_state ();
1892 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1893 parser->lexer_->push_note_state (nn);
1895 $$ = ly_symbol2scm ("notes");
1899 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1900 parser->lexer_->push_note_state (nn);
1902 $$ = ly_symbol2scm ("drums");
1905 parser->lexer_->push_figuredbass_state ();
1907 $$ = ly_symbol2scm ("figures");
1910 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1911 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1912 nn = parser->lexer_->lookup_identifier ("pitchnames");
1913 parser->lexer_->push_chord_state (nn);
1914 $$ = ly_symbol2scm ("chords");
1918 { parser->lexer_->push_lyric_state ();
1919 $$ = ly_symbol2scm ("lyrics");
1923 mode_changing_head_with_context:
1925 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1926 parser->lexer_->push_note_state (nn);
1928 $$ = ly_symbol2scm ("DrumStaff");
1931 parser->lexer_->push_figuredbass_state ();
1933 $$ = ly_symbol2scm ("FiguredBass");
1936 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1937 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1938 nn = parser->lexer_->lookup_identifier ("pitchnames");
1939 parser->lexer_->push_chord_state (nn);
1940 $$ = ly_symbol2scm ("ChordNames");
1943 { parser->lexer_->push_lyric_state ();
1944 $$ = ly_symbol2scm ("Lyrics");
1949 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1952 /* Can also use music at the expensive of two S/Rs similar to
1953 \repeat \alternative */
1954 parser->lexer_->pop_state ();
1956 $$ = scm_cons ($3, SCM_EOL);
1958 | new_lyrics ADDLYRICS {
1959 parser->lexer_->push_lyric_state ();
1961 parser->lexer_->pop_state ();
1962 $$ = scm_cons ($4, $1);
1967 composite_music new_lyrics {
1968 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1970 | LYRICSTO simple_string {
1971 parser->lexer_->push_lyric_state ();
1973 parser->lexer_->pop_state ();
1974 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1979 CHANGE STRING '=' STRING {
1980 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1985 property_path_revved:
1986 embedded_scm_closed {
1987 $$ = scm_cons ($1, SCM_EOL);
1989 | property_path_revved embedded_scm_closed {
1990 $$ = scm_cons ($2, $1);
1995 property_path_revved {
1996 $$ = scm_reverse_x ($1, SCM_EOL);
2002 $$ = scm_list_3 (ly_symbol2scm ("assign"),
2003 scm_string_to_symbol ($1), $3);
2005 | UNSET simple_string {
2006 $$ = scm_list_2 (ly_symbol2scm ("unset"),
2007 scm_string_to_symbol ($2));
2009 | OVERRIDE simple_string property_path '=' scalar {
2010 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
2011 scm_string_to_symbol ($2), $5),
2014 | REVERT simple_string embedded_scm {
2015 $$ = scm_list_3 (ly_symbol2scm ("pop"),
2016 scm_string_to_symbol ($2), $3);
2021 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2022 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2024 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2025 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2026 | DENIES { $$ = ly_symbol2scm ("denies"); }
2028 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2029 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2030 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2031 | NAME { $$ = ly_symbol2scm ("context-name"); }
2035 property_operation { $$ = $1; }
2036 | context_def_mod STRING {
2037 $$ = scm_list_2 ($1, $2);
2039 | context_def_mod embedded_scm
2041 if (!scm_is_string ($2)
2042 && ly_symbol2scm ("consists") != $1
2043 && ly_symbol2scm ("remove") != $1)
2046 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2050 $$ = scm_list_2 ($1, $2);
2057 if (!is_regular_identifier ($1))
2059 @$.error (_("Grob name should be alphanumeric"));
2062 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
2063 scm_string_to_symbol ($1));
2065 | simple_string '.' simple_string {
2066 $$ = scm_list_2 (scm_string_to_symbol ($1),
2067 scm_string_to_symbol ($3));
2071 simple_music_property_def:
2072 OVERRIDE context_prop_spec property_path '=' scalar {
2073 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
2074 ly_symbol2scm ("OverrideProperty"),
2079 | REVERT context_prop_spec embedded_scm {
2080 $$ = scm_list_4 (scm_car ($2),
2081 ly_symbol2scm ("RevertProperty"),
2085 | SET context_prop_spec '=' scalar {
2086 $$ = scm_list_4 (scm_car ($2),
2087 ly_symbol2scm ("PropertySet"),
2091 | UNSET context_prop_spec {
2092 $$ = scm_list_3 (scm_car ($2),
2093 ly_symbol2scm ("PropertyUnset"),
2099 simple_music_property_def {
2100 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2108 | STRING_IDENTIFIER {
2111 | string '+' string {
2112 $$ = scm_string_append (scm_list_2 ($1, $3));
2116 simple_string: STRING {
2122 | STRING_IDENTIFIER {
2135 embedded_scm_arg_closed
2143 simple_element post_events {
2144 // Let the rhythmic music iterator sort this mess out.
2145 if (scm_is_pair ($2)) {
2146 if (unsmob_pitch ($1)) {
2147 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
2148 n->set_property ("pitch", $1);
2149 n->set_property ("duration",
2150 parser->default_duration_.smobbed_copy ());
2151 $$ = n->unprotect ();
2153 unsmob_music ($$)->set_property ("articulations",
2154 scm_reverse_x ($2, SCM_EOL));
2157 | simple_chord_elements post_events {
2158 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2161 /* why is this giving wrong start location? -ns
2163 i.set_location (@1, @2);
2164 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2166 | CHORD_REPETITION optional_notemode_duration post_events {
2168 i.set_location (@1, @3);
2169 $$ = MAKE_SYNTAX ("repetition-chord", i,
2170 $2, scm_reverse_x ($3, SCM_EOL));
2172 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2174 i.set_location (@1, @3);
2175 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2176 scm_reverse_x ($3, SCM_EOL));
2179 | note_chord_element
2184 chord_body optional_notemode_duration post_events
2186 Music *m = unsmob_music ($1);
2187 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2188 SCM es = m->get_property ("elements");
2189 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2191 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2192 unsmob_music (scm_car (s))->set_property ("duration", dur);
2193 es = ly_append2 (es, postevs);
2195 m-> set_property ("elements", es);
2197 $$ = m->self_scm ();
2202 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2204 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2208 chord_body_elements:
2209 /* empty */ { $$ = SCM_EOL; }
2210 | chord_body_elements chord_body_element {
2211 if (!SCM_UNBNDP ($2))
2212 $$ = scm_cons ($2, $1);
2217 pitch exclamations questions octave_check post_events
2224 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2225 n->set_property ("pitch", $1);
2227 n->set_property ("cautionary", SCM_BOOL_T);
2228 if (ex % 2 || q % 2)
2229 n->set_property ("force-accidental", SCM_BOOL_T);
2231 if (scm_is_pair (post)) {
2232 SCM arts = scm_reverse_x (post, SCM_EOL);
2233 n->set_property ("articulations", arts);
2235 if (scm_is_number (check))
2237 int q = scm_to_int (check);
2238 n->set_property ("absolute-octave", scm_from_int (q-1));
2241 $$ = n->unprotect ();
2243 | DRUM_PITCH post_events {
2244 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2245 n->set_property ("drum-type", $1);
2247 if (scm_is_pair ($2)) {
2248 SCM arts = scm_reverse_x ($2, SCM_EOL);
2249 n->set_property ("articulations", arts);
2251 $$ = n->unprotect ();
2253 | music_function_chord_body
2255 Music *m = unsmob_music ($1);
2257 while (m && m->is_mus_type ("music-wrapper-music")) {
2258 $$ = m->get_property ("element");
2259 m = unsmob_music ($$);
2262 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2263 parser->parser_error (@$, _ ("not a rhythmic event"));
2269 music_function_chord_body:
2274 // Event functions may only take closed arglists, otherwise it would
2275 // not be clear whether a following postevent should be associated
2276 // with the last argument of the event function or with the expression
2277 // for which the function call acts itself as event.
2279 music_function_call_closed:
2280 MUSIC_FUNCTION function_arglist_closed {
2281 $$ = MAKE_SYNTAX ("music-function", @$,
2286 event_function_event:
2287 EVENT_FUNCTION function_arglist_closed {
2288 $$ = MAKE_SYNTAX ("music-function", @$,
2298 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2299 m->set_property ("span-direction", scm_from_int (START));
2300 $$ = m->unprotect();
2303 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2304 m->set_property ("span-direction", scm_from_int (STOP));
2305 $$ = m->unprotect ();
2308 $$ = MAKE_SYNTAX ("voice-separator", @$);
2311 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2313 Music *m = unsmob_music (pipe);
2318 $$ = m->unprotect ();
2321 $$ = MAKE_SYNTAX ("bar-check", @$);
2328 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2340 | post_events post_event {
2341 unsmob_music ($2)->set_spot (@2);
2342 $$ = scm_cons ($2, $$);
2346 post_event_nofinger:
2347 direction_less_event {
2350 | script_dir music_function_call_closed {
2354 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2358 if (!parser->lexer_->is_lyric_state ())
2359 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2360 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2363 if (!parser->lexer_->is_lyric_state ())
2364 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2365 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2367 | script_dir direction_reqd_event {
2370 Music *m = unsmob_music ($2);
2371 m->set_property ("direction", scm_from_int ($1));
2375 | script_dir direction_less_event {
2378 Music *m = unsmob_music ($2);
2379 m->set_property ("direction", scm_from_int ($1));
2386 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2391 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2402 string_number_event:
2404 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2405 s->set_property ("string-number", scm_from_int ($1));
2406 $$ = s->unprotect ();
2410 direction_less_char:
2412 $$ = ly_symbol2scm ("bracketOpenSymbol");
2415 $$ = ly_symbol2scm ("bracketCloseSymbol");
2418 $$ = ly_symbol2scm ("tildeSymbol");
2421 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2424 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2427 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2430 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2433 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2436 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2439 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2443 direction_less_event:
2444 direction_less_char {
2445 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2447 if (unsmob_music (predefd))
2449 m = unsmob_music (predefd)->clone ();
2454 m = MY_MAKE_MUSIC ("Music", @$);
2456 $$ = m->unprotect ();
2458 | string_number_event
2459 | EVENT_IDENTIFIER {
2463 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2464 a->set_property ("tremolo-type", scm_from_int ($1));
2465 $$ = a->unprotect ();
2467 | event_function_event
2470 direction_reqd_event:
2474 | script_abbreviation {
2475 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2476 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2477 if (scm_is_string (s))
2478 a->set_property ("articulation-type", s);
2479 else parser->parser_error (@1, _ ("expecting string as script definition"));
2480 $$ = a->unprotect ();
2485 /**/ { $$ = SCM_EOL; }
2486 | '=' { $$ = scm_from_int (0); }
2487 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2488 | '=' sup_quotes { $$ = scm_from_int ($2); }
2513 | NOTENAME_PITCH sup_quotes {
2514 Pitch p = *unsmob_pitch ($1);
2515 p = p.transposed (Pitch ($2,0,0));
2516 $$ = p.smobbed_copy ();
2518 | NOTENAME_PITCH sub_quotes {
2519 Pitch p =* unsmob_pitch ($1);
2520 p = p.transposed (Pitch (-$2,0,0));
2521 $$ = p.smobbed_copy ();
2533 | TONICNAME_PITCH sup_quotes {
2534 Pitch p = *unsmob_pitch ($1);
2535 p = p.transposed (Pitch ($2,0,0));
2536 $$ = p.smobbed_copy ();
2538 | TONICNAME_PITCH sub_quotes {
2539 Pitch p = *unsmob_pitch ($1);
2541 p = p.transposed (Pitch (-$2,0,0));
2542 $$ = p.smobbed_copy ();
2553 pitch_also_in_chords:
2560 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2561 t->set_property ("text", $1);
2562 $$ = t->unprotect ();
2565 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2566 t->set_property ("text",
2567 make_simple_markup ($1));
2568 $$ = t->unprotect ();
2574 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2575 t->set_property ("digit", $1);
2576 $$ = t->unprotect ();
2580 script_abbreviation:
2582 $$ = scm_from_locale_string ("Hat");
2585 $$ = scm_from_locale_string ("Plus");
2588 $$ = scm_from_locale_string ("Dash");
2591 $$ = scm_from_locale_string ("Bar");
2594 $$ = scm_from_locale_string ("Larger");
2597 $$ = scm_from_locale_string ("Dot");
2600 $$ = scm_from_locale_string ("Underscore");
2607 | '-' { $$ = CENTER; }
2611 multiplied_duration {
2616 maybe_notemode_duration:
2620 | multiplied_duration {
2622 parser->default_duration_ = *unsmob_duration ($$);
2627 optional_notemode_duration:
2628 maybe_notemode_duration
2630 if (SCM_UNBNDP ($$))
2631 $$ = parser->default_duration_.smobbed_copy ();
2636 bare_unsigned dots {
2638 if (!is_duration ($1))
2639 parser->parser_error (@1, _f ("not a duration: %d", $1));
2643 $$ = Duration (len, $2).smobbed_copy ();
2645 | DURATION_IDENTIFIER dots {
2646 Duration *d = unsmob_duration ($1);
2647 Duration k (d->duration_log (), d->dot_count () + $2);
2648 k = k.compressed (d->factor ());
2654 multiplied_duration:
2658 | multiplied_duration '*' bare_unsigned {
2659 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2661 | multiplied_duration '*' FRACTION {
2662 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2664 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2681 | ':' bare_unsigned {
2682 if (!is_duration ($2))
2683 parser->parser_error (@2, _f ("not a duration: %d", $2));
2689 UNSIGNED { $$ = $1; }
2690 | STRING { $$ = $1; }
2691 | full_markup { $$ = $1; }
2694 figured_bass_alteration:
2695 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2696 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2697 | '!' { $$ = scm_from_int (0); }
2702 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2703 $$ = bfr->unprotect ();
2706 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2707 $$ = bfr->self_scm ();
2709 if (scm_is_number ($1))
2710 bfr->set_property ("figure", $1);
2711 else if (Text_interface::is_markup ($1))
2712 bfr->set_property ("text", $1);
2718 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2720 | bass_figure figured_bass_alteration {
2721 Music *m = unsmob_music ($1);
2722 if (scm_to_double ($2)) {
2723 SCM salter = m->get_property ("alteration");
2724 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2725 m->set_property ("alteration",
2726 scm_sum (alter, $2));
2728 m->set_property ("alteration", scm_from_int (0));
2731 | bass_figure figured_bass_modification {
2732 Music *m = unsmob_music ($1);
2733 if ($2 == ly_symbol2scm ("plus"))
2735 m->set_property ("augmented", SCM_BOOL_T);
2737 else if ($2 == ly_symbol2scm ("slash"))
2739 m->set_property ("diminished", SCM_BOOL_T);
2741 else if ($2 == ly_symbol2scm ("exclamation"))
2743 m->set_property ("no-continuation", SCM_BOOL_T);
2745 else if ($2 == ly_symbol2scm ("backslash"))
2747 m->set_property ("augmented-slash", SCM_BOOL_T);
2753 figured_bass_modification:
2755 $$ = ly_symbol2scm ("plus");
2758 $$ = ly_symbol2scm ("exclamation");
2761 $$ = ly_symbol2scm ("slash");
2764 $$ = ly_symbol2scm ("backslash");
2774 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2782 | figure_list br_bass_figure {
2783 $$ = scm_cons ($2, $1);
2788 FIGURE_OPEN figure_list FIGURE_CLOSE {
2789 $$ = scm_reverse_x ($2, SCM_EOL);
2800 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2801 if (!parser->lexer_->is_note_state ())
2802 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2803 if ($2 || $3 || scm_is_number ($4) || !SCM_UNBNDP ($5) || $6)
2807 n = MY_MAKE_MUSIC ("RestEvent", @$);
2809 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2811 n->set_property ("pitch", $1);
2812 if (SCM_UNBNDP ($5))
2813 n->set_property ("duration",
2814 parser->default_duration_.smobbed_copy ());
2816 n->set_property ("duration", $5);
2818 if (scm_is_number ($4))
2820 int q = scm_to_int ($4);
2821 n->set_property ("absolute-octave", scm_from_int (q-1));
2825 n->set_property ("cautionary", SCM_BOOL_T);
2826 if ($2 % 2 || $3 % 2)
2827 n->set_property ("force-accidental", SCM_BOOL_T);
2829 $$ = n->unprotect ();
2832 | DRUM_PITCH optional_notemode_duration {
2833 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2834 n->set_property ("duration", $2);
2835 n->set_property ("drum-type", $1);
2837 $$ = n->unprotect ();
2839 | RESTNAME optional_notemode_duration {
2841 if (ly_scm2string ($1) == "s") {
2843 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2846 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2849 ev->set_property ("duration", $2);
2850 $$ = ev->unprotect ();
2854 simple_chord_elements:
2856 if (!parser->lexer_->is_chord_state ())
2857 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2860 | figure_spec optional_notemode_duration {
2861 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2863 unsmob_music (scm_car (s))->set_property ("duration", $2);
2880 | lyric_element multiplied_duration post_events {
2881 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2882 if (scm_is_pair ($3))
2883 unsmob_music ($$)->set_property
2884 ("articulations", scm_reverse_x ($3, SCM_EOL));
2886 | lyric_element post_event post_events {
2887 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2888 parser->default_duration_.smobbed_copy ());
2889 unsmob_music ($$)->set_property
2890 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2892 | LYRIC_ELEMENT optional_notemode_duration post_events {
2893 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2894 if (scm_is_pair ($3))
2895 unsmob_music ($$)->set_property
2896 ("articulations", scm_reverse_x ($3, SCM_EOL));
2901 lyric_element_music:
2902 lyric_element optional_notemode_duration post_events {
2903 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2904 if (scm_is_pair ($3))
2905 unsmob_music ($$)->set_property
2906 ("articulations", scm_reverse_x ($3, SCM_EOL));
2911 steno_tonic_pitch optional_notemode_duration {
2912 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2914 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2915 SCM its = scm_reverse_x ($4, SCM_EOL);
2916 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2924 | chord_items chord_item {
2925 $$ = scm_cons ($2, $$);
2931 $$ = ly_symbol2scm ("chord-colon");
2934 $$ = ly_symbol2scm ("chord-caret");
2936 | CHORD_SLASH steno_tonic_pitch {
2937 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2939 | CHORD_BASS steno_tonic_pitch {
2940 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2949 $$ = scm_reverse_x ($1, SCM_EOL);
2957 step_number { $$ = scm_cons ($1, SCM_EOL); }
2958 | step_numbers '.' step_number {
2959 $$ = scm_cons ($3, $$);
2965 $$ = make_chord_step ($1, 0);
2967 | bare_unsigned '+' {
2968 $$ = make_chord_step ($1, SHARP_ALTERATION);
2970 | bare_unsigned CHORD_MINUS {
2971 $$ = make_chord_step ($1, FLAT_ALTERATION);
2977 $$ = scm_from_int ($1);
2979 | bare_unsigned '~' bare_unsigned {
2980 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2987 TODO: should deprecate in favor of Scheme?
2991 number_expression '+' number_term {
2992 $$ = scm_sum ($1, $3);
2994 | number_expression '-' number_term {
2995 $$ = scm_difference ($1, $3);
3004 | number_factor '*' number_factor {
3005 $$ = scm_product ($1, $3);
3007 | number_factor '/' number_factor {
3008 $$ = scm_divide ($1, $3);
3013 '-' number_factor { /* %prec UNARY_MINUS */
3014 $$ = scm_difference ($2, SCM_UNDEFINED);
3022 | UNSIGNED NUMBER_IDENTIFIER {
3023 $$ = scm_product ($1, $2);
3025 | REAL NUMBER_IDENTIFIER {
3026 $$ = scm_product ($1, $2);
3038 $$ = scm_to_int ($1);
3049 | exclamations '!' { $$ ++; }
3054 | questions '?' { $$ ++; }
3058 This should be done more dynamically if possible.
3062 LYRIC_MARKUP_IDENTIFIER {
3066 { parser->lexer_->push_markup_state (); }
3069 parser->lexer_->pop_state ();
3074 MARKUPLIST_IDENTIFIER {
3078 { parser->lexer_->push_markup_state (); }
3081 parser->lexer_->pop_state ();
3090 { parser->lexer_->push_markup_state (); }
3093 parser->lexer_->pop_state ();
3099 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3101 | markup_head_1_list simple_markup {
3102 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3112 if (Text_interface::is_markup ($1))
3113 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3114 else if (Text_interface::is_markup_list ($1))
3115 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3117 parser->parser_error (@1, _ ("not a markup"));
3118 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3125 MARKUPLIST_IDENTIFIER {
3128 | markup_composed_list {
3131 | markup_braced_list {
3134 | markup_command_list {
3135 $$ = scm_list_1 ($1);
3137 | markup_scm MARKUPLIST_IDENTIFIER
3143 markup_composed_list:
3144 markup_head_1_list markup_braced_list {
3145 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3151 '{' markup_braced_list_body '}' {
3152 $$ = scm_reverse_x ($2, SCM_EOL);
3156 markup_braced_list_body:
3157 /* empty */ { $$ = SCM_EOL; }
3158 | markup_braced_list_body markup {
3159 $$ = scm_cons ($2, $1);
3161 | markup_braced_list_body markup_list {
3162 $$ = scm_reverse_x ($2, $1);
3166 markup_command_list:
3167 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3168 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3172 markup_command_basic_arguments:
3173 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3174 $$ = scm_cons ($3, $2);
3176 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3177 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3179 | EXPECT_NO_MORE_ARGS {
3184 markup_command_list_arguments:
3185 markup_command_basic_arguments { $$ = $1; }
3186 | EXPECT_MARKUP markup_command_list_arguments markup {
3187 $$ = scm_cons ($3, $2);
3192 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3193 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3198 markup_head_1_item {
3199 $$ = scm_list_1 ($1);
3201 | markup_head_1_list markup_head_1_item {
3202 $$ = scm_cons ($2, $1);
3208 $$ = make_simple_markup ($1);
3210 | MARKUP_IDENTIFIER {
3213 | LYRIC_MARKUP_IDENTIFIER {
3216 | STRING_IDENTIFIER {
3220 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3221 parser->lexer_->push_note_state (nn);
3222 } '{' score_body '}' {
3224 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3226 parser->lexer_->pop_state ();
3228 | MARKUP_FUNCTION markup_command_basic_arguments {
3229 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3231 | markup_scm MARKUP_IDENTIFIER
3238 markup_head_1_list simple_markup {
3239 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3240 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3250 Lily_parser::set_yydebug (bool x)
3256 Lily_parser::do_yyparse ()
3267 It is a little strange to have this function in this file, but
3268 otherwise, we have to import music classes into the lexer.
3272 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3274 if (scm_is_string (sid)) {
3276 return STRING_IDENTIFIER;
3277 } else if (unsmob_book (sid)) {
3278 Book *book = unsmob_book (sid)->clone ();
3279 *destination = book->self_scm ();
3282 return BOOK_IDENTIFIER;
3283 } else if (scm_is_number (sid)) {
3285 return NUMBER_IDENTIFIER;
3286 } else if (unsmob_context_def (sid)) {
3287 Context_def *def= unsmob_context_def (sid)->clone ();
3289 *destination = def->self_scm ();
3292 return CONTEXT_DEF_IDENTIFIER;
3293 } else if (unsmob_context_mod (sid)) {
3294 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3296 return CONTEXT_MOD_IDENTIFIER;
3297 } else if (unsmob_score (sid)) {
3298 Score *score = new Score (*unsmob_score (sid));
3299 *destination = score->self_scm ();
3301 score->unprotect ();
3302 return SCORE_IDENTIFIER;
3303 } else if (Music *mus = unsmob_music (sid)) {
3304 mus = mus->clone ();
3305 *destination = mus->self_scm ();
3306 unsmob_music (*destination)->
3307 set_property ("origin", make_input (last_input_));
3309 bool is_event = mus->is_mus_type ("post-event");
3311 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3312 } else if (unsmob_pitch (sid)) {
3313 *destination = unsmob_pitch (sid)->smobbed_copy ();
3314 return PITCH_IDENTIFIER;
3315 } else if (unsmob_duration (sid)) {
3316 *destination = unsmob_duration (sid)->smobbed_copy ();
3317 return DURATION_IDENTIFIER;
3318 } else if (unsmob_output_def (sid)) {
3319 Output_def *p = unsmob_output_def (sid);
3322 *destination = p->self_scm ();
3324 return OUTPUT_DEF_IDENTIFIER;
3325 } else if (Text_interface::is_markup (sid)) {
3327 if (is_lyric_state ())
3328 return LYRIC_MARKUP_IDENTIFIER;
3329 return MARKUP_IDENTIFIER;
3330 } else if (Text_interface::is_markup_list (sid)) {
3332 return MARKUPLIST_IDENTIFIER;
3339 get_next_unique_context_id ()
3341 return scm_from_locale_string ("$uniqueContextId");
3346 get_next_unique_lyrics_context_id ()
3348 static int new_context_count;
3350 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3351 return scm_from_locale_string (s);
3354 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3355 SCM arg, SCM args, SCM pred)
3357 args = scm_cons (arg, args);
3358 if (scm_is_true (scm_call_1 (pred, arg)))
3360 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3361 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3362 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3366 SCM loc_on_music (Input loc, SCM arg)
3368 if (Music *m = unsmob_music (arg))
3372 return m->unprotect ();
3378 is_regular_identifier (SCM id)
3380 string str = ly_scm2string (id);
3381 char const *s = str.c_str ();
3390 v = v && isalnum (*s);
3397 make_music_with_input (SCM name, Input where)
3399 Music *m = make_music_by_name (name);
3400 m->set_spot (where);
3405 make_simple_markup (SCM a)
3413 return t && t == 1 << intlog2 (t);
3417 set_music_properties (Music *p, SCM a)
3419 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3420 p->set_property (scm_caar (k), scm_cdar (k));
3425 make_chord_step (int step, Rational alter)
3428 alter += FLAT_ALTERATION;
3432 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3433 return m.smobbed_copy ();
3438 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3440 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3441 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3442 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3444 unsmob_music (scm_car (s))->set_spot (loc);
3450 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3452 Lily_lexer *lex = parser->lexer_;
3456 lex->prepare_for_next_token ();
3457 return lex->yylex ();