2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 Jan Nieuwenhuizen <janneke@gnu.org>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
24 #define YYERROR_VERBOSE 1
25 #define YYPARSE_PARAM my_lily_parser
26 #define YYLEX_PARAM my_lily_parser
27 #define PARSER ((Lily_parser *) my_lily_parser)
29 #define yyerror PARSER->parser_error
31 /* We use custom location type: Input objects */
33 #define YYLLOC_DEFAULT(Current,Rhs,N) \
34 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
39 /* We use SCMs to do strings, because it saves us the trouble of
40 deleting them. Let's hope that a stack overflow doesnt trigger a move
41 of the parse stack onto the heap. */
47 /* The above precedences tackle the shift/reduce problem
50 \repeat .. \alternative
52 \repeat { \repeat .. \alternative }
56 \repeat { \repeat } \alternative
62 /* ADDLYRICS needs to have lower precedence than argument scanning,
63 * or we won't be able to tell music apart from closed_music without
64 * lookahead in the context of function calls.
69 /* \default is only applied after exhausting function arguments */
71 %nonassoc FUNCTION_ARGLIST
73 /* expressions with units are permitted into argument lists */
75 %right PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
76 UNSIGNED REAL DURATION_IDENTIFIER ':'
78 /* The above are the symbols that can start optional function arguments
79 that are recognized in the grammar rather than by predicate
82 %nonassoc NUMBER_IDENTIFIER '/'
84 /* Number-unit expressions, where permitted, are concatenated into
85 * function arguments, just like fractions and tremoli. Tremoli must
86 * not have higher precedence than UNSIGNED, or Lilypond will not
87 * join ':' with a following optional number.
100 %{ // -*-Fundamental-*-
105 * The rules for who is protecting what are very shady. Uniformise
108 * There are too many lexical modes?
119 #include "context-def.hh"
120 #include "context-mod.hh"
121 #include "dimensions.hh"
122 #include "file-path.hh"
124 #include "international.hh"
125 #include "lily-guile.hh"
126 #include "lily-lexer.hh"
127 #include "lily-parser.hh"
131 #include "output-def.hh"
132 #include "paper-book.hh"
133 #include "scm-hash.hh"
135 #include "text-interface.hh"
138 #define MYBACKUP(Token, Value, Location) \
140 if (yychar == YYEMPTY) \
143 PARSER->lexer_->push_extra_token (Token, Value); \
144 PARSER->lexer_->push_extra_token (BACKUP); \
146 PARSER->parser_error \
147 (Location, _("Too much lookahead")); \
152 #define MYREPARSE(Location, Pred, Token, Value) \
154 if (yychar == YYEMPTY) \
156 PARSER->lexer_->push_extra_token (Token, Value); \
157 PARSER->lexer_->push_extra_token (REPARSE, \
160 PARSER->parser_error \
161 (Location, _("Too much lookahead")); \
170 Output_def *outputdef;
179 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
182 - Don't use lily module, create a new module instead.
183 - delay application of the function
185 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
186 scm_apply_0 (proc, args)
187 /* Syntactic Sugar. */
188 #define MAKE_SYNTAX(name, location, ...) \
189 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location) , ##__VA_ARGS__, SCM_UNDEFINED));
190 #define START_MAKE_SYNTAX(name, ...) \
191 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
192 #define FINISH_MAKE_SYNTAX(start, location, ...) \
193 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)))))
195 SCM get_next_unique_context_id ();
196 SCM get_next_unique_lyrics_context_id ();
203 #define _(x) gettext (x)
207 static Music *make_music_with_input (SCM name, Input where);
208 SCM check_scheme_arg (Lily_parser *parser, Input loc,
209 SCM arg, SCM args, SCM pred);
210 SCM loc_on_music (Input loc, SCM arg);
211 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
212 SCM make_chord_step (int step, Rational alter);
213 SCM make_simple_markup (SCM a);
214 bool is_duration (int t);
215 bool is_regular_identifier (SCM id);
216 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
217 void set_music_properties (Music *p, SCM a);
221 /* The third option is an alias that will be used to display the
222 syntax error. Bison CVS now correctly handles backslash escapes.
224 FIXME: Bison needs to translate some of these, eg, STRING.
228 /* Keyword tokens with plain escaped name. */
229 %token ACCEPTS "\\accepts"
230 %token ADDLYRICS "\\addlyrics"
231 %token ALIAS "\\alias"
232 %token ALTERNATIVE "\\alternative"
234 %token BOOKPART "\\bookpart"
235 %token CHANGE "\\change"
236 %token CHORDMODE "\\chordmode"
237 %token CHORDS "\\chords"
238 %token CONSISTS "\\consists"
239 %token CONTEXT "\\context"
240 %token DEFAULT "\\default"
241 %token DEFAULTCHILD "\\defaultchild"
242 %token DENIES "\\denies"
243 %token DESCRIPTION "\\description"
244 %token DRUMMODE "\\drummode"
245 %token DRUMS "\\drums"
246 %token FIGUREMODE "\\figuremode"
247 %token FIGURES "\\figures"
248 %token HEADER "\\header"
249 %token INVALID "\\version-error"
250 %token LAYOUT "\\layout"
251 %token LYRICMODE "\\lyricmode"
252 %token LYRICS "\\lyrics"
253 %token LYRICSTO "\\lyricsto"
254 %token MARKUP "\\markup"
255 %token MARKUPLIST "\\markuplist"
258 %token NOTEMODE "\\notemode"
259 %token OVERRIDE "\\override"
260 %token PAPER "\\paper"
261 %token REMOVE "\\remove"
262 %token REPEAT "\\repeat"
264 %token REVERT "\\revert"
265 %token SCORE "\\score"
266 %token SEQUENTIAL "\\sequential"
268 %token SIMULTANEOUS "\\simultaneous"
269 %token TEMPO "\\tempo"
271 %token UNSET "\\unset"
274 /* Keyword token exceptions. */
275 %token NEWCONTEXT "\\new"
278 /* Other string tokens. */
280 %token CHORD_BASS "/+"
281 %token CHORD_CARET "^"
282 %token CHORD_COLON ":"
283 %token CHORD_MINUS "-"
284 %token CHORD_SLASH "/"
285 %token ANGLE_OPEN "<"
286 %token ANGLE_CLOSE ">"
287 %token DOUBLE_ANGLE_OPEN "<<"
288 %token DOUBLE_ANGLE_CLOSE ">>"
289 %token E_BACKSLASH "\\"
290 %token E_ANGLE_CLOSE "\\>"
291 %token E_CHAR "\\C[haracter]"
293 %token E_EXCLAMATION "\\!"
294 %token E_BRACKET_OPEN "\\["
296 %token E_BRACKET_CLOSE "\\]"
297 %token E_ANGLE_OPEN "\\<"
303 If we give names, Bison complains.
305 %token FIGURE_CLOSE /* "\\>" */
306 %token FIGURE_OPEN /* "\\<" */
307 %token FIGURE_SPACE "_"
310 %token CHORDMODIFIERS
312 %token MULTI_MEASURE_REST
315 %token <i> E_UNSIGNED
316 %token <scm> UNSIGNED
318 /* Artificial tokens, for more generic function syntax */
319 %token <i> EXPECT_MARKUP "markup?"
320 %token <i> EXPECT_PITCH "ly:pitch?"
321 %token <i> EXPECT_DURATION "ly:duration?"
322 %token <scm> EXPECT_SCM "scheme?"
323 %token <scm> BACKUP "(backed-up?)"
324 %token <scm> REPARSE "(reparsed?)"
325 %token <i> EXPECT_MARKUP_LIST "markup-list?"
326 %token <scm> EXPECT_OPTIONAL "optional?"
327 /* After the last argument. */
328 %token <i> EXPECT_NO_MORE_ARGS;
330 /* An artificial token for parsing embedded Lilypond */
331 %token <i> EMBEDDED_LILY "#{"
333 %token <scm> BOOK_IDENTIFIER
334 %token <scm> CHORDMODIFIER_PITCH
335 %token <scm> CHORD_MODIFIER
336 %token <scm> CHORD_REPETITION
337 %token <scm> CONTEXT_DEF_IDENTIFIER
338 %token <scm> CONTEXT_MOD_IDENTIFIER
339 %token <scm> DRUM_PITCH
340 %token <scm> PITCH_IDENTIFIER
341 %token <scm> DURATION_IDENTIFIER
342 %token <scm> EVENT_IDENTIFIER
343 %token <scm> EVENT_FUNCTION
344 %token <scm> FRACTION
345 %token <scm> LYRICS_STRING
346 %token <scm> LYRIC_ELEMENT
347 %token <scm> LYRIC_ELEMENT_P
348 %token <scm> LYRIC_MARKUP_IDENTIFIER
349 %token <scm> MARKUP_FUNCTION
350 %token <scm> MARKUP_LIST_FUNCTION
351 %token <scm> MARKUP_IDENTIFIER
352 %token <scm> MARKUPLIST_IDENTIFIER
353 %token <scm> MUSIC_FUNCTION
354 %token <scm> MUSIC_IDENTIFIER
355 %token <scm> NOTENAME_PITCH
356 %token <scm> NUMBER_IDENTIFIER
357 %token <scm> OUTPUT_DEF_IDENTIFIER
359 %token <scm> RESTNAME
360 %token <scm> SCM_FUNCTION
361 %token <scm> SCM_IDENTIFIER
362 %token <scm> SCM_TOKEN
363 %token <scm> SCORE_IDENTIFIER
365 %token <scm> STRING_IDENTIFIER
366 %token <scm> TONICNAME_PITCH
369 %type <book> book_block
370 %type <book> book_body
371 %type <book> bookpart_block
372 %type <book> bookpart_body
374 %type <i> bare_unsigned
375 %type <scm> figured_bass_alteration
377 %type <i> exclamations
378 %type <i> optional_rest
383 %type <i> tremolo_type
386 %type <scm> composite_music
387 %type <scm> grouped_music_list
388 %type <scm> braced_music_list
389 %type <scm> closed_music
391 %type <scm> music_bare
392 %type <scm> music_arg
393 %type <scm> complex_music
394 %type <scm> complex_music_prefix
395 %type <scm> mode_changed_music
396 %type <scm> repeated_music
397 %type <scm> sequential_music
398 %type <scm> simple_music
399 %type <scm> simultaneous_music
400 %type <scm> chord_body
401 %type <scm> chord_body_element
402 %type <scm> command_element
403 %type <scm> command_event
404 %type <scm> context_modification
405 %type <scm> context_change
406 %type <scm> direction_less_event
407 %type <scm> direction_reqd_event
408 %type <scm> embedded_lilypond
409 %type <scm> event_chord
410 %type <scm> fingering
411 %type <scm> gen_text_def
412 %type <scm> music_property_def
413 %type <scm> note_chord_element
414 %type <scm> post_event
415 %type <scm> post_event_nofinger
416 %type <scm> re_rhythmed_music
417 %type <scm> simple_element
418 %type <scm> simple_music_property_def
419 %type <scm> start_symbol
420 %type <scm> string_number_event
421 %type <scm> tempo_event
423 %type <outputdef> output_def_body
424 %type <outputdef> output_def_head
425 %type <outputdef> output_def_head_with_mode_switch
426 %type <outputdef> output_def
427 %type <outputdef> paper_block
429 %type <scm> music_function_call
430 %type <scm> music_list
431 %type <scm> assignment_id
432 %type <scm> bare_number
433 %type <scm> bare_number_closed
434 %type <scm> unsigned_number
435 %type <scm> bass_figure
436 %type <scm> figured_bass_modification
437 %type <scm> br_bass_figure
438 %type <scm> bass_number
439 %type <scm> chord_body_elements
440 %type <scm> chord_item
441 %type <scm> chord_items
442 %type <scm> chord_separator
443 %type <scm> context_def_mod
444 %type <scm> context_def_spec_block
445 %type <scm> context_def_spec_body
446 %type <scm> context_mod
447 %type <scm> context_mod_list
448 %type <scm> context_prop_spec
449 %type <scm> direction_less_char
450 %type <scm> duration_length
451 %type <scm> embedded_scm
452 %type <scm> embedded_scm_arg
453 %type <scm> embedded_scm_arg_closed
454 %type <scm> embedded_scm_bare
455 %type <scm> embedded_scm_bare_arg
456 %type <scm> embedded_scm_closed
457 %type <scm> embedded_scm_chord_body
458 %type <scm> event_function_event
459 %type <scm> figure_list
460 %type <scm> figure_spec
462 %type <scm> full_markup
463 %type <scm> full_markup_list
464 %type <scm> function_arglist
465 %type <scm> function_arglist_optional
466 %type <scm> function_arglist_backup
467 %type <scm> function_arglist_nonbackup
468 %type <scm> function_arglist_skip
469 %type <scm> function_arglist_bare
470 %type <scm> function_arglist_closed
471 %type <scm> function_arglist_closed_optional
472 %type <scm> function_arglist_common
473 %type <scm> function_arglist_common_lyric
474 %type <scm> function_arglist_common_minus
475 %type <scm> function_arglist_closed_common
476 %type <scm> function_arglist_keep
477 %type <scm> function_arglist_closed_keep
478 %type <scm> identifier_init
480 %type <scm> lilypond_header
481 %type <scm> lilypond_header_body
482 %type <scm> lyric_element
483 %type <scm> lyric_element_arg
484 %type <scm> lyric_element_music
485 %type <scm> lyric_markup
487 %type <scm> markup_braced_list
488 %type <scm> markup_braced_list_body
489 %type <scm> markup_composed_list
490 %type <scm> markup_command_list
491 %type <scm> markup_command_list_arguments
492 %type <scm> markup_command_basic_arguments
493 %type <scm> markup_head_1_item
494 %type <scm> markup_head_1_list
495 %type <scm> markup_list
496 %type <scm> markup_top
497 %type <scm> mode_changing_head
498 %type <scm> mode_changing_head_with_context
499 %type <scm> multiplied_duration
500 %type <scm> music_function_event
501 %type <scm> music_function_chord_body
502 %type <scm> music_function_chord_body_arglist
503 %type <scm> new_chord
504 %type <scm> new_lyrics
505 %type <scm> number_expression
506 %type <scm> number_factor
507 %type <scm> number_term
508 %type <scm> octave_check
509 %type <scm> optional_context_mod
510 %type <scm> optional_id
511 %type <scm> optional_notemode_duration
513 %type <scm> pitch_also_in_chords
514 %type <scm> post_events
515 %type <scm> property_operation
516 %type <scm> property_path property_path_revved
518 %type <scm> scalar_closed
519 %type <scm> scm_function_call
520 %type <scm> scm_function_call_closed
521 %type <scm> script_abbreviation
522 %type <scm> simple_chord_elements
523 %type <scm> simple_markup
524 %type <scm> simple_string
525 %type <scm> steno_duration
526 %type <scm> steno_pitch
527 %type <scm> steno_tonic_pitch
528 %type <scm> step_number
529 %type <scm> step_numbers
531 %type <scm> tempo_range
533 %type <score> score_block
534 %type <score> score_body
539 /* We don't assign precedence to / and *, because we might need varied
540 prec levels in different prods */
549 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
550 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
551 } embedded_lilypond {
552 PARSER->lexer_->pop_state ();
553 PARSER->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
557 lilypond: /* empty */ { }
558 | lilypond toplevel_expression {
560 | lilypond assignment {
563 PARSER->error_level_ = 1;
566 PARSER->error_level_ = 1;
573 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
577 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
578 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
583 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
584 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
585 bookpart->unprotect ();
590 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
591 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
595 Music *music = unsmob_music ($1);
596 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
597 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
600 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
601 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
604 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
605 scm_call_2 (proc, PARSER->self_scm (), $1);
609 Output_def * od = $1;
611 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
612 id = ly_symbol2scm ("$defaultpaper");
613 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
614 id = ly_symbol2scm ("$defaultmidi");
615 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
616 id = ly_symbol2scm ("$defaultlayout");
618 PARSER->lexer_->set_identifier (id, od->self_scm ());
626 $$ = PARSER->lexer_->eval_scm ($1);
631 embedded_scm_bare_arg:
637 | context_modification
640 $$ = $1->self_scm ();
643 | context_def_spec_block
646 $$ = $1->self_scm ();
651 $$ = $1->self_scm ();
656 $$ = $1->self_scm ();
661 /* The generic version may end in music, or not */
669 embedded_scm_bare_arg
675 SCM_FUNCTION function_arglist {
676 $$ = MAKE_SYNTAX ("music-function", @$,
684 $$ = MAKE_SYNTAX ("void-music", @$);
687 | music music music_list {
688 $$ = MAKE_SYNTAX ("sequential-music", @$,
689 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
692 PARSER->error_level_ = 1;
694 | INVALID embedded_lilypond {
695 PARSER->error_level_ = 1;
700 lilypond_header_body:
702 $$ = get_header (PARSER);
703 PARSER->lexer_->add_scope ($$);
705 | lilypond_header_body assignment {
711 HEADER '{' lilypond_header_body '}' {
712 $$ = PARSER->lexer_->remove_scope ();
721 | LYRICS_STRING { $$ = $1; }
725 assignment_id '=' identifier_init {
726 PARSER->lexer_->set_identifier ($1, $3);
728 | assignment_id property_path '=' identifier_init {
729 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
730 PARSER->lexer_->set_identifier (path, $4);
733 TODO: devise standard for protection in parser.
735 The parser stack lives on the C-stack, which means that
736 all objects can be unprotected as soon as they're here.
746 $$ = $1->self_scm ();
750 $$ = $1->self_scm ();
754 $$ = $1->self_scm ();
758 $$ = $1->self_scm ();
761 | context_def_spec_block {
765 /* Hack: Create event-chord around standalone events.
766 Prevents the identifier from being interpreted as a post-event. */
767 Music *mus = unsmob_music ($1);
768 bool is_event = mus &&
769 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
774 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
776 | post_event_nofinger {
779 | number_expression {
794 | context_modification {
799 context_def_spec_block:
800 CONTEXT '{' context_def_spec_body '}'
806 context_def_spec_body:
808 $$ = Context_def::make_scm ();
809 unsmob_context_def ($$)->origin ()->set_spot (@$);
811 | CONTEXT_DEF_IDENTIFIER {
813 unsmob_context_def ($$)->origin ()->set_spot (@$);
815 | context_def_spec_body embedded_scm {
816 if (Context_mod *cm = unsmob_context_mod ($2)) {
817 SCM p = cm->get_mods ();
818 Context_def*td = unsmob_context_def ($$);
820 for (; scm_is_pair (p); p = scm_cdr (p)) {
821 td->add_context_mod (scm_car (p));
824 PARSER->parser_error (@2, "context-mod expected");
827 | context_def_spec_body context_mod {
828 unsmob_context_def ($$)->add_context_mod ($2);
830 | context_def_spec_body context_modification {
831 Context_def *td = unsmob_context_def ($$);
832 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
833 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
834 td->add_context_mod (scm_car (m));
842 BOOK '{' book_body '}' {
845 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
850 * Use 'handlers' like for toplevel-* stuff?
851 * grok \layout and \midi? */
855 init_papers (PARSER);
856 $$->origin ()->set_spot (@$);
857 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
858 $$->paper_->unprotect ();
859 push_paper (PARSER, $$->paper_);
860 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
861 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
862 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
863 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
866 $$ = unsmob_book ($1);
868 $$->origin ()->set_spot (@$);
869 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
871 | book_body paper_block {
874 set_paper (PARSER, $2);
876 | book_body bookpart_block {
878 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
879 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
880 bookpart->unprotect ();
882 | book_body score_block {
884 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
885 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
888 | book_body composite_music {
889 Music *music = unsmob_music ($2);
890 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
891 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
893 | book_body full_markup {
894 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
895 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
897 | book_body full_markup_list {
898 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
899 scm_call_2 (proc, $$->self_scm (), $2);
901 | book_body lilypond_header {
904 | book_body embedded_scm { }
907 $$->scores_ = SCM_EOL;
908 $$->bookparts_ = SCM_EOL;
913 BOOKPART '{' bookpart_body '}' {
915 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
922 $$->origin ()->set_spot (@$);
923 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
926 $$ = unsmob_book ($1);
928 $$->origin ()->set_spot (@$);
929 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
931 | bookpart_body paper_block {
935 | bookpart_body score_block {
937 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
938 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
941 | bookpart_body composite_music {
942 Music *music = unsmob_music ($2);
943 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
944 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
946 | bookpart_body full_markup {
947 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
948 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
950 | bookpart_body full_markup_list {
951 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
952 scm_call_2 (proc, $$->self_scm (), $2);
954 | bookpart_body lilypond_header {
957 | bookpart_body embedded_scm { }
958 | bookpart_body error {
960 $$->scores_ = SCM_EOL;
965 SCORE '{' score_body '}' {
973 SCM scorify = ly_lily_module_constant ("scorify-music");
974 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
976 // pass ownernship to C++ again.
977 $$ = unsmob_score (score);
979 $$->origin ()->set_spot (@$);
982 $$ = unsmob_score ($1);
984 $$->origin ()->set_spot (@$);
986 | score_body lilypond_header {
989 | score_body output_def {
990 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
992 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
997 $$->add_output_def ($2);
1001 | score_body error {
1002 $$->error_found_ = true;
1014 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1016 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
1018 $$ = get_paper (PARSER);
1025 output_def_body '}' {
1028 PARSER->lexer_->remove_scope ();
1029 PARSER->lexer_->pop_state ();
1035 $$ = get_paper (PARSER);
1036 $$->input_origin_ = @$;
1037 PARSER->lexer_->add_scope ($$->scope_);
1040 Output_def *p = get_midi (PARSER);
1042 PARSER->lexer_->add_scope (p->scope_);
1045 Output_def *p = get_layout (PARSER);
1047 PARSER->lexer_->add_scope (p->scope_);
1052 output_def_head_with_mode_switch:
1054 PARSER->lexer_->push_initial_state ();
1060 output_def_head_with_mode_switch '{' {
1062 $$->input_origin_.set_spot (@$);
1064 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1067 Output_def *o = unsmob_output_def ($3);
1068 o->input_origin_.set_spot (@$);
1071 PARSER->lexer_->remove_scope ();
1072 PARSER->lexer_->add_scope (o->scope_);
1074 | output_def_body assignment {
1077 | output_def_body context_def_spec_block {
1078 assign_context_def ($$, $2);
1080 | output_def_body error {
1086 TEMPO steno_duration '=' tempo_range {
1087 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1089 | TEMPO scalar_closed steno_duration '=' tempo_range {
1090 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1093 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1098 The representation of a list is reversed to have efficient append. */
1104 | music_list music {
1105 $$ = scm_cons ($2, $1);
1107 | music_list embedded_scm {
1110 | music_list error {
1111 Music *m = MY_MAKE_MUSIC("Music", @$);
1113 m->set_property ("error-found", SCM_BOOL_T);
1114 $$ = scm_cons (m->self_scm (), $1);
1115 m->unprotect (); /* UGH */
1122 $$ = scm_reverse_x ($2, SCM_EOL);
1127 | lyric_element_music
1128 | composite_music %prec COMPOSITE
1133 | composite_music %prec COMPOSITE
1137 REPEAT simple_string unsigned_number music
1139 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1141 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1143 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1148 SEQUENTIAL braced_music_list {
1149 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1151 | braced_music_list {
1152 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1157 SIMULTANEOUS braced_music_list {
1158 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1160 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1161 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1167 | music_property_def
1171 context_modification:
1172 WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1174 PARSER->lexer_->pop_state ();
1177 | WITH CONTEXT_MOD_IDENTIFIER
1181 | CONTEXT_MOD_IDENTIFIER
1185 | WITH embedded_scm_closed
1187 if (unsmob_context_mod ($2))
1190 PARSER->parser_error (@2, "context-mod expected");
1191 $$ = Context_mod ().smobbed_copy ();
1196 optional_context_mod:
1200 | context_modification
1208 $$ = Context_mod ().smobbed_copy ();
1210 | context_mod_list context_mod {
1211 unsmob_context_mod ($1)->add_context_mod ($2);
1213 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1214 Context_mod *md = unsmob_context_mod ($2);
1216 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1225 /* Music that can be parsed without lookahead */
1228 | complex_music_prefix closed_music
1230 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1237 | grouped_music_list
1241 simultaneous_music { $$ = $1; }
1242 | sequential_music { $$ = $1; }
1245 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1246 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1247 and this rule returns the reversed list of arguments. */
1249 function_arglist_skip:
1250 function_arglist_common
1251 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1253 $$ = scm_cons ($1, $3);
1254 } %prec FUNCTION_ARGLIST
1255 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1257 $$ = scm_cons ($1, $3);
1258 } %prec FUNCTION_ARGLIST
1259 | EXPECT_SCM EXPECT_DURATION function_arglist_skip
1261 $$ = scm_cons ($1, $3);
1262 } %prec FUNCTION_ARGLIST
1266 function_arglist_nonbackup:
1267 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1268 $$ = scm_cons ($4, $3);
1270 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1271 $$ = scm_cons ($4, $3);
1273 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1275 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1277 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1279 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1281 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1283 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1285 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1287 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1289 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1291 SCM n = scm_difference ($5, SCM_UNDEFINED);
1292 if (scm_is_true (scm_call_1 ($2, n)))
1293 $$ = scm_cons (n, $3);
1295 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1296 t->set_property ("digit", $5);
1297 $$ = t->unprotect ();
1298 if (scm_is_true (scm_call_1 ($2, $$)))
1299 $$ = scm_cons ($$, $3);
1301 $$ = check_scheme_arg (PARSER, @4, n, $3, $2);
1305 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1307 $$ = check_scheme_arg (PARSER, @4,
1308 scm_difference ($5, SCM_UNDEFINED),
1311 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1313 $$ = check_scheme_arg (PARSER, @4,
1314 scm_difference ($5, SCM_UNDEFINED),
1320 function_arglist_keep:
1321 function_arglist_common
1322 | function_arglist_backup
1325 function_arglist_closed_keep:
1326 function_arglist_closed_common
1327 | function_arglist_backup
1330 function_arglist_backup:
1331 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1333 if (scm_is_true (scm_call_1 ($2, $4)))
1335 $$ = scm_cons ($4, $3);
1337 $$ = scm_cons (loc_on_music (@3, $1), $3);
1338 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1341 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1343 if (scm_is_true (scm_call_1 ($2, $4)))
1345 $$ = scm_cons ($4, $3);
1347 $$ = scm_cons (loc_on_music (@3, $1), $3);
1348 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1351 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1353 // There is no point interpreting a lyrics string as
1354 // an event, since we don't allow music possibly
1355 // followed by durations or postevent into closed
1356 // music, and we only accept closed music in optional
1357 // arguments at the moment. If this changes, more
1358 // complex schemes might become interesting here as
1359 // well: see how we do this at the mandatory argument
1361 if (scm_is_true (scm_call_1 ($2, $4)))
1362 $$ = scm_cons ($3, $2);
1364 $$ = scm_cons (loc_on_music (@3, $1), $3);
1365 MYBACKUP (LYRIC_MARKUP_IDENTIFIER, $4, @4);
1368 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1370 if (scm_is_true (scm_call_1 ($2, $4)))
1373 MYREPARSE (@4, $2, UNSIGNED, $4);
1375 $$ = scm_cons (loc_on_music (@3, $1), $3);
1376 MYBACKUP (UNSIGNED, $4, @4);
1379 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1381 if (scm_is_true (scm_call_1 ($2, $4)))
1384 MYREPARSE (@4, $2, REAL, $4);
1386 $$ = scm_cons (loc_on_music (@3, $1), $3);
1387 MYBACKUP (REAL, $4, @4);
1390 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1392 if (scm_is_true (scm_call_1 ($2, $4)))
1394 $$ = scm_cons ($4, $3);
1396 $$ = scm_cons (loc_on_music (@3, $1), $3);
1397 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1400 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1402 if (scm_is_true (scm_call_1 ($2, $4)))
1404 $$ = scm_cons ($4, $3);
1406 $$ = scm_cons (loc_on_music (@3, $1), $3);
1407 MYBACKUP (FRACTION, $4, @4);
1410 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1412 SCM n = scm_difference ($5, SCM_UNDEFINED);
1413 if (scm_is_true (scm_call_1 ($2, n))) {
1415 MYREPARSE (@5, $2, REAL, n);
1417 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1418 t->set_property ("digit", $5);
1419 $$ = t->unprotect ();
1420 if (scm_is_true (scm_call_1 ($2, $$)))
1421 $$ = scm_cons ($$, $3);
1423 $$ = scm_cons (loc_on_music (@3, $1), $3);
1424 MYBACKUP (UNSIGNED, $5, @5);
1425 PARSER->lexer_->push_extra_token ('-');
1430 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1432 SCM n = scm_difference ($5, SCM_UNDEFINED);
1433 if (scm_is_true (scm_call_1 ($2, n))) {
1434 MYREPARSE (@5, $2, REAL, n);
1437 MYBACKUP (REAL, n, @5);
1440 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1442 SCM n = scm_difference ($5, SCM_UNDEFINED);
1443 if (scm_is_true (scm_call_1 ($2, n))) {
1444 $$ = scm_cons (n, $3);
1446 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1449 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1451 $$ = scm_cons ($4, $3);
1453 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1455 $$ = scm_cons ($4, $3);
1457 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1459 $$ = scm_cons ($1, $3);
1460 MYBACKUP(0, SCM_UNDEFINED, @3);
1462 | function_arglist_backup REPARSE embedded_scm_arg_closed
1464 $$ = check_scheme_arg (PARSER, @3,
1467 | function_arglist_backup REPARSE bare_number
1469 $$ = check_scheme_arg (PARSER, @3,
1472 | function_arglist_backup REPARSE fraction
1474 $$ = check_scheme_arg (PARSER, @3,
1480 function_arglist_common
1481 | function_arglist_nonbackup
1484 function_arglist_common:
1485 function_arglist_bare
1486 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1488 $$ = check_scheme_arg (PARSER, @3,
1491 | EXPECT_SCM function_arglist_closed_optional bare_number
1493 $$ = check_scheme_arg (PARSER, @3,
1496 | EXPECT_SCM function_arglist_closed_optional fraction
1498 $$ = check_scheme_arg (PARSER, @3,
1501 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1503 $$ = check_scheme_arg (PARSER, @3,
1506 | function_arglist_common_minus
1507 | function_arglist_common_lyric
1510 function_arglist_common_lyric:
1511 EXPECT_SCM function_arglist_optional lyric_element
1513 // We check how the predicate thinks about a lyrics
1514 // event or about a markup. If it accepts neither, we
1515 // backup the original token. Otherwise we commit to
1516 // taking the token. Depending on what the predicate
1517 // is willing to accept, we interpret as a string, as
1518 // a lyric event, or ambiguously (meaning that if
1519 // something looking like a duration or post event
1520 // follows, we take the event, otherwise the string).
1521 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1522 PARSER->default_duration_.smobbed_copy ());
1523 if (scm_is_true (scm_call_1 ($1, $3)))
1524 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1527 MYREPARSE (@3, $1, LYRIC_ELEMENT_P, $3);
1529 $$ = scm_cons ($3, $2);
1531 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1534 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1536 // This is going to flag a syntax error, we
1537 // know the predicate to be false.
1538 check_scheme_arg (PARSER, @3,
1542 | function_arglist_common_lyric REPARSE lyric_element_arg
1544 // This should never be false
1545 $$ = check_scheme_arg (PARSER, @3,
1550 function_arglist_common_minus:
1551 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1553 SCM n = scm_difference ($4, SCM_UNDEFINED);
1554 if (scm_is_true (scm_call_1 ($1, n))) {
1556 MYREPARSE (@4, $1, REAL, n);
1558 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1559 t->set_property ("digit", $4);
1560 $$ = t->unprotect ();
1561 if (scm_is_true (scm_call_1 ($1, $$)))
1562 $$ = scm_cons ($$, $2);
1564 $$ = check_scheme_arg (PARSER, @3, n, $2, $1);
1568 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1571 SCM n = scm_difference ($4, SCM_UNDEFINED);
1572 MYREPARSE (@4, $1, REAL, n);
1574 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1576 SCM n = scm_difference ($4, SCM_UNDEFINED);
1577 $$ = check_scheme_arg (PARSER, @4, n, $2, $1);
1579 | function_arglist_common_minus REPARSE bare_number
1581 $$ = check_scheme_arg (PARSER, @3, $3, $1, $2);
1585 function_arglist_closed:
1586 function_arglist_closed_common
1587 | function_arglist_nonbackup
1590 function_arglist_closed_common:
1591 function_arglist_bare
1592 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1594 $$ = check_scheme_arg (PARSER, @3,
1597 | EXPECT_SCM function_arglist_closed_optional bare_number
1599 $$ = check_scheme_arg (PARSER, @3,
1602 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1604 SCM n = scm_difference ($4, SCM_UNDEFINED);
1605 if (scm_is_true (scm_call_1 ($1, n))) {
1606 $$ = scm_cons (n, $2);
1608 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1609 t->set_property ("digit", $4);
1610 $$ = t->unprotect ();
1611 if (scm_is_true (scm_call_1 ($1, $$)))
1612 $$ = scm_cons ($$, $2);
1614 $$ = check_scheme_arg (PARSER, @3, n, $2, $1);
1618 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1620 $$ = check_scheme_arg (PARSER, @3,
1621 scm_difference ($4, SCM_UNDEFINED),
1624 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1626 $$ = check_scheme_arg (PARSER, @3,
1627 scm_difference ($4, SCM_UNDEFINED),
1630 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1632 $$ = check_scheme_arg (PARSER, @3,
1635 | EXPECT_SCM function_arglist_closed_optional fraction
1637 $$ = check_scheme_arg (PARSER, @3,
1640 | EXPECT_SCM function_arglist_optional lyric_element
1642 $$ = check_scheme_arg (PARSER, @3,
1647 function_arglist_optional:
1648 function_arglist_keep %prec FUNCTION_ARGLIST
1649 | function_arglist_backup BACKUP
1650 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1652 $$ = scm_cons ($1, $3);
1654 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1656 $$ = scm_cons ($1, $3);
1660 function_arglist_closed_optional:
1661 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1662 | function_arglist_backup BACKUP
1663 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1665 $$ = scm_cons ($1, $3);
1667 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1669 $$ = scm_cons ($1, $3);
1673 embedded_scm_closed:
1675 | scm_function_call_closed
1678 embedded_scm_arg_closed:
1679 embedded_scm_bare_arg
1680 | scm_function_call_closed
1684 scm_function_call_closed:
1685 SCM_FUNCTION function_arglist_closed {
1686 $$ = MAKE_SYNTAX ("music-function", @$,
1688 } %prec FUNCTION_ARGLIST
1691 function_arglist_bare:
1692 EXPECT_NO_MORE_ARGS {
1695 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1696 $$ = scm_cons ($3, $2);
1698 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1699 $$ = scm_cons ($3, $2);
1701 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1702 $$ = scm_cons ($1, $3);
1704 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1705 $$ = scm_cons ($1, $3);
1707 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1708 $$ = scm_cons ($1, $3);
1712 music_function_call:
1713 MUSIC_FUNCTION function_arglist {
1714 $$ = MAKE_SYNTAX ("music-function", @$,
1721 /**/ { $$ = SCM_EOL; }
1722 | '=' simple_string {
1729 | repeated_music { $$ = $1; }
1730 | re_rhythmed_music { $$ = $1; }
1731 | complex_music_prefix music
1733 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1737 complex_music_prefix:
1738 CONTEXT simple_string optional_id optional_context_mod {
1739 Context_mod *ctxmod = unsmob_context_mod ($4);
1742 mods = ctxmod->get_mods ();
1743 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1745 | NEWCONTEXT simple_string optional_id optional_context_mod {
1746 Context_mod *ctxmod = unsmob_context_mod ($4);
1749 mods = ctxmod->get_mods ();
1750 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1755 mode_changing_head grouped_music_list {
1756 if ($1 == ly_symbol2scm ("chords"))
1758 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1764 PARSER->lexer_->pop_state ();
1766 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1767 Context_mod *ctxmod = unsmob_context_mod ($2);
1770 mods = ctxmod->get_mods ();
1771 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1772 if ($1 == ly_symbol2scm ("ChordNames"))
1774 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1776 PARSER->lexer_->pop_state ();
1782 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1783 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1785 $$ = ly_symbol2scm ("notes");
1789 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1790 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1792 $$ = ly_symbol2scm ("drums");
1795 PARSER->lexer_->push_figuredbass_state ();
1797 $$ = ly_symbol2scm ("figures");
1800 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1801 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1802 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1803 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1804 $$ = ly_symbol2scm ("chords");
1808 { PARSER->lexer_->push_lyric_state ();
1809 $$ = ly_symbol2scm ("lyrics");
1813 mode_changing_head_with_context:
1815 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1816 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1818 $$ = ly_symbol2scm ("DrumStaff");
1821 PARSER->lexer_->push_figuredbass_state ();
1823 $$ = ly_symbol2scm ("FiguredBass");
1826 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1827 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1828 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1829 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1830 $$ = ly_symbol2scm ("ChordNames");
1833 { PARSER->lexer_->push_lyric_state ();
1834 $$ = ly_symbol2scm ("Lyrics");
1839 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1842 /* Can also use music at the expensive of two S/Rs similar to
1843 \repeat \alternative */
1844 PARSER->lexer_->pop_state ();
1846 $$ = scm_cons ($3, SCM_EOL);
1848 | new_lyrics ADDLYRICS {
1849 PARSER->lexer_->push_lyric_state ();
1851 PARSER->lexer_->pop_state ();
1852 $$ = scm_cons ($4, $1);
1857 composite_music new_lyrics {
1858 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1860 | LYRICSTO simple_string {
1861 PARSER->lexer_->push_lyric_state ();
1863 PARSER->lexer_->pop_state ();
1864 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1869 CHANGE STRING '=' STRING {
1870 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1875 property_path_revved:
1876 embedded_scm_closed {
1877 $$ = scm_cons ($1, SCM_EOL);
1879 | property_path_revved embedded_scm_closed {
1880 $$ = scm_cons ($2, $1);
1885 property_path_revved {
1886 $$ = scm_reverse_x ($1, SCM_EOL);
1892 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1893 scm_string_to_symbol ($1), $3);
1895 | UNSET simple_string {
1896 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1897 scm_string_to_symbol ($2));
1899 | OVERRIDE simple_string property_path '=' scalar {
1900 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1901 scm_string_to_symbol ($2), $5),
1904 | REVERT simple_string embedded_scm {
1905 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1906 scm_string_to_symbol ($2), $3);
1911 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1912 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1914 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1915 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1916 | DENIES { $$ = ly_symbol2scm ("denies"); }
1918 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1919 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1920 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1921 | NAME { $$ = ly_symbol2scm ("context-name"); }
1925 property_operation { $$ = $1; }
1926 | context_def_mod STRING {
1927 $$ = scm_list_2 ($1, $2);
1929 | context_def_mod embedded_scm {
1930 if (ly_symbol2scm ("consists") != $1)
1933 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1937 $$ = scm_list_2 ($1, $2);
1944 if (!is_regular_identifier ($1))
1946 @$.error (_("Grob name should be alphanumeric"));
1949 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1950 scm_string_to_symbol ($1));
1952 | simple_string '.' simple_string {
1953 $$ = scm_list_2 (scm_string_to_symbol ($1),
1954 scm_string_to_symbol ($3));
1958 simple_music_property_def:
1959 OVERRIDE context_prop_spec property_path '=' scalar {
1960 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1961 ly_symbol2scm ("OverrideProperty"),
1966 | REVERT context_prop_spec embedded_scm {
1967 $$ = scm_list_4 (scm_car ($2),
1968 ly_symbol2scm ("RevertProperty"),
1972 | SET context_prop_spec '=' scalar {
1973 $$ = scm_list_4 (scm_car ($2),
1974 ly_symbol2scm ("PropertySet"),
1978 | UNSET context_prop_spec {
1979 $$ = scm_list_3 (scm_car ($2),
1980 ly_symbol2scm ("PropertyUnset"),
1986 simple_music_property_def {
1987 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (PARSER->self_scm (), make_input (@$), $1));
1995 | STRING_IDENTIFIER {
1998 | string '+' string {
1999 $$ = scm_string_append (scm_list_2 ($1, $3));
2003 simple_string: STRING {
2009 | STRING_IDENTIFIER {
2021 embedded_scm_arg_closed
2028 /* TODO: Create a special case that avoids the creation of
2029 EventChords around simple_elements that have no post_events?
2031 simple_chord_elements post_events {
2032 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2035 /* why is this giving wrong start location? -ns
2037 i.set_location (@1, @2);
2038 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2040 | CHORD_REPETITION optional_notemode_duration post_events {
2042 i.set_location (@1, @3);
2043 $$ = MAKE_SYNTAX ("repetition-chord", i,
2044 PARSER->lexer_->chord_repetition_.last_chord_,
2045 PARSER->lexer_->chord_repetition_.repetition_function_,
2046 $2, scm_reverse_x ($3, SCM_EOL));
2048 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2050 i.set_location (@1, @3);
2051 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2052 scm_reverse_x ($3, SCM_EOL));
2055 /* note chord elements are memorized into
2056 PARSER->lexer_->chord_repetition_ so that the chord repetition
2057 mechanism copy them when a chord repetition symbol is found
2059 | note_chord_element {
2060 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
2066 chord_body optional_notemode_duration post_events
2068 Music *m = unsmob_music ($1);
2069 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2070 SCM es = m->get_property ("elements");
2071 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2073 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2074 unsmob_music (scm_car (s))->set_property ("duration", dur);
2075 es = ly_append2 (es, postevs);
2077 m-> set_property ("elements", es);
2079 $$ = m->self_scm ();
2084 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2086 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2090 chord_body_elements:
2091 /* empty */ { $$ = SCM_EOL; }
2092 | chord_body_elements chord_body_element {
2093 $$ = scm_cons ($2, $1);
2098 pitch exclamations questions octave_check post_events
2105 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2106 n->set_property ("pitch", $1);
2108 n->set_property ("cautionary", SCM_BOOL_T);
2109 if (ex % 2 || q % 2)
2110 n->set_property ("force-accidental", SCM_BOOL_T);
2112 if (scm_is_pair (post)) {
2113 SCM arts = scm_reverse_x (post, SCM_EOL);
2114 n->set_property ("articulations", arts);
2116 if (scm_is_number (check))
2118 int q = scm_to_int (check);
2119 n->set_property ("absolute-octave", scm_from_int (q-1));
2122 $$ = n->unprotect ();
2124 | DRUM_PITCH post_events {
2125 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2126 n->set_property ("drum-type", $1);
2128 if (scm_is_pair ($2)) {
2129 SCM arts = scm_reverse_x ($2, SCM_EOL);
2130 n->set_property ("articulations", arts);
2132 $$ = n->unprotect ();
2134 | music_function_chord_body
2137 /* We can't accept a music argument, not even a closed one,
2138 * immediately before chord_body_elements, otherwise a function \fun
2139 * with a signature of two music arguments can't be sorted out
2140 * properly in a construct like
2141 * <\fun { c } \fun { c } c>
2142 * The second call could be interpreted either as a chord constituent
2143 * or a music expression.
2146 music_function_chord_body_arglist:
2147 function_arglist_bare
2148 | EXPECT_SCM music_function_chord_body_arglist embedded_scm_chord_body
2150 $$ = check_scheme_arg (PARSER, @3,
2155 embedded_scm_chord_body:
2156 embedded_scm_bare_arg
2157 | SCM_FUNCTION music_function_chord_body_arglist {
2158 $$ = MAKE_SYNTAX ("music-function", @$,
2164 | chord_body_element
2167 music_function_chord_body:
2168 MUSIC_FUNCTION music_function_chord_body_arglist {
2169 $$ = MAKE_SYNTAX ("music-function", @$,
2174 // Event functions may only take closed arglists, otherwise it would
2175 // not be clear whether a following postevent should be associated
2176 // with the last argument of the event function or with the expression
2177 // for which the function call acts itself as event.
2179 music_function_event:
2180 MUSIC_FUNCTION function_arglist_closed {
2181 $$ = MAKE_SYNTAX ("music-function", @$,
2186 event_function_event:
2187 EVENT_FUNCTION function_arglist_closed {
2188 $$ = MAKE_SYNTAX ("music-function", @$,
2198 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2199 m->set_property ("span-direction", scm_from_int (START));
2200 $$ = m->unprotect();
2203 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2204 m->set_property ("span-direction", scm_from_int (STOP));
2205 $$ = m->unprotect ();
2208 $$ = MAKE_SYNTAX ("voice-separator", @$);
2211 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
2213 Music *m = unsmob_music (pipe);
2218 $$ = m->unprotect ();
2221 $$ = MAKE_SYNTAX ("bar-check", @$);
2228 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2240 | post_events post_event {
2241 unsmob_music ($2)->set_spot (@2);
2242 $$ = scm_cons ($2, $$);
2246 post_event_nofinger:
2247 direction_less_event {
2250 | script_dir music_function_event {
2254 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2258 if (!PARSER->lexer_->is_lyric_state ())
2259 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2260 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2263 if (!PARSER->lexer_->is_lyric_state ())
2264 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2265 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2267 | script_dir direction_reqd_event {
2270 Music *m = unsmob_music ($2);
2271 m->set_property ("direction", scm_from_int ($1));
2275 | script_dir direction_less_event {
2278 Music *m = unsmob_music ($2);
2279 m->set_property ("direction", scm_from_int ($1));
2283 | string_number_event
2287 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2292 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2303 string_number_event:
2305 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2306 s->set_property ("string-number", scm_from_int ($1));
2307 $$ = s->unprotect ();
2311 direction_less_char:
2313 $$ = ly_symbol2scm ("bracketOpenSymbol");
2316 $$ = ly_symbol2scm ("bracketCloseSymbol");
2319 $$ = ly_symbol2scm ("tildeSymbol");
2322 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2325 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2328 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2331 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2334 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2337 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2340 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2344 direction_less_event:
2345 direction_less_char {
2346 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
2348 if (unsmob_music (predefd))
2350 m = unsmob_music (predefd)->clone ();
2355 m = MY_MAKE_MUSIC ("Music", @$);
2357 $$ = m->unprotect ();
2359 | EVENT_IDENTIFIER {
2363 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2364 a->set_property ("tremolo-type", scm_from_int ($1));
2365 $$ = a->unprotect ();
2367 | event_function_event
2370 direction_reqd_event:
2374 | script_abbreviation {
2375 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2376 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2377 if (scm_is_string (s))
2378 a->set_property ("articulation-type", s);
2379 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
2380 $$ = a->unprotect ();
2385 /**/ { $$ = SCM_EOL; }
2386 | '=' { $$ = scm_from_int (0); }
2387 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2388 | '=' sup_quotes { $$ = scm_from_int ($2); }
2413 | NOTENAME_PITCH sup_quotes {
2414 Pitch p = *unsmob_pitch ($1);
2415 p = p.transposed (Pitch ($2,0,0));
2416 $$ = p.smobbed_copy ();
2418 | NOTENAME_PITCH sub_quotes {
2419 Pitch p =* unsmob_pitch ($1);
2420 p = p.transposed (Pitch (-$2,0,0));
2421 $$ = p.smobbed_copy ();
2433 | TONICNAME_PITCH sup_quotes {
2434 Pitch p = *unsmob_pitch ($1);
2435 p = p.transposed (Pitch ($2,0,0));
2436 $$ = p.smobbed_copy ();
2438 | TONICNAME_PITCH sub_quotes {
2439 Pitch p = *unsmob_pitch ($1);
2441 p = p.transposed (Pitch (-$2,0,0));
2442 $$ = p.smobbed_copy ();
2453 pitch_also_in_chords:
2460 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2461 t->set_property ("text", $1);
2462 $$ = t->unprotect ();
2465 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2466 t->set_property ("text",
2467 make_simple_markup ($1));
2468 $$ = t->unprotect ();
2474 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2475 t->set_property ("digit", $1);
2476 $$ = t->unprotect ();
2480 script_abbreviation:
2482 $$ = scm_from_locale_string ("Hat");
2485 $$ = scm_from_locale_string ("Plus");
2488 $$ = scm_from_locale_string ("Dash");
2491 $$ = scm_from_locale_string ("Bar");
2494 $$ = scm_from_locale_string ("Larger");
2497 $$ = scm_from_locale_string ("Dot");
2500 $$ = scm_from_locale_string ("Underscore");
2507 | '-' { $$ = CENTER; }
2511 multiplied_duration {
2516 optional_notemode_duration:
2518 Duration dd = PARSER->default_duration_;
2519 $$ = dd.smobbed_copy ();
2521 | multiplied_duration {
2523 PARSER->default_duration_ = *unsmob_duration ($$);
2528 bare_unsigned dots {
2530 if (!is_duration ($1))
2531 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
2535 $$ = Duration (len, $2).smobbed_copy ();
2537 | DURATION_IDENTIFIER dots {
2538 Duration *d = unsmob_duration ($1);
2539 Duration k (d->duration_log (), d->dot_count () + $2);
2540 k = k.compressed (d->factor ());
2546 multiplied_duration:
2550 | multiplied_duration '*' bare_unsigned {
2551 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2553 | multiplied_duration '*' FRACTION {
2554 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2556 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2561 FRACTION { $$ = $1; }
2562 | UNSIGNED '/' UNSIGNED {
2563 $$ = scm_cons ($1, $3);
2580 | ':' bare_unsigned {
2581 if (!is_duration ($2))
2582 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2588 UNSIGNED { $$ = $1; }
2589 | STRING { $$ = $1; }
2590 | full_markup { $$ = $1; }
2593 figured_bass_alteration:
2594 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2595 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2596 | '!' { $$ = scm_from_int (0); }
2601 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2602 $$ = bfr->unprotect ();
2605 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2606 $$ = bfr->self_scm ();
2608 if (scm_is_number ($1))
2609 bfr->set_property ("figure", $1);
2610 else if (Text_interface::is_markup ($1))
2611 bfr->set_property ("text", $1);
2617 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2619 | bass_figure figured_bass_alteration {
2620 Music *m = unsmob_music ($1);
2621 if (scm_to_double ($2)) {
2622 SCM salter = m->get_property ("alteration");
2623 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2624 m->set_property ("alteration",
2625 scm_sum (alter, $2));
2627 m->set_property ("alteration", scm_from_int (0));
2630 | bass_figure figured_bass_modification {
2631 Music *m = unsmob_music ($1);
2632 if ($2 == ly_symbol2scm ("plus"))
2634 m->set_property ("augmented", SCM_BOOL_T);
2636 else if ($2 == ly_symbol2scm ("slash"))
2638 m->set_property ("diminished", SCM_BOOL_T);
2640 else if ($2 == ly_symbol2scm ("exclamation"))
2642 m->set_property ("no-continuation", SCM_BOOL_T);
2644 else if ($2 == ly_symbol2scm ("backslash"))
2646 m->set_property ("augmented-slash", SCM_BOOL_T);
2652 figured_bass_modification:
2654 $$ = ly_symbol2scm ("plus");
2657 $$ = ly_symbol2scm ("exclamation");
2660 $$ = ly_symbol2scm ("slash");
2663 $$ = ly_symbol2scm ("backslash");
2673 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2681 | figure_list br_bass_figure {
2682 $$ = scm_cons ($2, $1);
2687 FIGURE_OPEN figure_list FIGURE_CLOSE {
2688 $$ = scm_reverse_x ($2, SCM_EOL);
2699 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2700 if (!PARSER->lexer_->is_note_state ())
2701 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2705 n = MY_MAKE_MUSIC ("RestEvent", @$);
2707 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2709 n->set_property ("pitch", $1);
2710 n->set_property ("duration", $5);
2712 if (scm_is_number ($4))
2714 int q = scm_to_int ($4);
2715 n->set_property ("absolute-octave", scm_from_int (q-1));
2719 n->set_property ("cautionary", SCM_BOOL_T);
2720 if ($2 % 2 || $3 % 2)
2721 n->set_property ("force-accidental", SCM_BOOL_T);
2723 $$ = n->unprotect ();
2725 | DRUM_PITCH optional_notemode_duration {
2726 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2727 n->set_property ("duration", $2);
2728 n->set_property ("drum-type", $1);
2730 $$ = n->unprotect ();
2732 | RESTNAME optional_notemode_duration {
2734 if (ly_scm2string ($1) == "s") {
2736 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2739 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2742 ev->set_property ("duration", $2);
2743 $$ = ev->unprotect ();
2747 simple_chord_elements:
2749 $$ = scm_list_1 ($1);
2752 if (!PARSER->lexer_->is_chord_state ())
2753 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2756 | figure_spec optional_notemode_duration {
2757 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2759 unsmob_music (scm_car (s))->set_property ("duration", $2);
2777 | lyric_element multiplied_duration post_events {
2778 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2779 $$ = MAKE_SYNTAX ("event-chord", @$,
2780 scm_cons (lyric_event,
2781 scm_reverse_x ($3, SCM_EOL)));
2783 | lyric_element post_event post_events {
2785 MAKE_SYNTAX ("lyric-event", @$, $1,
2786 PARSER->default_duration_.smobbed_copy ());
2787 $$ = MAKE_SYNTAX ("event-chord", @$,
2788 scm_cons2 (lyric_event, $2,
2789 scm_reverse_x ($3, SCM_EOL)));
2792 | LYRIC_ELEMENT optional_notemode_duration post_events {
2793 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2794 $$ = MAKE_SYNTAX ("event-chord", @$,
2795 scm_cons (lyric_event,
2796 scm_reverse_x ($3, SCM_EOL)));
2801 lyric_element_music:
2802 lyric_element optional_notemode_duration post_events {
2803 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2804 $$ = MAKE_SYNTAX ("event-chord", @$,
2805 scm_cons (lyric_event,
2806 scm_reverse_x ($3, SCM_EOL)));
2811 steno_tonic_pitch optional_notemode_duration {
2812 $$ = make_chord_elements ($1, $2, SCM_EOL);
2814 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2815 SCM its = scm_reverse_x ($4, SCM_EOL);
2816 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2824 | chord_items chord_item {
2825 $$ = scm_cons ($2, $$);
2831 $$ = ly_symbol2scm ("chord-colon");
2834 $$ = ly_symbol2scm ("chord-caret");
2836 | CHORD_SLASH steno_tonic_pitch {
2837 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2839 | CHORD_BASS steno_tonic_pitch {
2840 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2849 $$ = scm_reverse_x ($1, SCM_EOL);
2857 step_number { $$ = scm_cons ($1, SCM_EOL); }
2858 | step_numbers '.' step_number {
2859 $$ = scm_cons ($3, $$);
2865 $$ = make_chord_step ($1, 0);
2867 | bare_unsigned '+' {
2868 $$ = make_chord_step ($1, SHARP_ALTERATION);
2870 | bare_unsigned CHORD_MINUS {
2871 $$ = make_chord_step ($1, FLAT_ALTERATION);
2877 $$ = scm_from_int ($1);
2879 | bare_unsigned '~' bare_unsigned {
2880 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2887 TODO: should deprecate in favor of Scheme?
2891 number_expression '+' number_term {
2892 $$ = scm_sum ($1, $3);
2894 | number_expression '-' number_term {
2895 $$ = scm_difference ($1, $3);
2904 | number_factor '*' number_factor {
2905 $$ = scm_product ($1, $3);
2907 | number_factor '/' number_factor {
2908 $$ = scm_divide ($1, $3);
2913 '-' number_factor { /* %prec UNARY_MINUS */
2914 $$ = scm_difference ($2, SCM_UNDEFINED);
2922 | UNSIGNED NUMBER_IDENTIFIER {
2923 $$ = scm_product ($1, $2)
2925 | REAL NUMBER_IDENTIFIER {
2926 $$ = scm_product ($1, $2)
2938 $$ = scm_to_int ($1);
2949 | exclamations '!' { $$ ++; }
2954 | questions '?' { $$ ++; }
2958 This should be done more dynamically if possible.
2962 LYRIC_MARKUP_IDENTIFIER {
2966 { PARSER->lexer_->push_markup_state (); }
2969 PARSER->lexer_->pop_state ();
2974 MARKUPLIST_IDENTIFIER {
2978 { PARSER->lexer_->push_markup_state (); }
2981 PARSER->lexer_->pop_state ();
2990 { PARSER->lexer_->push_markup_state (); }
2993 PARSER->lexer_->pop_state ();
2999 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3001 | markup_head_1_list simple_markup {
3002 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3012 if (Text_interface::is_markup ($1))
3013 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3014 else if (Text_interface::is_markup_list ($1))
3015 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3017 PARSER->parser_error (@1, _("markup expected"));
3018 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3025 MARKUPLIST_IDENTIFIER {
3028 | markup_composed_list {
3031 | markup_braced_list {
3034 | markup_command_list {
3035 $$ = scm_list_1 ($1);
3037 | markup_scm MARKUPLIST_IDENTIFIER
3043 markup_composed_list:
3044 markup_head_1_list markup_braced_list {
3045 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3051 '{' markup_braced_list_body '}' {
3052 $$ = scm_reverse_x ($2, SCM_EOL);
3056 markup_braced_list_body:
3057 /* empty */ { $$ = SCM_EOL; }
3058 | markup_braced_list_body markup {
3059 $$ = scm_cons ($2, $1);
3061 | markup_braced_list_body markup_list {
3062 $$ = scm_reverse_x ($2, $1);
3066 markup_command_list:
3067 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3068 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3072 markup_command_basic_arguments:
3073 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3074 $$ = scm_cons ($3, $2);
3076 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3077 $$ = check_scheme_arg (PARSER, @3, $3, $2, $1);
3079 | EXPECT_NO_MORE_ARGS {
3084 markup_command_list_arguments:
3085 markup_command_basic_arguments { $$ = $1; }
3086 | EXPECT_MARKUP markup_command_list_arguments markup {
3087 $$ = scm_cons ($3, $2);
3092 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3093 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3098 markup_head_1_item {
3099 $$ = scm_list_1 ($1);
3101 | markup_head_1_list markup_head_1_item {
3102 $$ = scm_cons ($2, $1);
3108 $$ = make_simple_markup ($1);
3110 | MARKUP_IDENTIFIER {
3113 | LYRIC_MARKUP_IDENTIFIER {
3116 | STRING_IDENTIFIER {
3120 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
3121 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
3122 } '{' score_body '}' {
3124 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3126 PARSER->lexer_->pop_state ();
3128 | MARKUP_FUNCTION markup_command_basic_arguments {
3129 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3131 | markup_scm MARKUP_IDENTIFIER
3138 markup_head_1_list simple_markup {
3139 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3140 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3150 Lily_parser::set_yydebug (bool x)
3156 Lily_parser::do_yyparse ()
3158 yyparse ((void*)this);
3167 It is a little strange to have this function in this file, but
3168 otherwise, we have to import music classes into the lexer.
3172 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3174 if (scm_is_string (sid)) {
3176 return STRING_IDENTIFIER;
3177 } else if (unsmob_book (sid)) {
3178 Book *book = unsmob_book (sid)->clone ();
3179 *destination = book->self_scm ();
3182 return BOOK_IDENTIFIER;
3183 } else if (scm_is_number (sid)) {
3185 return NUMBER_IDENTIFIER;
3186 } else if (unsmob_context_def (sid)) {
3187 Context_def *def= unsmob_context_def (sid)->clone ();
3189 *destination = def->self_scm ();
3192 return CONTEXT_DEF_IDENTIFIER;
3193 } else if (unsmob_context_mod (sid)) {
3194 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3196 return CONTEXT_MOD_IDENTIFIER;
3197 } else if (unsmob_score (sid)) {
3198 Score *score = new Score (*unsmob_score (sid));
3199 *destination = score->self_scm ();
3201 score->unprotect ();
3202 return SCORE_IDENTIFIER;
3203 } else if (Music *mus = unsmob_music (sid)) {
3204 mus = mus->clone ();
3205 *destination = mus->self_scm ();
3206 unsmob_music (*destination)->
3207 set_property ("origin", make_input (last_input_));
3209 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
3213 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3214 } else if (unsmob_pitch (sid)) {
3215 *destination = unsmob_pitch (sid)->smobbed_copy ();
3216 return PITCH_IDENTIFIER;
3217 } else if (unsmob_duration (sid)) {
3218 *destination = unsmob_duration (sid)->smobbed_copy ();
3219 return DURATION_IDENTIFIER;
3220 } else if (unsmob_output_def (sid)) {
3221 Output_def *p = unsmob_output_def (sid);
3224 *destination = p->self_scm ();
3226 return OUTPUT_DEF_IDENTIFIER;
3227 } else if (Text_interface::is_markup (sid)) {
3229 if (is_lyric_state ())
3230 return LYRIC_MARKUP_IDENTIFIER;
3231 return MARKUP_IDENTIFIER;
3232 } else if (Text_interface::is_markup_list (sid)) {
3234 return MARKUPLIST_IDENTIFIER;
3241 get_next_unique_context_id ()
3243 return scm_from_locale_string ("$uniqueContextId");
3248 get_next_unique_lyrics_context_id ()
3250 static int new_context_count;
3252 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3253 return scm_from_locale_string (s);
3256 SCM check_scheme_arg (Lily_parser *my_lily_parser, Input loc,
3257 SCM arg, SCM args, SCM pred)
3259 args = scm_cons (arg, args);
3260 if (scm_is_true (scm_call_1 (pred, arg)))
3262 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3263 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3264 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3268 SCM loc_on_music (Input loc, SCM arg)
3270 if (Music *m = unsmob_music (arg))
3274 return m->unprotect ();
3280 is_regular_identifier (SCM id)
3282 string str = ly_scm2string (id);
3283 char const *s = str.c_str ();
3292 v = v && isalnum (*s);
3299 make_music_with_input (SCM name, Input where)
3301 Music *m = make_music_by_name (name);
3302 m->set_spot (where);
3307 make_simple_markup (SCM a)
3315 return t && t == 1 << intlog2 (t);
3319 set_music_properties (Music *p, SCM a)
3321 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3322 p->set_property (scm_caar (k), scm_cdar (k));
3327 make_chord_step (int step, Rational alter)
3330 alter += FLAT_ALTERATION;
3334 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3335 return m.smobbed_copy ();
3340 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
3342 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3343 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
3347 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
3349 Lily_parser *pars = (Lily_parser*) v;
3350 Lily_lexer *lex = pars->lexer_;
3352 lex->lexval_ = (void*) s;
3354 lex->prepare_for_next_token ();
3355 return lex->yylex ();