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_MARKUP_IDENTIFIER
348 %token <scm> MARKUP_FUNCTION
349 %token <scm> MARKUP_LIST_FUNCTION
350 %token <scm> MARKUP_IDENTIFIER
351 %token <scm> MARKUPLIST_IDENTIFIER
352 %token <scm> MUSIC_FUNCTION
353 %token <scm> MUSIC_IDENTIFIER
354 %token <scm> NOTENAME_PITCH
355 %token <scm> NUMBER_IDENTIFIER
356 %token <scm> OUTPUT_DEF_IDENTIFIER
358 %token <scm> RESTNAME
359 %token <scm> SCM_FUNCTION
360 %token <scm> SCM_IDENTIFIER
361 %token <scm> SCM_TOKEN
362 %token <scm> SCORE_IDENTIFIER
364 %token <scm> STRING_IDENTIFIER
365 %token <scm> TONICNAME_PITCH
368 %type <book> book_block
369 %type <book> book_body
370 %type <book> bookpart_block
371 %type <book> bookpart_body
373 %type <i> bare_unsigned
374 %type <scm> figured_bass_alteration
376 %type <i> exclamations
377 %type <i> optional_rest
382 %type <i> tremolo_type
385 %type <scm> composite_music
386 %type <scm> grouped_music_list
387 %type <scm> braced_music_list
388 %type <scm> closed_music
390 %type <scm> music_bare
391 %type <scm> music_arg
392 %type <scm> complex_music
393 %type <scm> complex_music_prefix
394 %type <scm> mode_changed_music
395 %type <scm> repeated_music
396 %type <scm> sequential_music
397 %type <scm> simple_music
398 %type <scm> simultaneous_music
399 %type <scm> chord_body
400 %type <scm> chord_body_element
401 %type <scm> command_element
402 %type <scm> command_event
403 %type <scm> context_modification
404 %type <scm> context_change
405 %type <scm> direction_less_event
406 %type <scm> direction_reqd_event
407 %type <scm> embedded_lilypond
408 %type <scm> event_chord
409 %type <scm> fingering
410 %type <scm> gen_text_def
411 %type <scm> music_property_def
412 %type <scm> note_chord_element
413 %type <scm> post_event
414 %type <scm> post_event_nofinger
415 %type <scm> re_rhythmed_music
416 %type <scm> simple_element
417 %type <scm> simple_music_property_def
418 %type <scm> start_symbol
419 %type <scm> string_number_event
420 %type <scm> tempo_event
422 %type <outputdef> output_def_body
423 %type <outputdef> output_def_head
424 %type <outputdef> output_def_head_with_mode_switch
425 %type <outputdef> output_def
426 %type <outputdef> paper_block
428 %type <scm> music_function_call
429 %type <scm> music_list
430 %type <scm> assignment_id
431 %type <scm> bare_number
432 %type <scm> bare_number_closed
433 %type <scm> unsigned_number
434 %type <scm> bass_figure
435 %type <scm> figured_bass_modification
436 %type <scm> br_bass_figure
437 %type <scm> bass_number
438 %type <scm> chord_body_elements
439 %type <scm> chord_item
440 %type <scm> chord_items
441 %type <scm> chord_separator
442 %type <scm> context_def_mod
443 %type <scm> context_def_spec_block
444 %type <scm> context_def_spec_body
445 %type <scm> context_mod
446 %type <scm> context_mod_list
447 %type <scm> context_prop_spec
448 %type <scm> direction_less_char
449 %type <scm> duration_length
450 %type <scm> embedded_scm
451 %type <scm> embedded_scm_arg
452 %type <scm> embedded_scm_arg_closed
453 %type <scm> embedded_scm_bare
454 %type <scm> embedded_scm_bare_arg
455 %type <scm> embedded_scm_closed
456 %type <scm> embedded_scm_chord_body
457 %type <scm> event_function_event
458 %type <scm> figure_list
459 %type <scm> figure_spec
461 %type <scm> full_markup
462 %type <scm> full_markup_list
463 %type <scm> function_arglist
464 %type <scm> function_arglist_optional
465 %type <scm> function_arglist_backup
466 %type <scm> function_arglist_nonbackup
467 %type <scm> function_arglist_skip
468 %type <scm> function_arglist_bare
469 %type <scm> function_arglist_closed
470 %type <scm> function_arglist_closed_optional
471 %type <scm> function_arglist_common
472 %type <scm> function_arglist_common_lyric
473 %type <scm> function_arglist_common_minus
474 %type <scm> function_arglist_closed_common
475 %type <scm> function_arglist_keep
476 %type <scm> function_arglist_closed_keep
477 %type <scm> identifier_init
479 %type <scm> lilypond_header
480 %type <scm> lilypond_header_body
481 %type <scm> lyric_element
482 %type <scm> lyric_element_arg
483 %type <scm> lyric_element_music
484 %type <scm> lyric_markup
486 %type <scm> markup_braced_list
487 %type <scm> markup_braced_list_body
488 %type <scm> markup_composed_list
489 %type <scm> markup_command_list
490 %type <scm> markup_command_list_arguments
491 %type <scm> markup_command_basic_arguments
492 %type <scm> markup_head_1_item
493 %type <scm> markup_head_1_list
494 %type <scm> markup_list
495 %type <scm> markup_top
496 %type <scm> mode_changing_head
497 %type <scm> mode_changing_head_with_context
498 %type <scm> multiplied_duration
499 %type <scm> music_function_event
500 %type <scm> music_function_chord_body
501 %type <scm> music_function_chord_body_arglist
502 %type <scm> new_chord
503 %type <scm> new_lyrics
504 %type <scm> number_expression
505 %type <scm> number_factor
506 %type <scm> number_term
507 %type <scm> octave_check
508 %type <scm> optional_context_mod
509 %type <scm> optional_id
510 %type <scm> optional_notemode_duration
512 %type <scm> pitch_also_in_chords
513 %type <scm> post_events
514 %type <scm> property_operation
515 %type <scm> property_path property_path_revved
517 %type <scm> scalar_closed
518 %type <scm> scm_function_call
519 %type <scm> scm_function_call_closed
520 %type <scm> script_abbreviation
521 %type <scm> simple_chord_elements
522 %type <scm> simple_markup
523 %type <scm> simple_string
524 %type <scm> steno_duration
525 %type <scm> steno_pitch
526 %type <scm> steno_tonic_pitch
527 %type <scm> step_number
528 %type <scm> step_numbers
530 %type <scm> tempo_range
532 %type <score> score_block
533 %type <score> score_body
538 /* We don't assign precedence to / and *, because we might need varied
539 prec levels in different prods */
548 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
549 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
550 } embedded_lilypond {
551 PARSER->lexer_->pop_state ();
552 PARSER->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
556 lilypond: /* empty */ { }
557 | lilypond toplevel_expression {
559 | lilypond assignment {
562 PARSER->error_level_ = 1;
565 PARSER->error_level_ = 1;
572 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
576 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
577 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
582 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
583 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
584 bookpart->unprotect ();
589 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
590 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
594 Music *music = unsmob_music ($1);
595 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
596 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
599 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
600 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
603 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
604 scm_call_2 (proc, PARSER->self_scm (), $1);
608 Output_def * od = $1;
610 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
611 id = ly_symbol2scm ("$defaultpaper");
612 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
613 id = ly_symbol2scm ("$defaultmidi");
614 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
615 id = ly_symbol2scm ("$defaultlayout");
617 PARSER->lexer_->set_identifier (id, od->self_scm ());
625 $$ = PARSER->lexer_->eval_scm ($1);
630 embedded_scm_bare_arg:
636 | context_modification
639 $$ = $1->self_scm ();
642 | context_def_spec_block
645 $$ = $1->self_scm ();
650 $$ = $1->self_scm ();
655 $$ = $1->self_scm ();
660 /* The generic version may end in music, or not */
668 embedded_scm_bare_arg
674 SCM_FUNCTION function_arglist {
675 $$ = MAKE_SYNTAX ("music-function", @$,
683 $$ = MAKE_SYNTAX ("void-music", @$);
686 | music music music_list {
687 $$ = MAKE_SYNTAX ("sequential-music", @$,
688 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
691 PARSER->error_level_ = 1;
693 | INVALID embedded_lilypond {
694 PARSER->error_level_ = 1;
699 lilypond_header_body:
701 $$ = get_header (PARSER);
702 PARSER->lexer_->add_scope ($$);
704 | lilypond_header_body assignment {
710 HEADER '{' lilypond_header_body '}' {
711 $$ = PARSER->lexer_->remove_scope ();
720 | LYRICS_STRING { $$ = $1; }
724 assignment_id '=' identifier_init {
725 PARSER->lexer_->set_identifier ($1, $3);
727 | assignment_id property_path '=' identifier_init {
728 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
729 PARSER->lexer_->set_identifier (path, $4);
732 TODO: devise standard for protection in parser.
734 The parser stack lives on the C-stack, which means that
735 all objects can be unprotected as soon as they're here.
745 $$ = $1->self_scm ();
749 $$ = $1->self_scm ();
753 $$ = $1->self_scm ();
757 $$ = $1->self_scm ();
760 | context_def_spec_block {
764 /* Hack: Create event-chord around standalone events.
765 Prevents the identifier from being interpreted as a post-event. */
766 Music *mus = unsmob_music ($1);
767 bool is_event = mus &&
768 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
773 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
775 | post_event_nofinger {
778 | number_expression {
793 | context_modification {
798 context_def_spec_block:
799 CONTEXT '{' context_def_spec_body '}'
805 context_def_spec_body:
807 $$ = Context_def::make_scm ();
808 unsmob_context_def ($$)->origin ()->set_spot (@$);
810 | CONTEXT_DEF_IDENTIFIER {
812 unsmob_context_def ($$)->origin ()->set_spot (@$);
814 | context_def_spec_body embedded_scm {
815 if (Context_mod *cm = unsmob_context_mod ($2)) {
816 SCM p = cm->get_mods ();
817 Context_def*td = unsmob_context_def ($$);
819 for (; scm_is_pair (p); p = scm_cdr (p)) {
820 td->add_context_mod (scm_car (p));
823 PARSER->parser_error (@2, "context-mod expected");
826 | context_def_spec_body context_mod {
827 unsmob_context_def ($$)->add_context_mod ($2);
829 | context_def_spec_body context_modification {
830 Context_def *td = unsmob_context_def ($$);
831 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
832 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
833 td->add_context_mod (scm_car (m));
841 BOOK '{' book_body '}' {
844 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
849 * Use 'handlers' like for toplevel-* stuff?
850 * grok \layout and \midi? */
854 init_papers (PARSER);
855 $$->origin ()->set_spot (@$);
856 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
857 $$->paper_->unprotect ();
858 push_paper (PARSER, $$->paper_);
859 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
860 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
861 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
862 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
865 $$ = unsmob_book ($1);
867 $$->origin ()->set_spot (@$);
868 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
870 | book_body paper_block {
873 set_paper (PARSER, $2);
875 | book_body bookpart_block {
877 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
878 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
879 bookpart->unprotect ();
881 | book_body score_block {
883 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
884 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
887 | book_body composite_music {
888 Music *music = unsmob_music ($2);
889 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
890 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
892 | book_body full_markup {
893 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
894 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
896 | book_body full_markup_list {
897 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
898 scm_call_2 (proc, $$->self_scm (), $2);
900 | book_body lilypond_header {
903 | book_body embedded_scm { }
906 $$->scores_ = SCM_EOL;
907 $$->bookparts_ = SCM_EOL;
912 BOOKPART '{' bookpart_body '}' {
914 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
921 $$->origin ()->set_spot (@$);
922 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
925 $$ = unsmob_book ($1);
927 $$->origin ()->set_spot (@$);
928 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
930 | bookpart_body paper_block {
934 | bookpart_body score_block {
936 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
937 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
940 | bookpart_body composite_music {
941 Music *music = unsmob_music ($2);
942 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
943 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
945 | bookpart_body full_markup {
946 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
947 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
949 | bookpart_body full_markup_list {
950 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
951 scm_call_2 (proc, $$->self_scm (), $2);
953 | bookpart_body lilypond_header {
956 | bookpart_body embedded_scm { }
957 | bookpart_body error {
959 $$->scores_ = SCM_EOL;
964 SCORE '{' score_body '}' {
972 SCM scorify = ly_lily_module_constant ("scorify-music");
973 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
975 // pass ownernship to C++ again.
976 $$ = unsmob_score (score);
978 $$->origin ()->set_spot (@$);
981 $$ = unsmob_score ($1);
983 $$->origin ()->set_spot (@$);
985 | score_body lilypond_header {
988 | score_body output_def {
989 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
991 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
996 $$->add_output_def ($2);
1000 | score_body error {
1001 $$->error_found_ = true;
1013 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1015 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
1017 $$ = get_paper (PARSER);
1024 output_def_body '}' {
1027 PARSER->lexer_->remove_scope ();
1028 PARSER->lexer_->pop_state ();
1034 $$ = get_paper (PARSER);
1035 $$->input_origin_ = @$;
1036 PARSER->lexer_->add_scope ($$->scope_);
1039 Output_def *p = get_midi (PARSER);
1041 PARSER->lexer_->add_scope (p->scope_);
1044 Output_def *p = get_layout (PARSER);
1046 PARSER->lexer_->add_scope (p->scope_);
1051 output_def_head_with_mode_switch:
1053 PARSER->lexer_->push_initial_state ();
1059 output_def_head_with_mode_switch '{' {
1061 $$->input_origin_.set_spot (@$);
1063 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1066 Output_def *o = unsmob_output_def ($3);
1067 o->input_origin_.set_spot (@$);
1070 PARSER->lexer_->remove_scope ();
1071 PARSER->lexer_->add_scope (o->scope_);
1073 | output_def_body assignment {
1076 | output_def_body context_def_spec_block {
1077 assign_context_def ($$, $2);
1079 | output_def_body error {
1085 TEMPO steno_duration '=' tempo_range {
1086 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1088 | TEMPO scalar_closed steno_duration '=' tempo_range {
1089 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1092 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1097 The representation of a list is reversed to have efficient append. */
1103 | music_list music {
1104 $$ = scm_cons ($2, $1);
1106 | music_list embedded_scm {
1109 | music_list error {
1110 Music *m = MY_MAKE_MUSIC("Music", @$);
1112 m->set_property ("error-found", SCM_BOOL_T);
1113 $$ = scm_cons (m->self_scm (), $1);
1114 m->unprotect (); /* UGH */
1121 $$ = scm_reverse_x ($2, SCM_EOL);
1126 | lyric_element_music
1127 | composite_music %prec COMPOSITE
1132 | composite_music %prec COMPOSITE
1136 REPEAT simple_string unsigned_number music
1138 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1140 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1142 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1147 SEQUENTIAL braced_music_list {
1148 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1150 | braced_music_list {
1151 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1156 SIMULTANEOUS braced_music_list {
1157 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1159 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1160 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1166 | music_property_def
1170 context_modification:
1171 WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1173 PARSER->lexer_->pop_state ();
1176 | WITH CONTEXT_MOD_IDENTIFIER
1180 | CONTEXT_MOD_IDENTIFIER
1184 | WITH embedded_scm_closed
1186 if (unsmob_context_mod ($2))
1189 PARSER->parser_error (@2, "context-mod expected");
1190 $$ = Context_mod ().smobbed_copy ();
1195 optional_context_mod:
1199 | context_modification
1207 $$ = Context_mod ().smobbed_copy ();
1209 | context_mod_list context_mod {
1210 unsmob_context_mod ($1)->add_context_mod ($2);
1212 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1213 Context_mod *md = unsmob_context_mod ($2);
1215 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1224 /* Music that can be parsed without lookahead */
1227 | complex_music_prefix closed_music
1229 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1236 | grouped_music_list
1240 simultaneous_music { $$ = $1; }
1241 | sequential_music { $$ = $1; }
1244 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1245 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1246 and this rule returns the reversed list of arguments. */
1248 function_arglist_skip:
1249 function_arglist_common
1250 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1252 $$ = scm_cons ($1, $3);
1253 } %prec FUNCTION_ARGLIST
1254 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1256 $$ = scm_cons ($1, $3);
1257 } %prec FUNCTION_ARGLIST
1258 | EXPECT_SCM EXPECT_DURATION function_arglist_skip
1260 $$ = scm_cons ($1, $3);
1261 } %prec FUNCTION_ARGLIST
1265 function_arglist_nonbackup:
1266 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1267 $$ = scm_cons ($4, $3);
1269 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1270 $$ = scm_cons ($4, $3);
1272 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1274 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1276 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1278 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1280 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1282 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1284 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1286 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1288 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1290 SCM n = scm_difference ($5, SCM_UNDEFINED);
1291 if (scm_is_true (scm_call_1 ($2, n)))
1292 $$ = scm_cons (n, $3);
1294 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1295 t->set_property ("digit", $5);
1296 $$ = t->unprotect ();
1297 if (scm_is_true (scm_call_1 ($2, $$)))
1298 $$ = scm_cons ($$, $3);
1300 $$ = check_scheme_arg (PARSER, @4, n, $3, $2);
1304 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1306 $$ = check_scheme_arg (PARSER, @4,
1307 scm_difference ($5, SCM_UNDEFINED),
1310 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1312 $$ = check_scheme_arg (PARSER, @4,
1313 scm_difference ($5, SCM_UNDEFINED),
1319 function_arglist_keep:
1320 function_arglist_common
1321 | function_arglist_backup
1324 function_arglist_closed_keep:
1325 function_arglist_closed_common
1326 | function_arglist_backup
1329 function_arglist_backup:
1330 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1332 if (scm_is_true (scm_call_1 ($2, $4)))
1334 $$ = scm_cons ($4, $3);
1336 $$ = scm_cons (loc_on_music (@3, $1), $3);
1337 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1340 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1342 if (scm_is_true (scm_call_1 ($2, $4)))
1344 $$ = scm_cons ($4, $3);
1346 $$ = scm_cons (loc_on_music (@3, $1), $3);
1347 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1350 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1352 // There is no point interpreting a lyrics string as
1353 // an event, since we don't allow music possibly
1354 // followed by durations or postevent into closed
1355 // music, and we only accept closed music in optional
1356 // arguments at the moment. If this changes, more
1357 // complex schemes might become interesting here as
1358 // well: see how we do this at the mandatory argument
1360 if (scm_is_true (scm_call_1 ($2, $4)))
1361 $$ = scm_cons ($4, $3);
1363 $$ = scm_cons (loc_on_music (@3, $1), $3);
1364 MYBACKUP (LYRICS_STRING, $4, @4);
1367 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1369 if (scm_is_true (scm_call_1 ($2, $4)))
1372 MYREPARSE (@4, $2, UNSIGNED, $4);
1374 $$ = scm_cons (loc_on_music (@3, $1), $3);
1375 MYBACKUP (UNSIGNED, $4, @4);
1378 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1380 if (scm_is_true (scm_call_1 ($2, $4)))
1383 MYREPARSE (@4, $2, REAL, $4);
1385 $$ = scm_cons (loc_on_music (@3, $1), $3);
1386 MYBACKUP (REAL, $4, @4);
1389 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1391 if (scm_is_true (scm_call_1 ($2, $4)))
1393 $$ = scm_cons ($4, $3);
1395 $$ = scm_cons (loc_on_music (@3, $1), $3);
1396 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1399 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1401 if (scm_is_true (scm_call_1 ($2, $4)))
1403 $$ = scm_cons ($4, $3);
1405 $$ = scm_cons (loc_on_music (@3, $1), $3);
1406 MYBACKUP (FRACTION, $4, @4);
1409 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1411 SCM n = scm_difference ($5, SCM_UNDEFINED);
1412 if (scm_is_true (scm_call_1 ($2, n))) {
1414 MYREPARSE (@5, $2, REAL, n);
1416 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1417 t->set_property ("digit", $5);
1418 $$ = t->unprotect ();
1419 if (scm_is_true (scm_call_1 ($2, $$)))
1420 $$ = scm_cons ($$, $3);
1422 $$ = scm_cons (loc_on_music (@3, $1), $3);
1423 MYBACKUP (UNSIGNED, $5, @5);
1424 PARSER->lexer_->push_extra_token ('-');
1429 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1431 SCM n = scm_difference ($5, SCM_UNDEFINED);
1432 if (scm_is_true (scm_call_1 ($2, n))) {
1433 MYREPARSE (@5, $2, REAL, n);
1436 MYBACKUP (REAL, n, @5);
1439 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1441 SCM n = scm_difference ($5, SCM_UNDEFINED);
1442 if (scm_is_true (scm_call_1 ($2, n))) {
1443 $$ = scm_cons (n, $3);
1445 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1448 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1450 $$ = scm_cons ($4, $3);
1452 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1454 $$ = scm_cons ($4, $3);
1456 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1458 $$ = scm_cons ($1, $3);
1459 MYBACKUP(0, SCM_UNDEFINED, @3);
1461 | function_arglist_backup REPARSE embedded_scm_arg_closed
1463 $$ = check_scheme_arg (PARSER, @3,
1466 | function_arglist_backup REPARSE bare_number
1468 $$ = check_scheme_arg (PARSER, @3,
1471 | function_arglist_backup REPARSE fraction
1473 $$ = check_scheme_arg (PARSER, @3,
1479 function_arglist_common
1480 | function_arglist_nonbackup
1483 function_arglist_common:
1484 function_arglist_bare
1485 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1487 $$ = check_scheme_arg (PARSER, @3,
1490 | EXPECT_SCM function_arglist_closed_optional bare_number
1492 $$ = check_scheme_arg (PARSER, @3,
1495 | EXPECT_SCM function_arglist_closed_optional fraction
1497 $$ = check_scheme_arg (PARSER, @3,
1500 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1502 $$ = check_scheme_arg (PARSER, @3,
1505 | function_arglist_common_minus
1506 | function_arglist_common_lyric
1509 function_arglist_common_lyric:
1510 EXPECT_SCM function_arglist_optional lyric_element
1512 // We check how the predicate thinks about a lyrics
1513 // event or about a markup. If it accepts neither, we
1514 // backup the original token. Otherwise we commit to
1515 // taking the token. Depending on what the predicate
1516 // is willing to accept, we interpret as a string, as
1517 // a lyric event, or ambiguously (meaning that if
1518 // something looking like a duration or post event
1519 // follows, we take the event, otherwise the string).
1520 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1521 PARSER->default_duration_.smobbed_copy ());
1522 if (scm_is_true (scm_call_1 ($1, $3)))
1523 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1526 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1528 $$ = scm_cons ($3, $2);
1530 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1533 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1535 // This is going to flag a syntax error, we
1536 // know the predicate to be false.
1537 check_scheme_arg (PARSER, @3,
1541 | function_arglist_common_lyric REPARSE lyric_element_arg
1543 // This should never be false
1544 $$ = check_scheme_arg (PARSER, @3,
1549 function_arglist_common_minus:
1550 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1552 SCM n = scm_difference ($4, SCM_UNDEFINED);
1553 if (scm_is_true (scm_call_1 ($1, n))) {
1555 MYREPARSE (@4, $1, REAL, n);
1557 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1558 t->set_property ("digit", $4);
1559 $$ = t->unprotect ();
1560 if (scm_is_true (scm_call_1 ($1, $$)))
1561 $$ = scm_cons ($$, $2);
1563 $$ = check_scheme_arg (PARSER, @3, n, $2, $1);
1567 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1570 SCM n = scm_difference ($4, SCM_UNDEFINED);
1571 MYREPARSE (@4, $1, REAL, n);
1573 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1575 SCM n = scm_difference ($4, SCM_UNDEFINED);
1576 $$ = check_scheme_arg (PARSER, @4, n, $2, $1);
1578 | function_arglist_common_minus REPARSE bare_number
1580 $$ = check_scheme_arg (PARSER, @3, $3, $1, $2);
1584 function_arglist_closed:
1585 function_arglist_closed_common
1586 | function_arglist_nonbackup
1589 function_arglist_closed_common:
1590 function_arglist_bare
1591 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1593 $$ = check_scheme_arg (PARSER, @3,
1596 | EXPECT_SCM function_arglist_closed_optional bare_number
1598 $$ = check_scheme_arg (PARSER, @3,
1601 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1603 SCM n = scm_difference ($4, SCM_UNDEFINED);
1604 if (scm_is_true (scm_call_1 ($1, n))) {
1605 $$ = scm_cons (n, $2);
1607 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1608 t->set_property ("digit", $4);
1609 $$ = t->unprotect ();
1610 if (scm_is_true (scm_call_1 ($1, $$)))
1611 $$ = scm_cons ($$, $2);
1613 $$ = check_scheme_arg (PARSER, @3, n, $2, $1);
1617 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1619 $$ = check_scheme_arg (PARSER, @3,
1620 scm_difference ($4, SCM_UNDEFINED),
1623 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1625 $$ = check_scheme_arg (PARSER, @3,
1626 scm_difference ($4, SCM_UNDEFINED),
1629 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1631 $$ = check_scheme_arg (PARSER, @3,
1634 | EXPECT_SCM function_arglist_closed_optional fraction
1636 $$ = check_scheme_arg (PARSER, @3,
1639 | EXPECT_SCM function_arglist_optional lyric_element
1641 $$ = check_scheme_arg (PARSER, @3,
1646 function_arglist_optional:
1647 function_arglist_keep %prec FUNCTION_ARGLIST
1648 | function_arglist_backup BACKUP
1649 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1651 $$ = scm_cons ($1, $3);
1653 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1655 $$ = scm_cons ($1, $3);
1659 function_arglist_closed_optional:
1660 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1661 | function_arglist_backup BACKUP
1662 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1664 $$ = scm_cons ($1, $3);
1666 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1668 $$ = scm_cons ($1, $3);
1672 embedded_scm_closed:
1674 | scm_function_call_closed
1677 embedded_scm_arg_closed:
1678 embedded_scm_bare_arg
1679 | scm_function_call_closed
1683 scm_function_call_closed:
1684 SCM_FUNCTION function_arglist_closed {
1685 $$ = MAKE_SYNTAX ("music-function", @$,
1687 } %prec FUNCTION_ARGLIST
1690 function_arglist_bare:
1691 EXPECT_NO_MORE_ARGS {
1694 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1695 $$ = scm_cons ($3, $2);
1697 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1698 $$ = scm_cons ($3, $2);
1700 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1701 $$ = scm_cons ($1, $3);
1703 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1704 $$ = scm_cons ($1, $3);
1706 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1707 $$ = scm_cons ($1, $3);
1711 music_function_call:
1712 MUSIC_FUNCTION function_arglist {
1713 $$ = MAKE_SYNTAX ("music-function", @$,
1720 /**/ { $$ = SCM_EOL; }
1721 | '=' simple_string {
1728 | repeated_music { $$ = $1; }
1729 | re_rhythmed_music { $$ = $1; }
1730 | complex_music_prefix music
1732 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1736 complex_music_prefix:
1737 CONTEXT simple_string optional_id optional_context_mod {
1738 Context_mod *ctxmod = unsmob_context_mod ($4);
1741 mods = ctxmod->get_mods ();
1742 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1744 | NEWCONTEXT simple_string optional_id optional_context_mod {
1745 Context_mod *ctxmod = unsmob_context_mod ($4);
1748 mods = ctxmod->get_mods ();
1749 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1754 mode_changing_head grouped_music_list {
1755 if ($1 == ly_symbol2scm ("chords"))
1757 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1763 PARSER->lexer_->pop_state ();
1765 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1766 Context_mod *ctxmod = unsmob_context_mod ($2);
1769 mods = ctxmod->get_mods ();
1770 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1771 if ($1 == ly_symbol2scm ("ChordNames"))
1773 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1775 PARSER->lexer_->pop_state ();
1781 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1782 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1784 $$ = ly_symbol2scm ("notes");
1788 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1789 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1791 $$ = ly_symbol2scm ("drums");
1794 PARSER->lexer_->push_figuredbass_state ();
1796 $$ = ly_symbol2scm ("figures");
1799 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1800 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1801 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1802 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1803 $$ = ly_symbol2scm ("chords");
1807 { PARSER->lexer_->push_lyric_state ();
1808 $$ = ly_symbol2scm ("lyrics");
1812 mode_changing_head_with_context:
1814 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1815 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1817 $$ = ly_symbol2scm ("DrumStaff");
1820 PARSER->lexer_->push_figuredbass_state ();
1822 $$ = ly_symbol2scm ("FiguredBass");
1825 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1826 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1827 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1828 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1829 $$ = ly_symbol2scm ("ChordNames");
1832 { PARSER->lexer_->push_lyric_state ();
1833 $$ = ly_symbol2scm ("Lyrics");
1838 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1841 /* Can also use music at the expensive of two S/Rs similar to
1842 \repeat \alternative */
1843 PARSER->lexer_->pop_state ();
1845 $$ = scm_cons ($3, SCM_EOL);
1847 | new_lyrics ADDLYRICS {
1848 PARSER->lexer_->push_lyric_state ();
1850 PARSER->lexer_->pop_state ();
1851 $$ = scm_cons ($4, $1);
1856 composite_music new_lyrics {
1857 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1859 | LYRICSTO simple_string {
1860 PARSER->lexer_->push_lyric_state ();
1862 PARSER->lexer_->pop_state ();
1863 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1868 CHANGE STRING '=' STRING {
1869 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1874 property_path_revved:
1875 embedded_scm_closed {
1876 $$ = scm_cons ($1, SCM_EOL);
1878 | property_path_revved embedded_scm_closed {
1879 $$ = scm_cons ($2, $1);
1884 property_path_revved {
1885 $$ = scm_reverse_x ($1, SCM_EOL);
1891 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1892 scm_string_to_symbol ($1), $3);
1894 | UNSET simple_string {
1895 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1896 scm_string_to_symbol ($2));
1898 | OVERRIDE simple_string property_path '=' scalar {
1899 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1900 scm_string_to_symbol ($2), $5),
1903 | REVERT simple_string embedded_scm {
1904 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1905 scm_string_to_symbol ($2), $3);
1910 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1911 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1913 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1914 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1915 | DENIES { $$ = ly_symbol2scm ("denies"); }
1917 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1918 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1919 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1920 | NAME { $$ = ly_symbol2scm ("context-name"); }
1924 property_operation { $$ = $1; }
1925 | context_def_mod STRING {
1926 $$ = scm_list_2 ($1, $2);
1928 | context_def_mod embedded_scm {
1929 if (ly_symbol2scm ("consists") != $1)
1932 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1936 $$ = scm_list_2 ($1, $2);
1943 if (!is_regular_identifier ($1))
1945 @$.error (_("Grob name should be alphanumeric"));
1948 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1949 scm_string_to_symbol ($1));
1951 | simple_string '.' simple_string {
1952 $$ = scm_list_2 (scm_string_to_symbol ($1),
1953 scm_string_to_symbol ($3));
1957 simple_music_property_def:
1958 OVERRIDE context_prop_spec property_path '=' scalar {
1959 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1960 ly_symbol2scm ("OverrideProperty"),
1965 | REVERT context_prop_spec embedded_scm {
1966 $$ = scm_list_4 (scm_car ($2),
1967 ly_symbol2scm ("RevertProperty"),
1971 | SET context_prop_spec '=' scalar {
1972 $$ = scm_list_4 (scm_car ($2),
1973 ly_symbol2scm ("PropertySet"),
1977 | UNSET context_prop_spec {
1978 $$ = scm_list_3 (scm_car ($2),
1979 ly_symbol2scm ("PropertyUnset"),
1985 simple_music_property_def {
1986 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (PARSER->self_scm (), make_input (@$), $1));
1994 | STRING_IDENTIFIER {
1997 | string '+' string {
1998 $$ = scm_string_append (scm_list_2 ($1, $3));
2002 simple_string: STRING {
2008 | STRING_IDENTIFIER {
2020 embedded_scm_arg_closed
2027 /* TODO: Create a special case that avoids the creation of
2028 EventChords around simple_elements that have no post_events?
2030 simple_chord_elements post_events {
2031 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2034 /* why is this giving wrong start location? -ns
2036 i.set_location (@1, @2);
2037 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2039 | CHORD_REPETITION optional_notemode_duration post_events {
2041 i.set_location (@1, @3);
2042 $$ = MAKE_SYNTAX ("repetition-chord", i,
2043 PARSER->lexer_->chord_repetition_.last_chord_,
2044 PARSER->lexer_->chord_repetition_.repetition_function_,
2045 $2, scm_reverse_x ($3, SCM_EOL));
2047 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2049 i.set_location (@1, @3);
2050 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2051 scm_reverse_x ($3, SCM_EOL));
2054 /* note chord elements are memorized into
2055 PARSER->lexer_->chord_repetition_ so that the chord repetition
2056 mechanism copy them when a chord repetition symbol is found
2058 | note_chord_element {
2059 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
2065 chord_body optional_notemode_duration post_events
2067 Music *m = unsmob_music ($1);
2068 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2069 SCM es = m->get_property ("elements");
2070 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2072 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2073 unsmob_music (scm_car (s))->set_property ("duration", dur);
2074 es = ly_append2 (es, postevs);
2076 m-> set_property ("elements", es);
2078 $$ = m->self_scm ();
2083 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2085 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2089 chord_body_elements:
2090 /* empty */ { $$ = SCM_EOL; }
2091 | chord_body_elements chord_body_element {
2092 $$ = scm_cons ($2, $1);
2097 pitch exclamations questions octave_check post_events
2104 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2105 n->set_property ("pitch", $1);
2107 n->set_property ("cautionary", SCM_BOOL_T);
2108 if (ex % 2 || q % 2)
2109 n->set_property ("force-accidental", SCM_BOOL_T);
2111 if (scm_is_pair (post)) {
2112 SCM arts = scm_reverse_x (post, SCM_EOL);
2113 n->set_property ("articulations", arts);
2115 if (scm_is_number (check))
2117 int q = scm_to_int (check);
2118 n->set_property ("absolute-octave", scm_from_int (q-1));
2121 $$ = n->unprotect ();
2123 | DRUM_PITCH post_events {
2124 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2125 n->set_property ("drum-type", $1);
2127 if (scm_is_pair ($2)) {
2128 SCM arts = scm_reverse_x ($2, SCM_EOL);
2129 n->set_property ("articulations", arts);
2131 $$ = n->unprotect ();
2133 | music_function_chord_body
2136 /* We can't accept a music argument, not even a closed one,
2137 * immediately before chord_body_elements, otherwise a function \fun
2138 * with a signature of two music arguments can't be sorted out
2139 * properly in a construct like
2140 * <\fun { c } \fun { c } c>
2141 * The second call could be interpreted either as a chord constituent
2142 * or a music expression.
2145 music_function_chord_body_arglist:
2146 function_arglist_bare
2147 | EXPECT_SCM music_function_chord_body_arglist embedded_scm_chord_body
2149 $$ = check_scheme_arg (PARSER, @3,
2154 embedded_scm_chord_body:
2155 embedded_scm_bare_arg
2156 | SCM_FUNCTION music_function_chord_body_arglist {
2157 $$ = MAKE_SYNTAX ("music-function", @$,
2163 | chord_body_element
2166 music_function_chord_body:
2167 MUSIC_FUNCTION music_function_chord_body_arglist {
2168 $$ = MAKE_SYNTAX ("music-function", @$,
2173 // Event functions may only take closed arglists, otherwise it would
2174 // not be clear whether a following postevent should be associated
2175 // with the last argument of the event function or with the expression
2176 // for which the function call acts itself as event.
2178 music_function_event:
2179 MUSIC_FUNCTION function_arglist_closed {
2180 $$ = MAKE_SYNTAX ("music-function", @$,
2185 event_function_event:
2186 EVENT_FUNCTION function_arglist_closed {
2187 $$ = MAKE_SYNTAX ("music-function", @$,
2197 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2198 m->set_property ("span-direction", scm_from_int (START));
2199 $$ = m->unprotect();
2202 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2203 m->set_property ("span-direction", scm_from_int (STOP));
2204 $$ = m->unprotect ();
2207 $$ = MAKE_SYNTAX ("voice-separator", @$);
2210 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
2212 Music *m = unsmob_music (pipe);
2217 $$ = m->unprotect ();
2220 $$ = MAKE_SYNTAX ("bar-check", @$);
2227 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2239 | post_events post_event {
2240 unsmob_music ($2)->set_spot (@2);
2241 $$ = scm_cons ($2, $$);
2245 post_event_nofinger:
2246 direction_less_event {
2249 | script_dir music_function_event {
2253 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2257 if (!PARSER->lexer_->is_lyric_state ())
2258 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2259 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2262 if (!PARSER->lexer_->is_lyric_state ())
2263 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2264 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2266 | script_dir direction_reqd_event {
2269 Music *m = unsmob_music ($2);
2270 m->set_property ("direction", scm_from_int ($1));
2274 | script_dir direction_less_event {
2277 Music *m = unsmob_music ($2);
2278 m->set_property ("direction", scm_from_int ($1));
2282 | string_number_event
2286 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2291 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2302 string_number_event:
2304 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2305 s->set_property ("string-number", scm_from_int ($1));
2306 $$ = s->unprotect ();
2310 direction_less_char:
2312 $$ = ly_symbol2scm ("bracketOpenSymbol");
2315 $$ = ly_symbol2scm ("bracketCloseSymbol");
2318 $$ = ly_symbol2scm ("tildeSymbol");
2321 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2324 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2327 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2330 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2333 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2336 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2339 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2343 direction_less_event:
2344 direction_less_char {
2345 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
2347 if (unsmob_music (predefd))
2349 m = unsmob_music (predefd)->clone ();
2354 m = MY_MAKE_MUSIC ("Music", @$);
2356 $$ = m->unprotect ();
2358 | EVENT_IDENTIFIER {
2362 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2363 a->set_property ("tremolo-type", scm_from_int ($1));
2364 $$ = a->unprotect ();
2366 | event_function_event
2369 direction_reqd_event:
2373 | script_abbreviation {
2374 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2375 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2376 if (scm_is_string (s))
2377 a->set_property ("articulation-type", s);
2378 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
2379 $$ = a->unprotect ();
2384 /**/ { $$ = SCM_EOL; }
2385 | '=' { $$ = scm_from_int (0); }
2386 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2387 | '=' sup_quotes { $$ = scm_from_int ($2); }
2412 | NOTENAME_PITCH sup_quotes {
2413 Pitch p = *unsmob_pitch ($1);
2414 p = p.transposed (Pitch ($2,0,0));
2415 $$ = p.smobbed_copy ();
2417 | NOTENAME_PITCH sub_quotes {
2418 Pitch p =* unsmob_pitch ($1);
2419 p = p.transposed (Pitch (-$2,0,0));
2420 $$ = p.smobbed_copy ();
2432 | TONICNAME_PITCH sup_quotes {
2433 Pitch p = *unsmob_pitch ($1);
2434 p = p.transposed (Pitch ($2,0,0));
2435 $$ = p.smobbed_copy ();
2437 | TONICNAME_PITCH sub_quotes {
2438 Pitch p = *unsmob_pitch ($1);
2440 p = p.transposed (Pitch (-$2,0,0));
2441 $$ = p.smobbed_copy ();
2452 pitch_also_in_chords:
2459 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2460 t->set_property ("text", $1);
2461 $$ = t->unprotect ();
2464 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2465 t->set_property ("text",
2466 make_simple_markup ($1));
2467 $$ = t->unprotect ();
2473 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2474 t->set_property ("digit", $1);
2475 $$ = t->unprotect ();
2479 script_abbreviation:
2481 $$ = scm_from_locale_string ("Hat");
2484 $$ = scm_from_locale_string ("Plus");
2487 $$ = scm_from_locale_string ("Dash");
2490 $$ = scm_from_locale_string ("Bar");
2493 $$ = scm_from_locale_string ("Larger");
2496 $$ = scm_from_locale_string ("Dot");
2499 $$ = scm_from_locale_string ("Underscore");
2506 | '-' { $$ = CENTER; }
2510 multiplied_duration {
2515 optional_notemode_duration:
2517 Duration dd = PARSER->default_duration_;
2518 $$ = dd.smobbed_copy ();
2520 | multiplied_duration {
2522 PARSER->default_duration_ = *unsmob_duration ($$);
2527 bare_unsigned dots {
2529 if (!is_duration ($1))
2530 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
2534 $$ = Duration (len, $2).smobbed_copy ();
2536 | DURATION_IDENTIFIER dots {
2537 Duration *d = unsmob_duration ($1);
2538 Duration k (d->duration_log (), d->dot_count () + $2);
2539 k = k.compressed (d->factor ());
2545 multiplied_duration:
2549 | multiplied_duration '*' bare_unsigned {
2550 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2552 | multiplied_duration '*' FRACTION {
2553 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2555 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2560 FRACTION { $$ = $1; }
2561 | UNSIGNED '/' UNSIGNED {
2562 $$ = scm_cons ($1, $3);
2579 | ':' bare_unsigned {
2580 if (!is_duration ($2))
2581 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2587 UNSIGNED { $$ = $1; }
2588 | STRING { $$ = $1; }
2589 | full_markup { $$ = $1; }
2592 figured_bass_alteration:
2593 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2594 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2595 | '!' { $$ = scm_from_int (0); }
2600 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2601 $$ = bfr->unprotect ();
2604 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2605 $$ = bfr->self_scm ();
2607 if (scm_is_number ($1))
2608 bfr->set_property ("figure", $1);
2609 else if (Text_interface::is_markup ($1))
2610 bfr->set_property ("text", $1);
2616 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2618 | bass_figure figured_bass_alteration {
2619 Music *m = unsmob_music ($1);
2620 if (scm_to_double ($2)) {
2621 SCM salter = m->get_property ("alteration");
2622 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2623 m->set_property ("alteration",
2624 scm_sum (alter, $2));
2626 m->set_property ("alteration", scm_from_int (0));
2629 | bass_figure figured_bass_modification {
2630 Music *m = unsmob_music ($1);
2631 if ($2 == ly_symbol2scm ("plus"))
2633 m->set_property ("augmented", SCM_BOOL_T);
2635 else if ($2 == ly_symbol2scm ("slash"))
2637 m->set_property ("diminished", SCM_BOOL_T);
2639 else if ($2 == ly_symbol2scm ("exclamation"))
2641 m->set_property ("no-continuation", SCM_BOOL_T);
2643 else if ($2 == ly_symbol2scm ("backslash"))
2645 m->set_property ("augmented-slash", SCM_BOOL_T);
2651 figured_bass_modification:
2653 $$ = ly_symbol2scm ("plus");
2656 $$ = ly_symbol2scm ("exclamation");
2659 $$ = ly_symbol2scm ("slash");
2662 $$ = ly_symbol2scm ("backslash");
2672 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2680 | figure_list br_bass_figure {
2681 $$ = scm_cons ($2, $1);
2686 FIGURE_OPEN figure_list FIGURE_CLOSE {
2687 $$ = scm_reverse_x ($2, SCM_EOL);
2698 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2699 if (!PARSER->lexer_->is_note_state ())
2700 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2704 n = MY_MAKE_MUSIC ("RestEvent", @$);
2706 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2708 n->set_property ("pitch", $1);
2709 n->set_property ("duration", $5);
2711 if (scm_is_number ($4))
2713 int q = scm_to_int ($4);
2714 n->set_property ("absolute-octave", scm_from_int (q-1));
2718 n->set_property ("cautionary", SCM_BOOL_T);
2719 if ($2 % 2 || $3 % 2)
2720 n->set_property ("force-accidental", SCM_BOOL_T);
2722 $$ = n->unprotect ();
2724 | DRUM_PITCH optional_notemode_duration {
2725 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2726 n->set_property ("duration", $2);
2727 n->set_property ("drum-type", $1);
2729 $$ = n->unprotect ();
2731 | RESTNAME optional_notemode_duration {
2733 if (ly_scm2string ($1) == "s") {
2735 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2738 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2741 ev->set_property ("duration", $2);
2742 $$ = ev->unprotect ();
2746 simple_chord_elements:
2748 $$ = scm_list_1 ($1);
2751 if (!PARSER->lexer_->is_chord_state ())
2752 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2755 | figure_spec optional_notemode_duration {
2756 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2758 unsmob_music (scm_car (s))->set_property ("duration", $2);
2775 | lyric_element multiplied_duration post_events {
2776 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2777 $$ = MAKE_SYNTAX ("event-chord", @$,
2778 scm_cons (lyric_event,
2779 scm_reverse_x ($3, SCM_EOL)));
2781 | lyric_element post_event post_events {
2783 MAKE_SYNTAX ("lyric-event", @$, $1,
2784 PARSER->default_duration_.smobbed_copy ());
2785 $$ = MAKE_SYNTAX ("event-chord", @$,
2786 scm_cons2 (lyric_event, $2,
2787 scm_reverse_x ($3, SCM_EOL)));
2790 | LYRIC_ELEMENT optional_notemode_duration post_events {
2791 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2792 $$ = MAKE_SYNTAX ("event-chord", @$,
2793 scm_cons (lyric_event,
2794 scm_reverse_x ($3, SCM_EOL)));
2799 lyric_element_music:
2800 lyric_element optional_notemode_duration post_events {
2801 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2802 $$ = MAKE_SYNTAX ("event-chord", @$,
2803 scm_cons (lyric_event,
2804 scm_reverse_x ($3, SCM_EOL)));
2809 steno_tonic_pitch optional_notemode_duration {
2810 $$ = make_chord_elements ($1, $2, SCM_EOL);
2812 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2813 SCM its = scm_reverse_x ($4, SCM_EOL);
2814 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2822 | chord_items chord_item {
2823 $$ = scm_cons ($2, $$);
2829 $$ = ly_symbol2scm ("chord-colon");
2832 $$ = ly_symbol2scm ("chord-caret");
2834 | CHORD_SLASH steno_tonic_pitch {
2835 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2837 | CHORD_BASS steno_tonic_pitch {
2838 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2847 $$ = scm_reverse_x ($1, SCM_EOL);
2855 step_number { $$ = scm_cons ($1, SCM_EOL); }
2856 | step_numbers '.' step_number {
2857 $$ = scm_cons ($3, $$);
2863 $$ = make_chord_step ($1, 0);
2865 | bare_unsigned '+' {
2866 $$ = make_chord_step ($1, SHARP_ALTERATION);
2868 | bare_unsigned CHORD_MINUS {
2869 $$ = make_chord_step ($1, FLAT_ALTERATION);
2875 $$ = scm_from_int ($1);
2877 | bare_unsigned '~' bare_unsigned {
2878 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2885 TODO: should deprecate in favor of Scheme?
2889 number_expression '+' number_term {
2890 $$ = scm_sum ($1, $3);
2892 | number_expression '-' number_term {
2893 $$ = scm_difference ($1, $3);
2902 | number_factor '*' number_factor {
2903 $$ = scm_product ($1, $3);
2905 | number_factor '/' number_factor {
2906 $$ = scm_divide ($1, $3);
2911 '-' number_factor { /* %prec UNARY_MINUS */
2912 $$ = scm_difference ($2, SCM_UNDEFINED);
2920 | UNSIGNED NUMBER_IDENTIFIER {
2921 $$ = scm_product ($1, $2)
2923 | REAL NUMBER_IDENTIFIER {
2924 $$ = scm_product ($1, $2)
2936 $$ = scm_to_int ($1);
2947 | exclamations '!' { $$ ++; }
2952 | questions '?' { $$ ++; }
2956 This should be done more dynamically if possible.
2960 LYRIC_MARKUP_IDENTIFIER {
2964 { PARSER->lexer_->push_markup_state (); }
2967 PARSER->lexer_->pop_state ();
2972 MARKUPLIST_IDENTIFIER {
2976 { PARSER->lexer_->push_markup_state (); }
2979 PARSER->lexer_->pop_state ();
2988 { PARSER->lexer_->push_markup_state (); }
2991 PARSER->lexer_->pop_state ();
2997 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2999 | markup_head_1_list simple_markup {
3000 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3010 if (Text_interface::is_markup ($1))
3011 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3012 else if (Text_interface::is_markup_list ($1))
3013 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3015 PARSER->parser_error (@1, _("markup expected"));
3016 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3023 MARKUPLIST_IDENTIFIER {
3026 | markup_composed_list {
3029 | markup_braced_list {
3032 | markup_command_list {
3033 $$ = scm_list_1 ($1);
3035 | markup_scm MARKUPLIST_IDENTIFIER
3041 markup_composed_list:
3042 markup_head_1_list markup_braced_list {
3043 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3049 '{' markup_braced_list_body '}' {
3050 $$ = scm_reverse_x ($2, SCM_EOL);
3054 markup_braced_list_body:
3055 /* empty */ { $$ = SCM_EOL; }
3056 | markup_braced_list_body markup {
3057 $$ = scm_cons ($2, $1);
3059 | markup_braced_list_body markup_list {
3060 $$ = scm_reverse_x ($2, $1);
3064 markup_command_list:
3065 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3066 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3070 markup_command_basic_arguments:
3071 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3072 $$ = scm_cons ($3, $2);
3074 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3075 $$ = check_scheme_arg (PARSER, @3, $3, $2, $1);
3077 | EXPECT_NO_MORE_ARGS {
3082 markup_command_list_arguments:
3083 markup_command_basic_arguments { $$ = $1; }
3084 | EXPECT_MARKUP markup_command_list_arguments markup {
3085 $$ = scm_cons ($3, $2);
3090 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3091 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3096 markup_head_1_item {
3097 $$ = scm_list_1 ($1);
3099 | markup_head_1_list markup_head_1_item {
3100 $$ = scm_cons ($2, $1);
3106 $$ = make_simple_markup ($1);
3108 | MARKUP_IDENTIFIER {
3111 | LYRIC_MARKUP_IDENTIFIER {
3114 | STRING_IDENTIFIER {
3118 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
3119 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
3120 } '{' score_body '}' {
3122 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3124 PARSER->lexer_->pop_state ();
3126 | MARKUP_FUNCTION markup_command_basic_arguments {
3127 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3129 | markup_scm MARKUP_IDENTIFIER
3136 markup_head_1_list simple_markup {
3137 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3138 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3148 Lily_parser::set_yydebug (bool x)
3154 Lily_parser::do_yyparse ()
3156 yyparse ((void*)this);
3165 It is a little strange to have this function in this file, but
3166 otherwise, we have to import music classes into the lexer.
3170 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3172 if (scm_is_string (sid)) {
3174 return STRING_IDENTIFIER;
3175 } else if (unsmob_book (sid)) {
3176 Book *book = unsmob_book (sid)->clone ();
3177 *destination = book->self_scm ();
3180 return BOOK_IDENTIFIER;
3181 } else if (scm_is_number (sid)) {
3183 return NUMBER_IDENTIFIER;
3184 } else if (unsmob_context_def (sid)) {
3185 Context_def *def= unsmob_context_def (sid)->clone ();
3187 *destination = def->self_scm ();
3190 return CONTEXT_DEF_IDENTIFIER;
3191 } else if (unsmob_context_mod (sid)) {
3192 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3194 return CONTEXT_MOD_IDENTIFIER;
3195 } else if (unsmob_score (sid)) {
3196 Score *score = new Score (*unsmob_score (sid));
3197 *destination = score->self_scm ();
3199 score->unprotect ();
3200 return SCORE_IDENTIFIER;
3201 } else if (Music *mus = unsmob_music (sid)) {
3202 mus = mus->clone ();
3203 *destination = mus->self_scm ();
3204 unsmob_music (*destination)->
3205 set_property ("origin", make_input (last_input_));
3207 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
3211 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3212 } else if (unsmob_pitch (sid)) {
3213 *destination = unsmob_pitch (sid)->smobbed_copy ();
3214 return PITCH_IDENTIFIER;
3215 } else if (unsmob_duration (sid)) {
3216 *destination = unsmob_duration (sid)->smobbed_copy ();
3217 return DURATION_IDENTIFIER;
3218 } else if (unsmob_output_def (sid)) {
3219 Output_def *p = unsmob_output_def (sid);
3222 *destination = p->self_scm ();
3224 return OUTPUT_DEF_IDENTIFIER;
3225 } else if (Text_interface::is_markup (sid)) {
3227 if (is_lyric_state ())
3228 return LYRIC_MARKUP_IDENTIFIER;
3229 return MARKUP_IDENTIFIER;
3230 } else if (Text_interface::is_markup_list (sid)) {
3232 return MARKUPLIST_IDENTIFIER;
3239 get_next_unique_context_id ()
3241 return scm_from_locale_string ("$uniqueContextId");
3246 get_next_unique_lyrics_context_id ()
3248 static int new_context_count;
3250 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3251 return scm_from_locale_string (s);
3254 SCM check_scheme_arg (Lily_parser *my_lily_parser, Input loc,
3255 SCM arg, SCM args, SCM pred)
3257 args = scm_cons (arg, args);
3258 if (scm_is_true (scm_call_1 (pred, arg)))
3260 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3261 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3262 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3266 SCM loc_on_music (Input loc, SCM arg)
3268 if (Music *m = unsmob_music (arg))
3272 return m->unprotect ();
3278 is_regular_identifier (SCM id)
3280 string str = ly_scm2string (id);
3281 char const *s = str.c_str ();
3290 v = v && isalnum (*s);
3297 make_music_with_input (SCM name, Input where)
3299 Music *m = make_music_by_name (name);
3300 m->set_spot (where);
3305 make_simple_markup (SCM a)
3313 return t && t == 1 << intlog2 (t);
3317 set_music_properties (Music *p, SCM a)
3319 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3320 p->set_property (scm_caar (k), scm_cdar (k));
3325 make_chord_step (int step, Rational alter)
3328 alter += FLAT_ALTERATION;
3332 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3333 return m.smobbed_copy ();
3338 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
3340 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3341 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
3345 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
3347 Lily_parser *pars = (Lily_parser*) v;
3348 Lily_lexer *lex = pars->lexer_;
3350 lex->lexval_ = (void*) s;
3352 lex->prepare_for_next_token ();
3353 return lex->yylex ();