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 ACCEPTS "\\accepts"
244 %token ADDLYRICS "\\addlyrics"
245 %token ALIAS "\\alias"
246 %token ALTERNATIVE "\\alternative"
248 %token BOOKPART "\\bookpart"
249 %token CHANGE "\\change"
250 %token CHORDMODE "\\chordmode"
251 %token CHORDS "\\chords"
252 %token CONSISTS "\\consists"
253 %token CONTEXT "\\context"
254 %token DEFAULT "\\default"
255 %token DEFAULTCHILD "\\defaultchild"
256 %token DENIES "\\denies"
257 %token DESCRIPTION "\\description"
258 %token DRUMMODE "\\drummode"
259 %token DRUMS "\\drums"
260 %token FIGUREMODE "\\figuremode"
261 %token FIGURES "\\figures"
262 %token HEADER "\\header"
263 %token INVALID "\\version-error"
264 %token LAYOUT "\\layout"
265 %token LYRICMODE "\\lyricmode"
266 %token LYRICS "\\lyrics"
267 %token LYRICSTO "\\lyricsto"
268 %token MARKUP "\\markup"
269 %token MARKUPLIST "\\markuplist"
272 %token NOTEMODE "\\notemode"
273 %token OVERRIDE "\\override"
274 %token PAPER "\\paper"
275 %token REMOVE "\\remove"
276 %token REPEAT "\\repeat"
278 %token REVERT "\\revert"
279 %token SCORE "\\score"
280 %token SEQUENTIAL "\\sequential"
282 %token SIMULTANEOUS "\\simultaneous"
283 %token TEMPO "\\tempo"
285 %token UNSET "\\unset"
288 /* Keyword token exceptions. */
289 %token NEWCONTEXT "\\new"
292 /* Other string tokens. */
294 %token CHORD_BASS "/+"
295 %token CHORD_CARET "^"
296 %token CHORD_COLON ":"
297 %token CHORD_MINUS "-"
298 %token CHORD_SLASH "/"
299 %token ANGLE_OPEN "<"
300 %token ANGLE_CLOSE ">"
301 %token DOUBLE_ANGLE_OPEN "<<"
302 %token DOUBLE_ANGLE_CLOSE ">>"
303 %token E_BACKSLASH "\\"
304 %token E_ANGLE_CLOSE "\\>"
305 %token E_CHAR "\\C[haracter]"
307 %token E_EXCLAMATION "\\!"
308 %token E_BRACKET_OPEN "\\["
310 %token E_BRACKET_CLOSE "\\]"
311 %token E_ANGLE_OPEN "\\<"
317 If we give names, Bison complains.
319 %token FIGURE_CLOSE /* "\\>" */
320 %token FIGURE_OPEN /* "\\<" */
321 %token FIGURE_SPACE "_"
324 %token CHORDMODIFIERS
326 %token MULTI_MEASURE_REST
329 %token <i> E_UNSIGNED
330 %token <scm> UNSIGNED
332 /* Artificial tokens, for more generic function syntax */
333 %token <i> EXPECT_MARKUP "markup?"
334 %token <i> EXPECT_PITCH "ly:pitch?"
335 %token <i> EXPECT_DURATION "ly:duration?"
336 %token <scm> EXPECT_SCM "scheme?"
337 %token <scm> BACKUP "(backed-up?)"
338 %token <scm> REPARSE "(reparsed?)"
339 %token <i> EXPECT_MARKUP_LIST "markup-list?"
340 %token <scm> EXPECT_OPTIONAL "optional?"
341 /* After the last argument. */
342 %token <i> EXPECT_NO_MORE_ARGS;
344 /* An artificial token for parsing embedded Lilypond */
345 %token <i> EMBEDDED_LILY "#{"
347 %token <scm> BOOK_IDENTIFIER
348 %token <scm> CHORDMODIFIER_PITCH
349 %token <scm> CHORD_MODIFIER
350 %token <scm> CHORD_REPETITION
351 %token <scm> CONTEXT_DEF_IDENTIFIER
352 %token <scm> CONTEXT_MOD_IDENTIFIER
353 %token <scm> DRUM_PITCH
354 %token <scm> PITCH_IDENTIFIER
355 %token <scm> DURATION_IDENTIFIER
356 %token <scm> EVENT_IDENTIFIER
357 %token <scm> EVENT_FUNCTION
358 %token <scm> FRACTION
359 %token <scm> LYRICS_STRING
360 %token <scm> LYRIC_ELEMENT
361 %token <scm> LYRIC_MARKUP_IDENTIFIER
362 %token <scm> MARKUP_FUNCTION
363 %token <scm> MARKUP_LIST_FUNCTION
364 %token <scm> MARKUP_IDENTIFIER
365 %token <scm> MARKUPLIST_IDENTIFIER
366 %token <scm> MUSIC_FUNCTION
367 %token <scm> MUSIC_IDENTIFIER
368 %token <scm> NOTENAME_PITCH
369 %token <scm> NUMBER_IDENTIFIER
370 %token <scm> OUTPUT_DEF_IDENTIFIER
372 %token <scm> RESTNAME
373 %token <scm> SCM_FUNCTION
374 %token <scm> SCM_IDENTIFIER
375 %token <scm> SCM_TOKEN
376 %token <scm> SCORE_IDENTIFIER
378 %token <scm> STRING_IDENTIFIER
379 %token <scm> TONICNAME_PITCH
382 %type <book> book_block
383 %type <book> book_body
384 %type <book> bookpart_block
385 %type <book> bookpart_body
387 %type <i> bare_unsigned
388 %type <scm> figured_bass_alteration
390 %type <i> exclamations
391 %type <i> optional_rest
396 %type <i> tremolo_type
399 %type <scm> composite_music
400 %type <scm> grouped_music_list
401 %type <scm> braced_music_list
402 %type <scm> closed_music
404 %type <scm> music_bare
405 %type <scm> music_arg
406 %type <scm> music_assign
407 %type <scm> music_embedded
408 %type <scm> music_or_context_def
409 %type <scm> complex_music
410 %type <scm> complex_music_prefix
411 %type <scm> mode_changed_music
412 %type <scm> repeated_music
413 %type <scm> sequential_music
414 %type <scm> simple_music
415 %type <scm> simultaneous_music
416 %type <scm> chord_body
417 %type <scm> chord_body_element
418 %type <scm> command_element
419 %type <scm> command_event
420 %type <scm> context_modification
421 %type <scm> context_change
422 %type <scm> direction_less_event
423 %type <scm> direction_reqd_event
424 %type <scm> embedded_lilypond
425 %type <scm> event_chord
426 %type <scm> fingering
427 %type <scm> gen_text_def
428 %type <scm> music_property_def
429 %type <scm> note_chord_element
430 %type <scm> post_event
431 %type <scm> post_event_nofinger
432 %type <scm> re_rhythmed_music
433 %type <scm> simple_element
434 %type <scm> simple_music_property_def
435 %type <scm> start_symbol
436 %type <scm> string_number_event
437 %type <scm> tempo_event
439 %type <outputdef> output_def_body
440 %type <outputdef> output_def_head
441 %type <outputdef> output_def_head_with_mode_switch
442 %type <outputdef> output_def
443 %type <outputdef> paper_block
445 %type <scm> music_function_call
446 %type <scm> music_list
447 %type <scm> assignment_id
448 %type <scm> bare_number
449 %type <scm> bare_number_closed
450 %type <scm> unsigned_number
451 %type <scm> bass_figure
452 %type <scm> figured_bass_modification
453 %type <scm> br_bass_figure
454 %type <scm> bass_number
455 %type <scm> chord_body_elements
456 %type <scm> chord_item
457 %type <scm> chord_items
458 %type <scm> chord_separator
459 %type <scm> context_def_mod
460 %type <scm> context_def_spec_block
461 %type <scm> context_def_spec_body
462 %type <scm> context_mod
463 %type <scm> context_mod_arg
464 %type <scm> context_mod_embedded
465 %type <scm> context_mod_list
466 %type <scm> context_prop_spec
467 %type <scm> direction_less_char
468 %type <scm> duration_length
469 %type <scm> embedded_scm
470 %type <scm> embedded_scm_arg
471 %type <scm> embedded_scm_arg_closed
472 %type <scm> embedded_scm_bare
473 %type <scm> embedded_scm_bare_arg
474 %type <scm> embedded_scm_closed
475 %type <scm> event_function_event
476 %type <scm> figure_list
477 %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> lyric_element
500 %type <scm> lyric_element_arg
501 %type <scm> lyric_element_music
502 %type <scm> lyric_markup
504 %type <scm> markup_braced_list
505 %type <scm> markup_braced_list_body
506 %type <scm> markup_composed_list
507 %type <scm> markup_command_list
508 %type <scm> markup_command_list_arguments
509 %type <scm> markup_command_basic_arguments
510 %type <scm> markup_head_1_item
511 %type <scm> markup_head_1_list
512 %type <scm> markup_list
513 %type <scm> markup_top
514 %type <scm> maybe_notemode_duration
515 %type <scm> mode_changing_head
516 %type <scm> mode_changing_head_with_context
517 %type <scm> multiplied_duration
518 %type <scm> music_function_event
519 %type <scm> music_function_chord_body
520 %type <scm> new_chord
521 %type <scm> new_lyrics
522 %type <scm> number_expression
523 %type <scm> number_factor
524 %type <scm> number_term
525 %type <scm> octave_check
526 %type <scm> optional_context_mod
527 %type <scm> optional_id
528 %type <scm> optional_notemode_duration
530 %type <scm> pitch_also_in_chords
531 %type <scm> post_events
532 %type <scm> property_operation
533 %type <scm> property_path property_path_revved
535 %type <scm> scalar_closed
536 %type <scm> scm_function_call
537 %type <scm> scm_function_call_closed
538 %type <scm> script_abbreviation
539 %type <scm> simple_chord_elements
540 %type <scm> simple_markup
541 %type <scm> simple_string
542 %type <scm> steno_duration
543 %type <scm> steno_pitch
544 %type <scm> steno_tonic_pitch
545 %type <scm> step_number
546 %type <scm> step_numbers
548 %type <scm> tempo_range
550 %type <score> score_block
551 %type <score> score_body
556 /* We don't assign precedence to / and *, because we might need varied
557 prec levels in different prods */
566 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
567 parser->lexer_->push_note_state (nn);
568 } embedded_lilypond {
569 parser->lexer_->pop_state ();
570 parser->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
574 lilypond: /* empty */ { }
575 | lilypond toplevel_expression {
577 | lilypond assignment {
580 parser->error_level_ = 1;
583 parser->error_level_ = 1;
590 parser->lexer_->add_scope (get_header (parser));
592 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
596 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
597 scm_call_2 (proc, parser->self_scm (), book->self_scm ());
602 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
603 scm_call_2 (proc, parser->self_scm (), bookpart->self_scm ());
604 bookpart->unprotect ();
609 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
610 scm_call_2 (proc, parser->self_scm (), score->self_scm ());
614 Music *music = unsmob_music ($1);
615 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
616 scm_call_2 (proc, parser->self_scm (), music->self_scm ());
619 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
620 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
623 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
624 scm_call_2 (proc, parser->self_scm (), $1);
628 Output_def * od = $1;
630 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
631 id = ly_symbol2scm ("$defaultpaper");
632 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
633 id = ly_symbol2scm ("$defaultmidi");
634 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
635 id = ly_symbol2scm ("$defaultlayout");
637 parser->lexer_->set_identifier (id, od->self_scm ());
645 $$ = parser->lexer_->eval_scm_token ($1);
650 embedded_scm_bare_arg:
656 | context_modification
659 $$ = $1->self_scm ();
662 | context_def_spec_block
665 $$ = $1->self_scm ();
670 $$ = $1->self_scm ();
675 $$ = $1->self_scm ();
680 /* The generic version may end in music, or not */
688 embedded_scm_bare_arg
694 SCM_FUNCTION function_arglist {
695 $$ = MAKE_SYNTAX ("music-function", @$,
703 $$ = MAKE_SYNTAX ("void-music", @$);
706 | music_embedded music_embedded music_list {
707 $3 = scm_reverse_x ($3, SCM_EOL);
708 if (unsmob_music ($2))
709 $3 = scm_cons ($2, $3);
710 if (unsmob_music ($1))
711 $3 = scm_cons ($1, $3);
712 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
715 parser->error_level_ = 1;
717 | INVALID embedded_lilypond {
718 parser->error_level_ = 1;
723 lilypond_header_body:
725 | lilypond_header_body assignment {
731 HEADER '{' lilypond_header_body '}' {
732 $$ = parser->lexer_->remove_scope ();
741 | LYRICS_STRING { $$ = $1; }
745 assignment_id '=' identifier_init {
746 parser->lexer_->set_identifier ($1, $3);
748 | assignment_id property_path '=' identifier_init {
749 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
750 parser->lexer_->set_identifier (path, $4);
753 TODO: devise standard for protection in parser.
755 The parser stack lives on the C-stack, which means that
756 all objects can be unprotected as soon as they're here.
766 $$ = $1->self_scm ();
770 $$ = $1->self_scm ();
774 $$ = $1->self_scm ();
778 $$ = $1->self_scm ();
781 | context_def_spec_block {
787 | post_event_nofinger {
790 | number_expression {
808 | context_modification {
813 context_def_spec_block:
814 CONTEXT '{' context_def_spec_body '}'
825 context_mod_embedded:
828 if (unsmob_music ($1)) {
829 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
830 $1 = scm_call_2 (proc, parser->self_scm (), $1);
832 if (unsmob_context_mod ($1))
835 parser->parser_error (@1, _ ("not a context mod"));
841 context_def_spec_body:
843 $$ = Context_def::make_scm ();
844 unsmob_context_def ($$)->origin ()->set_spot (@$);
846 | CONTEXT_DEF_IDENTIFIER {
848 unsmob_context_def ($$)->origin ()->set_spot (@$);
850 | context_def_spec_body context_mod {
851 unsmob_context_def ($$)->add_context_mod ($2);
853 | context_def_spec_body context_modification {
854 Context_def *td = unsmob_context_def ($$);
855 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
856 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
857 td->add_context_mod (scm_car (m));
860 | context_def_spec_body context_mod_embedded {
861 Context_def *td = unsmob_context_def ($$);
862 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
863 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
864 td->add_context_mod (scm_car (m));
872 BOOK '{' book_body '}' {
875 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
880 * Use 'handlers' like for toplevel-* stuff?
881 * grok \layout and \midi? */
885 init_papers (parser);
886 $$->origin ()->set_spot (@$);
887 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
888 $$->paper_->unprotect ();
889 push_paper (parser, $$->paper_);
890 $$->header_ = get_header (parser);
891 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
894 $$ = unsmob_book ($1);
896 $$->origin ()->set_spot (@$);
897 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
899 | book_body paper_block {
902 set_paper (parser, $2);
904 | book_body bookpart_block {
906 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
907 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
908 bookpart->unprotect ();
910 | book_body score_block {
912 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
913 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
916 | book_body composite_music {
917 Music *music = unsmob_music ($2);
918 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
919 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
921 | book_body full_markup {
922 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
923 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
925 | book_body full_markup_list {
926 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
927 scm_call_2 (proc, $$->self_scm (), $2);
931 parser->lexer_->add_scope ($1->header_);
933 | book_body embedded_scm { }
936 $$->scores_ = SCM_EOL;
937 $$->bookparts_ = SCM_EOL;
942 BOOKPART '{' bookpart_body '}' {
944 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
951 $$->origin ()->set_spot (@$);
952 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
955 $$ = unsmob_book ($1);
957 $$->origin ()->set_spot (@$);
958 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
960 | bookpart_body paper_block {
964 | bookpart_body score_block {
966 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
967 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
970 | bookpart_body composite_music {
971 Music *music = unsmob_music ($2);
972 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
973 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
975 | bookpart_body full_markup {
976 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
977 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
979 | bookpart_body full_markup_list {
980 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
981 scm_call_2 (proc, $$->self_scm (), $2);
985 if (!ly_is_module ($1->header_))
986 $1->header_ = ly_make_module (false);
987 parser->lexer_->add_scope ($1->header_);
989 | bookpart_body embedded_scm { }
990 | bookpart_body error {
992 $$->scores_ = SCM_EOL;
997 SCORE '{' score_body '}' {
1005 SCM scorify = ly_lily_module_constant ("scorify-music");
1006 SCM score = scm_call_2 (scorify, m, parser->self_scm ());
1008 // pass ownernship to C++ again.
1009 $$ = unsmob_score (score);
1011 $$->origin ()->set_spot (@$);
1013 | SCORE_IDENTIFIER {
1014 $$ = unsmob_score ($1);
1016 $$->origin ()->set_spot (@$);
1020 if (!ly_is_module ($1->get_header ()))
1021 $1->set_header (ly_make_module (false));
1022 parser->lexer_->add_scope ($1->get_header ());
1024 | score_body output_def {
1025 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
1027 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1032 $$->add_output_def ($2);
1036 | score_body error {
1037 $$->error_found_ = true;
1049 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1051 parser->parser_error (@1, _ ("need \\paper for paper block"));
1053 $$ = get_paper (parser);
1060 output_def_body '}' {
1063 parser->lexer_->remove_scope ();
1064 parser->lexer_->pop_state ();
1070 $$ = get_paper (parser);
1071 $$->input_origin_ = @$;
1072 parser->lexer_->add_scope ($$->scope_);
1075 Output_def *p = get_midi (parser);
1077 parser->lexer_->add_scope (p->scope_);
1080 Output_def *p = get_layout (parser);
1082 parser->lexer_->add_scope (p->scope_);
1087 output_def_head_with_mode_switch:
1089 parser->lexer_->push_initial_state ();
1094 // We need this weird nonterminal because both music as well as a
1095 // context definition can start with \context and the difference is
1096 // only apparent after looking at the next token. If it is '{', there
1097 // is still time to escape from notes mode.
1099 music_or_context_def:
1102 parser->lexer_->pop_state ();
1106 parser->lexer_->pop_state ();
1107 } '{' context_def_spec_body '}'
1114 output_def_head_with_mode_switch '{' {
1116 $$->input_origin_.set_spot (@$);
1118 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1121 Output_def *o = unsmob_output_def ($3);
1122 o->input_origin_.set_spot (@$);
1125 parser->lexer_->remove_scope ();
1126 parser->lexer_->add_scope (o->scope_);
1128 | output_def_body assignment {
1133 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1134 parser->lexer_->push_note_state (nn);
1135 } music_or_context_def
1137 if (unsmob_context_def ($3))
1138 assign_context_def ($$, $3);
1141 SCM proc = parser->lexer_->lookup_identifier
1142 ("output-def-music-handler");
1143 scm_call_3 (proc, parser->self_scm (),
1144 $1->self_scm (), $3);
1147 | output_def_body error {
1153 TEMPO steno_duration '=' tempo_range {
1154 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1156 | TEMPO scalar_closed steno_duration '=' tempo_range {
1157 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1160 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1165 The representation of a list is reversed to have efficient append. */
1171 | music_list music_embedded {
1172 if (unsmob_music ($2))
1173 $$ = scm_cons ($2, $1);
1175 | music_list error {
1176 Music *m = MY_MAKE_MUSIC("Music", @$);
1178 m->set_property ("error-found", SCM_BOOL_T);
1179 $$ = scm_cons (m->self_scm (), $1);
1180 m->unprotect (); /* UGH */
1187 $$ = scm_reverse_x ($2, SCM_EOL);
1192 | lyric_element_music
1199 if (unsmob_music ($1)
1200 || scm_is_eq ($1, SCM_UNSPECIFIED))
1204 @$.warning (_ ("Ignoring non-music expression"));
1205 $$ = SCM_UNSPECIFIED;
1213 if (unsmob_pitch ($1)) {
1214 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
1215 n->set_property ("pitch", $1);
1216 n->set_property ("duration",
1217 parser->default_duration_.smobbed_copy ());
1218 $$ = n->unprotect ();
1221 | composite_music %prec COMPOSITE
1226 | composite_music %prec COMPOSITE
1227 | lyric_element_music
1231 REPEAT simple_string unsigned_number music
1233 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1235 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1237 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1242 SEQUENTIAL braced_music_list {
1243 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1245 | braced_music_list {
1246 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1251 SIMULTANEOUS braced_music_list {
1252 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1254 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1255 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1261 | music_property_def
1265 context_modification:
1266 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1268 parser->lexer_->pop_state ();
1271 | WITH CONTEXT_MOD_IDENTIFIER
1275 | CONTEXT_MOD_IDENTIFIER
1279 | WITH embedded_scm_closed
1281 if (unsmob_context_mod ($2))
1284 parser->parser_error (@2, _ ("not a context mod"));
1285 $$ = Context_mod ().smobbed_copy ();
1290 optional_context_mod:
1294 | context_modification
1302 $$ = Context_mod ().smobbed_copy ();
1304 | context_mod_list context_mod {
1305 unsmob_context_mod ($1)->add_context_mod ($2);
1307 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1308 Context_mod *md = unsmob_context_mod ($2);
1310 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1312 | context_mod_list context_mod_embedded {
1313 unsmob_context_mod ($1)->add_context_mods
1314 (unsmob_context_mod ($2)->get_mods ());
1323 /* Music that can be parsed without lookahead */
1326 | complex_music_prefix closed_music
1328 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1335 | grouped_music_list
1339 simultaneous_music { $$ = $1; }
1340 | sequential_music { $$ = $1; }
1343 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1344 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1345 and this rule returns the reversed list of arguments. */
1347 function_arglist_skip:
1348 function_arglist_common
1349 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1351 $$ = scm_cons ($1, $3);
1352 } %prec FUNCTION_ARGLIST
1353 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1355 $$ = scm_cons ($1, $3);
1356 } %prec FUNCTION_ARGLIST
1357 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1359 $$ = scm_cons ($1, $3);
1360 } %prec FUNCTION_ARGLIST
1364 function_arglist_nonbackup_common:
1365 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1366 $$ = scm_cons ($4, $3);
1368 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1369 $$ = scm_cons ($4, $3);
1371 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1373 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1375 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1377 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1379 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1381 SCM n = scm_difference ($5, SCM_UNDEFINED);
1382 if (scm_is_true (scm_call_1 ($2, n)))
1383 $$ = scm_cons (n, $3);
1385 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1386 t->set_property ("digit", $5);
1387 $$ = t->unprotect ();
1388 if (scm_is_true (scm_call_1 ($2, $$)))
1389 $$ = scm_cons ($$, $3);
1391 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1395 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1397 $$ = check_scheme_arg (parser, @4,
1398 scm_difference ($5, SCM_UNDEFINED),
1401 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1403 $$ = check_scheme_arg (parser, @4,
1404 scm_difference ($5, SCM_UNDEFINED),
1409 function_arglist_closed_nonbackup:
1410 function_arglist_nonbackup_common
1411 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1413 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1415 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1417 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1421 function_arglist_nonbackup:
1422 function_arglist_nonbackup_common
1423 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1425 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1427 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1429 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1433 function_arglist_keep:
1434 function_arglist_common
1435 | function_arglist_backup
1438 function_arglist_closed_keep:
1439 function_arglist_closed_common
1440 | function_arglist_backup
1443 function_arglist_backup:
1444 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1446 if (scm_is_true (scm_call_1 ($2, $4)))
1448 $$ = scm_cons ($4, $3);
1450 $$ = scm_cons (loc_on_music (@3, $1), $3);
1451 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1454 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1456 if (scm_is_true (scm_call_1 ($2, $4)))
1458 $$ = scm_cons ($4, $3);
1460 $$ = scm_cons (loc_on_music (@3, $1), $3);
1461 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1464 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1466 // There is no point interpreting a lyrics string as
1467 // an event, since we don't allow music possibly
1468 // followed by durations or postevent into closed
1469 // music, and we only accept closed music in optional
1470 // arguments at the moment. If this changes, more
1471 // complex schemes might become interesting here as
1472 // well: see how we do this at the mandatory argument
1474 if (scm_is_true (scm_call_1 ($2, $4)))
1475 $$ = scm_cons ($4, $3);
1477 $$ = scm_cons (loc_on_music (@3, $1), $3);
1478 MYBACKUP (LYRICS_STRING, $4, @4);
1481 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1483 if (scm_is_true (scm_call_1 ($2, $4)))
1486 MYREPARSE (@4, $2, UNSIGNED, $4);
1488 $$ = scm_cons (loc_on_music (@3, $1), $3);
1489 MYBACKUP (UNSIGNED, $4, @4);
1492 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1494 if (scm_is_true (scm_call_1 ($2, $4)))
1497 MYREPARSE (@4, $2, REAL, $4);
1499 $$ = scm_cons (loc_on_music (@3, $1), $3);
1500 MYBACKUP (REAL, $4, @4);
1503 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1505 if (scm_is_true (scm_call_1 ($2, $4)))
1507 $$ = scm_cons ($4, $3);
1509 $$ = scm_cons (loc_on_music (@3, $1), $3);
1510 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1513 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1515 if (scm_is_true (scm_call_1 ($2, $4)))
1517 $$ = scm_cons ($4, $3);
1519 $$ = scm_cons (loc_on_music (@3, $1), $3);
1520 MYBACKUP (FRACTION, $4, @4);
1523 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1525 SCM n = scm_difference ($5, SCM_UNDEFINED);
1526 if (scm_is_true (scm_call_1 ($2, n))) {
1528 MYREPARSE (@5, $2, REAL, n);
1530 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1531 t->set_property ("digit", $5);
1532 $$ = t->unprotect ();
1533 if (scm_is_true (scm_call_1 ($2, $$)))
1534 $$ = scm_cons ($$, $3);
1536 $$ = scm_cons (loc_on_music (@3, $1), $3);
1537 MYBACKUP (UNSIGNED, $5, @5);
1538 parser->lexer_->push_extra_token ('-');
1543 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1545 SCM n = scm_difference ($5, SCM_UNDEFINED);
1546 if (scm_is_true (scm_call_1 ($2, n))) {
1547 MYREPARSE (@5, $2, REAL, n);
1550 MYBACKUP (REAL, n, @5);
1553 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1555 SCM n = scm_difference ($5, SCM_UNDEFINED);
1556 if (scm_is_true (scm_call_1 ($2, n))) {
1557 $$ = scm_cons (n, $3);
1559 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1562 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1564 $$ = scm_cons ($4, $3);
1566 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1568 $$ = scm_cons ($4, $3);
1570 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1572 $$ = scm_cons ($1, $3);
1573 MYBACKUP(0, SCM_UNDEFINED, @3);
1575 | function_arglist_backup REPARSE embedded_scm_arg_closed
1577 $$ = check_scheme_arg (parser, @3,
1580 | function_arglist_backup REPARSE bare_number
1582 $$ = check_scheme_arg (parser, @3,
1588 function_arglist_common
1589 | function_arglist_nonbackup
1592 function_arglist_common:
1593 function_arglist_bare
1594 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1596 $$ = check_scheme_arg (parser, @3,
1599 | EXPECT_SCM function_arglist_closed_optional bare_number
1601 $$ = check_scheme_arg (parser, @3,
1604 | EXPECT_SCM function_arglist_closed_optional FRACTION
1606 $$ = check_scheme_arg (parser, @3,
1609 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1611 $$ = check_scheme_arg (parser, @3,
1614 | function_arglist_common_minus
1615 | function_arglist_common_lyric
1618 function_arglist_common_lyric:
1619 EXPECT_SCM function_arglist_optional lyric_element
1621 // We check how the predicate thinks about a lyrics
1622 // event or about a markup. If it accepts neither, we
1623 // backup the original token. Otherwise we commit to
1624 // taking the token. Depending on what the predicate
1625 // is willing to accept, we interpret as a string, as
1626 // a lyric event, or ambiguously (meaning that if
1627 // something looking like a duration or post event
1628 // follows, we take the event, otherwise the string).
1629 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1630 parser->default_duration_.smobbed_copy ());
1631 if (scm_is_true (scm_call_1 ($1, $3)))
1632 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1635 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1637 $$ = scm_cons ($3, $2);
1639 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1642 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1644 // This is going to flag a syntax error, we
1645 // know the predicate to be false.
1646 check_scheme_arg (parser, @3,
1650 | function_arglist_common_lyric REPARSE lyric_element_arg
1652 // This should never be false
1653 $$ = check_scheme_arg (parser, @3,
1658 function_arglist_common_minus:
1659 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1661 SCM n = scm_difference ($4, SCM_UNDEFINED);
1662 if (scm_is_true (scm_call_1 ($1, n))) {
1664 MYREPARSE (@4, $1, REAL, n);
1666 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1667 t->set_property ("digit", $4);
1668 $$ = t->unprotect ();
1669 if (scm_is_true (scm_call_1 ($1, $$)))
1670 $$ = scm_cons ($$, $2);
1672 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1676 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1679 SCM n = scm_difference ($4, SCM_UNDEFINED);
1680 MYREPARSE (@4, $1, REAL, n);
1682 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1684 SCM n = scm_difference ($4, SCM_UNDEFINED);
1685 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1687 | function_arglist_common_minus REPARSE bare_number
1689 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1693 function_arglist_closed:
1694 function_arglist_closed_common
1695 | function_arglist_closed_nonbackup
1698 function_arglist_closed_common:
1699 function_arglist_bare
1700 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1702 $$ = check_scheme_arg (parser, @3,
1705 | EXPECT_SCM function_arglist_closed_optional bare_number
1707 $$ = check_scheme_arg (parser, @3,
1710 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1712 SCM n = scm_difference ($4, SCM_UNDEFINED);
1713 if (scm_is_true (scm_call_1 ($1, n))) {
1714 $$ = scm_cons (n, $2);
1716 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1717 t->set_property ("digit", $4);
1718 $$ = t->unprotect ();
1719 if (scm_is_true (scm_call_1 ($1, $$)))
1720 $$ = scm_cons ($$, $2);
1722 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1726 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1728 $$ = check_scheme_arg (parser, @3,
1729 scm_difference ($4, SCM_UNDEFINED),
1732 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1734 $$ = check_scheme_arg (parser, @3,
1735 scm_difference ($4, SCM_UNDEFINED),
1738 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1740 $$ = check_scheme_arg (parser, @3,
1743 | EXPECT_SCM function_arglist_closed_optional FRACTION
1745 $$ = check_scheme_arg (parser, @3,
1748 | EXPECT_SCM function_arglist_optional lyric_element
1750 $$ = check_scheme_arg (parser, @3,
1755 function_arglist_optional:
1756 function_arglist_keep %prec FUNCTION_ARGLIST
1757 | function_arglist_backup BACKUP
1758 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1760 $$ = scm_cons ($1, $3);
1762 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1764 $$ = scm_cons ($1, $3);
1768 function_arglist_closed_optional:
1769 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1770 | function_arglist_backup BACKUP
1771 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1773 $$ = scm_cons ($1, $3);
1775 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1777 $$ = scm_cons ($1, $3);
1781 embedded_scm_closed:
1783 | scm_function_call_closed
1786 embedded_scm_arg_closed:
1787 embedded_scm_bare_arg
1788 | scm_function_call_closed
1792 scm_function_call_closed:
1793 SCM_FUNCTION function_arglist_closed {
1794 $$ = MAKE_SYNTAX ("music-function", @$,
1796 } %prec FUNCTION_ARGLIST
1799 function_arglist_bare:
1800 EXPECT_NO_MORE_ARGS {
1803 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1804 $$ = scm_cons ($3, $2);
1806 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1807 $$ = scm_cons ($3, $2);
1809 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1810 $$ = scm_cons ($1, $3);
1812 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1813 $$ = scm_cons ($1, $3);
1815 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1816 $$ = scm_cons ($1, $3);
1820 music_function_call:
1821 MUSIC_FUNCTION function_arglist {
1822 $$ = MAKE_SYNTAX ("music-function", @$,
1829 /**/ { $$ = SCM_EOL; }
1830 | '=' simple_string {
1837 | repeated_music { $$ = $1; }
1838 | re_rhythmed_music { $$ = $1; }
1839 | complex_music_prefix music
1841 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1845 complex_music_prefix:
1846 CONTEXT simple_string optional_id optional_context_mod {
1847 Context_mod *ctxmod = unsmob_context_mod ($4);
1850 mods = ctxmod->get_mods ();
1851 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1853 | NEWCONTEXT simple_string optional_id optional_context_mod {
1854 Context_mod *ctxmod = unsmob_context_mod ($4);
1857 mods = ctxmod->get_mods ();
1858 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1863 mode_changing_head grouped_music_list {
1864 if ($1 == ly_symbol2scm ("chords"))
1866 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1872 parser->lexer_->pop_state ();
1874 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1875 Context_mod *ctxmod = unsmob_context_mod ($2);
1878 mods = ctxmod->get_mods ();
1879 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1880 if ($1 == ly_symbol2scm ("ChordNames"))
1882 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1884 parser->lexer_->pop_state ();
1890 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1891 parser->lexer_->push_note_state (nn);
1893 $$ = ly_symbol2scm ("notes");
1897 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1898 parser->lexer_->push_note_state (nn);
1900 $$ = ly_symbol2scm ("drums");
1903 parser->lexer_->push_figuredbass_state ();
1905 $$ = ly_symbol2scm ("figures");
1908 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1909 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1910 nn = parser->lexer_->lookup_identifier ("pitchnames");
1911 parser->lexer_->push_chord_state (nn);
1912 $$ = ly_symbol2scm ("chords");
1916 { parser->lexer_->push_lyric_state ();
1917 $$ = ly_symbol2scm ("lyrics");
1921 mode_changing_head_with_context:
1923 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1924 parser->lexer_->push_note_state (nn);
1926 $$ = ly_symbol2scm ("DrumStaff");
1929 parser->lexer_->push_figuredbass_state ();
1931 $$ = ly_symbol2scm ("FiguredBass");
1934 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1935 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1936 nn = parser->lexer_->lookup_identifier ("pitchnames");
1937 parser->lexer_->push_chord_state (nn);
1938 $$ = ly_symbol2scm ("ChordNames");
1941 { parser->lexer_->push_lyric_state ();
1942 $$ = ly_symbol2scm ("Lyrics");
1947 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1950 /* Can also use music at the expensive of two S/Rs similar to
1951 \repeat \alternative */
1952 parser->lexer_->pop_state ();
1954 $$ = scm_cons ($3, SCM_EOL);
1956 | new_lyrics ADDLYRICS {
1957 parser->lexer_->push_lyric_state ();
1959 parser->lexer_->pop_state ();
1960 $$ = scm_cons ($4, $1);
1965 composite_music new_lyrics {
1966 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1968 | LYRICSTO simple_string {
1969 parser->lexer_->push_lyric_state ();
1971 parser->lexer_->pop_state ();
1972 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1977 CHANGE STRING '=' STRING {
1978 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1983 property_path_revved:
1984 embedded_scm_closed {
1985 $$ = scm_cons ($1, SCM_EOL);
1987 | property_path_revved embedded_scm_closed {
1988 $$ = scm_cons ($2, $1);
1993 property_path_revved {
1994 $$ = scm_reverse_x ($1, SCM_EOL);
2000 $$ = scm_list_3 (ly_symbol2scm ("assign"),
2001 scm_string_to_symbol ($1), $3);
2003 | UNSET simple_string {
2004 $$ = scm_list_2 (ly_symbol2scm ("unset"),
2005 scm_string_to_symbol ($2));
2007 | OVERRIDE simple_string property_path '=' scalar {
2008 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
2009 scm_string_to_symbol ($2), $5),
2012 | REVERT simple_string embedded_scm {
2013 $$ = scm_list_3 (ly_symbol2scm ("pop"),
2014 scm_string_to_symbol ($2), $3);
2019 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2020 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2022 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2023 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2024 | DENIES { $$ = ly_symbol2scm ("denies"); }
2026 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2027 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2028 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2029 | NAME { $$ = ly_symbol2scm ("context-name"); }
2033 property_operation { $$ = $1; }
2034 | context_def_mod STRING {
2035 $$ = scm_list_2 ($1, $2);
2037 | context_def_mod embedded_scm
2039 if (!scm_is_string ($2)
2040 && ly_symbol2scm ("consists") != $1
2041 && ly_symbol2scm ("remove") != $1)
2044 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2048 $$ = scm_list_2 ($1, $2);
2055 if (!is_regular_identifier ($1))
2057 @$.error (_("Grob name should be alphanumeric"));
2060 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
2061 scm_string_to_symbol ($1));
2063 | simple_string '.' simple_string {
2064 $$ = scm_list_2 (scm_string_to_symbol ($1),
2065 scm_string_to_symbol ($3));
2069 simple_music_property_def:
2070 OVERRIDE context_prop_spec property_path '=' scalar {
2071 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
2072 ly_symbol2scm ("OverrideProperty"),
2077 | REVERT context_prop_spec embedded_scm {
2078 $$ = scm_list_4 (scm_car ($2),
2079 ly_symbol2scm ("RevertProperty"),
2083 | SET context_prop_spec '=' scalar {
2084 $$ = scm_list_4 (scm_car ($2),
2085 ly_symbol2scm ("PropertySet"),
2089 | UNSET context_prop_spec {
2090 $$ = scm_list_3 (scm_car ($2),
2091 ly_symbol2scm ("PropertyUnset"),
2097 simple_music_property_def {
2098 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2106 | STRING_IDENTIFIER {
2109 | string '+' string {
2110 $$ = scm_string_append (scm_list_2 ($1, $3));
2114 simple_string: STRING {
2120 | STRING_IDENTIFIER {
2133 embedded_scm_arg_closed
2141 simple_element post_events {
2142 // Let the rhythmic music iterator sort this mess out.
2143 if (scm_is_pair ($2)) {
2144 if (unsmob_pitch ($1)) {
2145 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
2146 n->set_property ("pitch", $1);
2147 n->set_property ("duration",
2148 parser->default_duration_.smobbed_copy ());
2149 $$ = n->unprotect ();
2151 unsmob_music ($$)->set_property ("articulations",
2152 scm_reverse_x ($2, SCM_EOL));
2155 | simple_chord_elements post_events {
2156 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2159 /* why is this giving wrong start location? -ns
2161 i.set_location (@1, @2);
2162 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2164 | CHORD_REPETITION optional_notemode_duration post_events {
2166 i.set_location (@1, @3);
2167 $$ = MAKE_SYNTAX ("repetition-chord", i,
2168 $2, scm_reverse_x ($3, SCM_EOL));
2170 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2172 i.set_location (@1, @3);
2173 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2174 scm_reverse_x ($3, SCM_EOL));
2177 | note_chord_element
2182 chord_body optional_notemode_duration post_events
2184 Music *m = unsmob_music ($1);
2185 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2186 SCM es = m->get_property ("elements");
2187 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2189 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2190 unsmob_music (scm_car (s))->set_property ("duration", dur);
2191 es = ly_append2 (es, postevs);
2193 m-> set_property ("elements", es);
2195 $$ = m->self_scm ();
2200 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2202 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2206 chord_body_elements:
2207 /* empty */ { $$ = SCM_EOL; }
2208 | chord_body_elements chord_body_element {
2209 if (!SCM_UNBNDP ($2))
2210 $$ = scm_cons ($2, $1);
2215 pitch exclamations questions octave_check post_events
2222 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2223 n->set_property ("pitch", $1);
2225 n->set_property ("cautionary", SCM_BOOL_T);
2226 if (ex % 2 || q % 2)
2227 n->set_property ("force-accidental", SCM_BOOL_T);
2229 if (scm_is_pair (post)) {
2230 SCM arts = scm_reverse_x (post, SCM_EOL);
2231 n->set_property ("articulations", arts);
2233 if (scm_is_number (check))
2235 int q = scm_to_int (check);
2236 n->set_property ("absolute-octave", scm_from_int (q-1));
2239 $$ = n->unprotect ();
2241 | DRUM_PITCH post_events {
2242 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2243 n->set_property ("drum-type", $1);
2245 if (scm_is_pair ($2)) {
2246 SCM arts = scm_reverse_x ($2, SCM_EOL);
2247 n->set_property ("articulations", arts);
2249 $$ = n->unprotect ();
2251 | music_function_chord_body
2253 Music *m = unsmob_music ($1);
2255 while (m && m->is_mus_type ("music-wrapper-music")) {
2256 $$ = m->get_property ("element");
2257 m = unsmob_music ($$);
2260 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2261 parser->parser_error (@$, _ ("not a rhythmic event"));
2267 music_function_chord_body:
2272 // Event functions may only take closed arglists, otherwise it would
2273 // not be clear whether a following postevent should be associated
2274 // with the last argument of the event function or with the expression
2275 // for which the function call acts itself as event.
2277 music_function_event:
2278 MUSIC_FUNCTION function_arglist_closed {
2279 $$ = MAKE_SYNTAX ("music-function", @$,
2284 event_function_event:
2285 EVENT_FUNCTION function_arglist_closed {
2286 $$ = MAKE_SYNTAX ("music-function", @$,
2296 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2297 m->set_property ("span-direction", scm_from_int (START));
2298 $$ = m->unprotect();
2301 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2302 m->set_property ("span-direction", scm_from_int (STOP));
2303 $$ = m->unprotect ();
2306 $$ = MAKE_SYNTAX ("voice-separator", @$);
2309 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2311 Music *m = unsmob_music (pipe);
2316 $$ = m->unprotect ();
2319 $$ = MAKE_SYNTAX ("bar-check", @$);
2326 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2338 | post_events post_event {
2339 unsmob_music ($2)->set_spot (@2);
2340 $$ = scm_cons ($2, $$);
2344 post_event_nofinger:
2345 direction_less_event {
2348 | script_dir music_function_event {
2352 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2356 if (!parser->lexer_->is_lyric_state ())
2357 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2358 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2361 if (!parser->lexer_->is_lyric_state ())
2362 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2363 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2365 | script_dir direction_reqd_event {
2368 Music *m = unsmob_music ($2);
2369 m->set_property ("direction", scm_from_int ($1));
2373 | script_dir direction_less_event {
2376 Music *m = unsmob_music ($2);
2377 m->set_property ("direction", scm_from_int ($1));
2381 | string_number_event
2385 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2390 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2401 string_number_event:
2403 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2404 s->set_property ("string-number", scm_from_int ($1));
2405 $$ = s->unprotect ();
2409 direction_less_char:
2411 $$ = ly_symbol2scm ("bracketOpenSymbol");
2414 $$ = ly_symbol2scm ("bracketCloseSymbol");
2417 $$ = ly_symbol2scm ("tildeSymbol");
2420 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2423 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2426 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2429 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2432 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2435 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2438 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2442 direction_less_event:
2443 direction_less_char {
2444 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2446 if (unsmob_music (predefd))
2448 m = unsmob_music (predefd)->clone ();
2453 m = MY_MAKE_MUSIC ("Music", @$);
2455 $$ = m->unprotect ();
2457 | EVENT_IDENTIFIER {
2461 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2462 a->set_property ("tremolo-type", scm_from_int ($1));
2463 $$ = a->unprotect ();
2465 | event_function_event
2468 direction_reqd_event:
2472 | script_abbreviation {
2473 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2474 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2475 if (scm_is_string (s))
2476 a->set_property ("articulation-type", s);
2477 else parser->parser_error (@1, _ ("expecting string as script definition"));
2478 $$ = a->unprotect ();
2483 /**/ { $$ = SCM_EOL; }
2484 | '=' { $$ = scm_from_int (0); }
2485 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2486 | '=' sup_quotes { $$ = scm_from_int ($2); }
2511 | NOTENAME_PITCH sup_quotes {
2512 Pitch p = *unsmob_pitch ($1);
2513 p = p.transposed (Pitch ($2,0,0));
2514 $$ = p.smobbed_copy ();
2516 | NOTENAME_PITCH sub_quotes {
2517 Pitch p =* unsmob_pitch ($1);
2518 p = p.transposed (Pitch (-$2,0,0));
2519 $$ = p.smobbed_copy ();
2531 | TONICNAME_PITCH sup_quotes {
2532 Pitch p = *unsmob_pitch ($1);
2533 p = p.transposed (Pitch ($2,0,0));
2534 $$ = p.smobbed_copy ();
2536 | TONICNAME_PITCH sub_quotes {
2537 Pitch p = *unsmob_pitch ($1);
2539 p = p.transposed (Pitch (-$2,0,0));
2540 $$ = p.smobbed_copy ();
2551 pitch_also_in_chords:
2558 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2559 t->set_property ("text", $1);
2560 $$ = t->unprotect ();
2563 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2564 t->set_property ("text",
2565 make_simple_markup ($1));
2566 $$ = t->unprotect ();
2572 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2573 t->set_property ("digit", $1);
2574 $$ = t->unprotect ();
2578 script_abbreviation:
2580 $$ = scm_from_locale_string ("Hat");
2583 $$ = scm_from_locale_string ("Plus");
2586 $$ = scm_from_locale_string ("Dash");
2589 $$ = scm_from_locale_string ("Bar");
2592 $$ = scm_from_locale_string ("Larger");
2595 $$ = scm_from_locale_string ("Dot");
2598 $$ = scm_from_locale_string ("Underscore");
2605 | '-' { $$ = CENTER; }
2609 multiplied_duration {
2614 maybe_notemode_duration:
2618 | multiplied_duration {
2620 parser->default_duration_ = *unsmob_duration ($$);
2625 optional_notemode_duration:
2626 maybe_notemode_duration
2628 if (SCM_UNBNDP ($$))
2629 $$ = parser->default_duration_.smobbed_copy ();
2634 bare_unsigned dots {
2636 if (!is_duration ($1))
2637 parser->parser_error (@1, _f ("not a duration: %d", $1));
2641 $$ = Duration (len, $2).smobbed_copy ();
2643 | DURATION_IDENTIFIER dots {
2644 Duration *d = unsmob_duration ($1);
2645 Duration k (d->duration_log (), d->dot_count () + $2);
2646 k = k.compressed (d->factor ());
2652 multiplied_duration:
2656 | multiplied_duration '*' bare_unsigned {
2657 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2659 | multiplied_duration '*' FRACTION {
2660 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2662 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2679 | ':' bare_unsigned {
2680 if (!is_duration ($2))
2681 parser->parser_error (@2, _f ("not a duration: %d", $2));
2687 UNSIGNED { $$ = $1; }
2688 | STRING { $$ = $1; }
2689 | full_markup { $$ = $1; }
2692 figured_bass_alteration:
2693 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2694 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2695 | '!' { $$ = scm_from_int (0); }
2700 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2701 $$ = bfr->unprotect ();
2704 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2705 $$ = bfr->self_scm ();
2707 if (scm_is_number ($1))
2708 bfr->set_property ("figure", $1);
2709 else if (Text_interface::is_markup ($1))
2710 bfr->set_property ("text", $1);
2716 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2718 | bass_figure figured_bass_alteration {
2719 Music *m = unsmob_music ($1);
2720 if (scm_to_double ($2)) {
2721 SCM salter = m->get_property ("alteration");
2722 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2723 m->set_property ("alteration",
2724 scm_sum (alter, $2));
2726 m->set_property ("alteration", scm_from_int (0));
2729 | bass_figure figured_bass_modification {
2730 Music *m = unsmob_music ($1);
2731 if ($2 == ly_symbol2scm ("plus"))
2733 m->set_property ("augmented", SCM_BOOL_T);
2735 else if ($2 == ly_symbol2scm ("slash"))
2737 m->set_property ("diminished", SCM_BOOL_T);
2739 else if ($2 == ly_symbol2scm ("exclamation"))
2741 m->set_property ("no-continuation", SCM_BOOL_T);
2743 else if ($2 == ly_symbol2scm ("backslash"))
2745 m->set_property ("augmented-slash", SCM_BOOL_T);
2751 figured_bass_modification:
2753 $$ = ly_symbol2scm ("plus");
2756 $$ = ly_symbol2scm ("exclamation");
2759 $$ = ly_symbol2scm ("slash");
2762 $$ = ly_symbol2scm ("backslash");
2772 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2780 | figure_list br_bass_figure {
2781 $$ = scm_cons ($2, $1);
2786 FIGURE_OPEN figure_list FIGURE_CLOSE {
2787 $$ = scm_reverse_x ($2, SCM_EOL);
2798 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2799 if (!parser->lexer_->is_note_state ())
2800 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2801 if ($2 || $3 || scm_is_number ($4) || !SCM_UNBNDP ($5) || $6)
2805 n = MY_MAKE_MUSIC ("RestEvent", @$);
2807 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2809 n->set_property ("pitch", $1);
2810 if (SCM_UNBNDP ($5))
2811 n->set_property ("duration",
2812 parser->default_duration_.smobbed_copy ());
2814 n->set_property ("duration", $5);
2816 if (scm_is_number ($4))
2818 int q = scm_to_int ($4);
2819 n->set_property ("absolute-octave", scm_from_int (q-1));
2823 n->set_property ("cautionary", SCM_BOOL_T);
2824 if ($2 % 2 || $3 % 2)
2825 n->set_property ("force-accidental", SCM_BOOL_T);
2827 $$ = n->unprotect ();
2830 | DRUM_PITCH optional_notemode_duration {
2831 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2832 n->set_property ("duration", $2);
2833 n->set_property ("drum-type", $1);
2835 $$ = n->unprotect ();
2837 | RESTNAME optional_notemode_duration {
2839 if (ly_scm2string ($1) == "s") {
2841 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2844 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2847 ev->set_property ("duration", $2);
2848 $$ = ev->unprotect ();
2852 simple_chord_elements:
2854 if (!parser->lexer_->is_chord_state ())
2855 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2858 | figure_spec optional_notemode_duration {
2859 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2861 unsmob_music (scm_car (s))->set_property ("duration", $2);
2878 | lyric_element multiplied_duration post_events {
2879 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2880 if (scm_is_pair ($3))
2881 unsmob_music ($$)->set_property
2882 ("articulations", scm_reverse_x ($3, SCM_EOL));
2884 | lyric_element post_event post_events {
2885 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2886 parser->default_duration_.smobbed_copy ());
2887 unsmob_music ($$)->set_property
2888 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2890 | LYRIC_ELEMENT optional_notemode_duration post_events {
2891 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2892 if (scm_is_pair ($3))
2893 unsmob_music ($$)->set_property
2894 ("articulations", scm_reverse_x ($3, SCM_EOL));
2899 lyric_element_music:
2900 lyric_element optional_notemode_duration post_events {
2901 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2902 if (scm_is_pair ($3))
2903 unsmob_music ($$)->set_property
2904 ("articulations", scm_reverse_x ($3, SCM_EOL));
2909 steno_tonic_pitch optional_notemode_duration {
2910 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2912 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2913 SCM its = scm_reverse_x ($4, SCM_EOL);
2914 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2922 | chord_items chord_item {
2923 $$ = scm_cons ($2, $$);
2929 $$ = ly_symbol2scm ("chord-colon");
2932 $$ = ly_symbol2scm ("chord-caret");
2934 | CHORD_SLASH steno_tonic_pitch {
2935 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2937 | CHORD_BASS steno_tonic_pitch {
2938 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2947 $$ = scm_reverse_x ($1, SCM_EOL);
2955 step_number { $$ = scm_cons ($1, SCM_EOL); }
2956 | step_numbers '.' step_number {
2957 $$ = scm_cons ($3, $$);
2963 $$ = make_chord_step ($1, 0);
2965 | bare_unsigned '+' {
2966 $$ = make_chord_step ($1, SHARP_ALTERATION);
2968 | bare_unsigned CHORD_MINUS {
2969 $$ = make_chord_step ($1, FLAT_ALTERATION);
2975 $$ = scm_from_int ($1);
2977 | bare_unsigned '~' bare_unsigned {
2978 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2985 TODO: should deprecate in favor of Scheme?
2989 number_expression '+' number_term {
2990 $$ = scm_sum ($1, $3);
2992 | number_expression '-' number_term {
2993 $$ = scm_difference ($1, $3);
3002 | number_factor '*' number_factor {
3003 $$ = scm_product ($1, $3);
3005 | number_factor '/' number_factor {
3006 $$ = scm_divide ($1, $3);
3011 '-' number_factor { /* %prec UNARY_MINUS */
3012 $$ = scm_difference ($2, SCM_UNDEFINED);
3020 | UNSIGNED NUMBER_IDENTIFIER {
3021 $$ = scm_product ($1, $2);
3023 | REAL NUMBER_IDENTIFIER {
3024 $$ = scm_product ($1, $2);
3036 $$ = scm_to_int ($1);
3047 | exclamations '!' { $$ ++; }
3052 | questions '?' { $$ ++; }
3056 This should be done more dynamically if possible.
3060 LYRIC_MARKUP_IDENTIFIER {
3064 { parser->lexer_->push_markup_state (); }
3067 parser->lexer_->pop_state ();
3072 MARKUPLIST_IDENTIFIER {
3076 { parser->lexer_->push_markup_state (); }
3079 parser->lexer_->pop_state ();
3088 { parser->lexer_->push_markup_state (); }
3091 parser->lexer_->pop_state ();
3097 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3099 | markup_head_1_list simple_markup {
3100 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3110 if (Text_interface::is_markup ($1))
3111 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3112 else if (Text_interface::is_markup_list ($1))
3113 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3115 parser->parser_error (@1, _ ("not a markup"));
3116 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3123 MARKUPLIST_IDENTIFIER {
3126 | markup_composed_list {
3129 | markup_braced_list {
3132 | markup_command_list {
3133 $$ = scm_list_1 ($1);
3135 | markup_scm MARKUPLIST_IDENTIFIER
3141 markup_composed_list:
3142 markup_head_1_list markup_braced_list {
3143 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3149 '{' markup_braced_list_body '}' {
3150 $$ = scm_reverse_x ($2, SCM_EOL);
3154 markup_braced_list_body:
3155 /* empty */ { $$ = SCM_EOL; }
3156 | markup_braced_list_body markup {
3157 $$ = scm_cons ($2, $1);
3159 | markup_braced_list_body markup_list {
3160 $$ = scm_reverse_x ($2, $1);
3164 markup_command_list:
3165 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3166 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3170 markup_command_basic_arguments:
3171 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3172 $$ = scm_cons ($3, $2);
3174 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3175 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3177 | EXPECT_NO_MORE_ARGS {
3182 markup_command_list_arguments:
3183 markup_command_basic_arguments { $$ = $1; }
3184 | EXPECT_MARKUP markup_command_list_arguments markup {
3185 $$ = scm_cons ($3, $2);
3190 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3191 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3196 markup_head_1_item {
3197 $$ = scm_list_1 ($1);
3199 | markup_head_1_list markup_head_1_item {
3200 $$ = scm_cons ($2, $1);
3206 $$ = make_simple_markup ($1);
3208 | MARKUP_IDENTIFIER {
3211 | LYRIC_MARKUP_IDENTIFIER {
3214 | STRING_IDENTIFIER {
3218 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3219 parser->lexer_->push_note_state (nn);
3220 } '{' score_body '}' {
3222 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3224 parser->lexer_->pop_state ();
3226 | MARKUP_FUNCTION markup_command_basic_arguments {
3227 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3229 | markup_scm MARKUP_IDENTIFIER
3236 markup_head_1_list simple_markup {
3237 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3238 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3248 Lily_parser::set_yydebug (bool x)
3254 Lily_parser::do_yyparse ()
3265 It is a little strange to have this function in this file, but
3266 otherwise, we have to import music classes into the lexer.
3270 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3272 if (scm_is_string (sid)) {
3274 return STRING_IDENTIFIER;
3275 } else if (unsmob_book (sid)) {
3276 Book *book = unsmob_book (sid)->clone ();
3277 *destination = book->self_scm ();
3280 return BOOK_IDENTIFIER;
3281 } else if (scm_is_number (sid)) {
3283 return NUMBER_IDENTIFIER;
3284 } else if (unsmob_context_def (sid)) {
3285 Context_def *def= unsmob_context_def (sid)->clone ();
3287 *destination = def->self_scm ();
3290 return CONTEXT_DEF_IDENTIFIER;
3291 } else if (unsmob_context_mod (sid)) {
3292 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3294 return CONTEXT_MOD_IDENTIFIER;
3295 } else if (unsmob_score (sid)) {
3296 Score *score = new Score (*unsmob_score (sid));
3297 *destination = score->self_scm ();
3299 score->unprotect ();
3300 return SCORE_IDENTIFIER;
3301 } else if (Music *mus = unsmob_music (sid)) {
3302 mus = mus->clone ();
3303 *destination = mus->self_scm ();
3304 unsmob_music (*destination)->
3305 set_property ("origin", make_input (last_input_));
3307 bool is_event = mus->is_mus_type ("post-event");
3309 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3310 } else if (unsmob_pitch (sid)) {
3311 *destination = unsmob_pitch (sid)->smobbed_copy ();
3312 return PITCH_IDENTIFIER;
3313 } else if (unsmob_duration (sid)) {
3314 *destination = unsmob_duration (sid)->smobbed_copy ();
3315 return DURATION_IDENTIFIER;
3316 } else if (unsmob_output_def (sid)) {
3317 Output_def *p = unsmob_output_def (sid);
3320 *destination = p->self_scm ();
3322 return OUTPUT_DEF_IDENTIFIER;
3323 } else if (Text_interface::is_markup (sid)) {
3325 if (is_lyric_state ())
3326 return LYRIC_MARKUP_IDENTIFIER;
3327 return MARKUP_IDENTIFIER;
3328 } else if (Text_interface::is_markup_list (sid)) {
3330 return MARKUPLIST_IDENTIFIER;
3337 get_next_unique_context_id ()
3339 return scm_from_locale_string ("$uniqueContextId");
3344 get_next_unique_lyrics_context_id ()
3346 static int new_context_count;
3348 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3349 return scm_from_locale_string (s);
3352 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3353 SCM arg, SCM args, SCM pred)
3355 args = scm_cons (arg, args);
3356 if (scm_is_true (scm_call_1 (pred, arg)))
3358 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3359 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3360 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3364 SCM loc_on_music (Input loc, SCM arg)
3366 if (Music *m = unsmob_music (arg))
3370 return m->unprotect ();
3376 is_regular_identifier (SCM id)
3378 string str = ly_scm2string (id);
3379 char const *s = str.c_str ();
3388 v = v && isalnum (*s);
3395 make_music_with_input (SCM name, Input where)
3397 Music *m = make_music_by_name (name);
3398 m->set_spot (where);
3403 make_simple_markup (SCM a)
3411 return t && t == 1 << intlog2 (t);
3415 set_music_properties (Music *p, SCM a)
3417 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3418 p->set_property (scm_caar (k), scm_cdar (k));
3423 make_chord_step (int step, Rational alter)
3426 alter += FLAT_ALTERATION;
3430 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3431 return m.smobbed_copy ();
3436 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3438 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3439 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3440 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3442 unsmob_music (scm_car (s))->set_spot (loc);
3448 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3450 Lily_lexer *lex = parser->lexer_;
3454 lex->prepare_for_next_token ();
3455 return lex->yylex ();