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, _ ("not a context mod"));
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, _ ("not a context mod"));
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 ());
1217 | context_mod_list embedded_scm {
1218 Context_mod *md = unsmob_context_mod ($2);
1220 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1222 PARSER->parser_error (@2, _ ("not a context mod"));
1231 /* Music that can be parsed without lookahead */
1234 | complex_music_prefix closed_music
1236 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1243 | grouped_music_list
1247 simultaneous_music { $$ = $1; }
1248 | sequential_music { $$ = $1; }
1251 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1252 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1253 and this rule returns the reversed list of arguments. */
1255 function_arglist_skip:
1256 function_arglist_common
1257 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1259 $$ = scm_cons ($1, $3);
1260 } %prec FUNCTION_ARGLIST
1261 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1263 $$ = scm_cons ($1, $3);
1264 } %prec FUNCTION_ARGLIST
1265 | EXPECT_SCM EXPECT_DURATION function_arglist_skip
1267 $$ = scm_cons ($1, $3);
1268 } %prec FUNCTION_ARGLIST
1272 function_arglist_nonbackup:
1273 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1274 $$ = scm_cons ($4, $3);
1276 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1277 $$ = scm_cons ($4, $3);
1279 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1281 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1283 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1285 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1287 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1289 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1291 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1293 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1295 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1297 SCM n = scm_difference ($5, SCM_UNDEFINED);
1298 if (scm_is_true (scm_call_1 ($2, n)))
1299 $$ = scm_cons (n, $3);
1301 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1302 t->set_property ("digit", $5);
1303 $$ = t->unprotect ();
1304 if (scm_is_true (scm_call_1 ($2, $$)))
1305 $$ = scm_cons ($$, $3);
1307 $$ = check_scheme_arg (PARSER, @4, n, $3, $2);
1311 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1313 $$ = check_scheme_arg (PARSER, @4,
1314 scm_difference ($5, SCM_UNDEFINED),
1317 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1319 $$ = check_scheme_arg (PARSER, @4,
1320 scm_difference ($5, SCM_UNDEFINED),
1326 function_arglist_keep:
1327 function_arglist_common
1328 | function_arglist_backup
1331 function_arglist_closed_keep:
1332 function_arglist_closed_common
1333 | function_arglist_backup
1336 function_arglist_backup:
1337 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1339 if (scm_is_true (scm_call_1 ($2, $4)))
1341 $$ = scm_cons ($4, $3);
1343 $$ = scm_cons (loc_on_music (@3, $1), $3);
1344 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1347 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1349 if (scm_is_true (scm_call_1 ($2, $4)))
1351 $$ = scm_cons ($4, $3);
1353 $$ = scm_cons (loc_on_music (@3, $1), $3);
1354 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1357 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1359 // There is no point interpreting a lyrics string as
1360 // an event, since we don't allow music possibly
1361 // followed by durations or postevent into closed
1362 // music, and we only accept closed music in optional
1363 // arguments at the moment. If this changes, more
1364 // complex schemes might become interesting here as
1365 // well: see how we do this at the mandatory argument
1367 if (scm_is_true (scm_call_1 ($2, $4)))
1368 $$ = scm_cons ($4, $3);
1370 $$ = scm_cons (loc_on_music (@3, $1), $3);
1371 MYBACKUP (LYRICS_STRING, $4, @4);
1374 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1376 if (scm_is_true (scm_call_1 ($2, $4)))
1379 MYREPARSE (@4, $2, UNSIGNED, $4);
1381 $$ = scm_cons (loc_on_music (@3, $1), $3);
1382 MYBACKUP (UNSIGNED, $4, @4);
1385 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1387 if (scm_is_true (scm_call_1 ($2, $4)))
1390 MYREPARSE (@4, $2, REAL, $4);
1392 $$ = scm_cons (loc_on_music (@3, $1), $3);
1393 MYBACKUP (REAL, $4, @4);
1396 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1398 if (scm_is_true (scm_call_1 ($2, $4)))
1400 $$ = scm_cons ($4, $3);
1402 $$ = scm_cons (loc_on_music (@3, $1), $3);
1403 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1406 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1408 if (scm_is_true (scm_call_1 ($2, $4)))
1410 $$ = scm_cons ($4, $3);
1412 $$ = scm_cons (loc_on_music (@3, $1), $3);
1413 MYBACKUP (FRACTION, $4, @4);
1416 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1418 SCM n = scm_difference ($5, SCM_UNDEFINED);
1419 if (scm_is_true (scm_call_1 ($2, n))) {
1421 MYREPARSE (@5, $2, REAL, n);
1423 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1424 t->set_property ("digit", $5);
1425 $$ = t->unprotect ();
1426 if (scm_is_true (scm_call_1 ($2, $$)))
1427 $$ = scm_cons ($$, $3);
1429 $$ = scm_cons (loc_on_music (@3, $1), $3);
1430 MYBACKUP (UNSIGNED, $5, @5);
1431 PARSER->lexer_->push_extra_token ('-');
1436 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1438 SCM n = scm_difference ($5, SCM_UNDEFINED);
1439 if (scm_is_true (scm_call_1 ($2, n))) {
1440 MYREPARSE (@5, $2, REAL, n);
1443 MYBACKUP (REAL, n, @5);
1446 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1448 SCM n = scm_difference ($5, SCM_UNDEFINED);
1449 if (scm_is_true (scm_call_1 ($2, n))) {
1450 $$ = scm_cons (n, $3);
1452 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1455 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1457 $$ = scm_cons ($4, $3);
1459 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1461 $$ = scm_cons ($4, $3);
1463 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1465 $$ = scm_cons ($1, $3);
1466 MYBACKUP(0, SCM_UNDEFINED, @3);
1468 | function_arglist_backup REPARSE embedded_scm_arg_closed
1470 $$ = check_scheme_arg (PARSER, @3,
1473 | function_arglist_backup REPARSE bare_number
1475 $$ = check_scheme_arg (PARSER, @3,
1478 | function_arglist_backup REPARSE fraction
1480 $$ = check_scheme_arg (PARSER, @3,
1486 function_arglist_common
1487 | function_arglist_nonbackup
1490 function_arglist_common:
1491 function_arglist_bare
1492 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1494 $$ = check_scheme_arg (PARSER, @3,
1497 | EXPECT_SCM function_arglist_closed_optional bare_number
1499 $$ = check_scheme_arg (PARSER, @3,
1502 | EXPECT_SCM function_arglist_closed_optional fraction
1504 $$ = check_scheme_arg (PARSER, @3,
1507 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1509 $$ = check_scheme_arg (PARSER, @3,
1512 | function_arglist_common_minus
1513 | function_arglist_common_lyric
1516 function_arglist_common_lyric:
1517 EXPECT_SCM function_arglist_optional lyric_element
1519 // We check how the predicate thinks about a lyrics
1520 // event or about a markup. If it accepts neither, we
1521 // backup the original token. Otherwise we commit to
1522 // taking the token. Depending on what the predicate
1523 // is willing to accept, we interpret as a string, as
1524 // a lyric event, or ambiguously (meaning that if
1525 // something looking like a duration or post event
1526 // follows, we take the event, otherwise the string).
1527 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1528 PARSER->default_duration_.smobbed_copy ());
1529 if (scm_is_true (scm_call_1 ($1, $3)))
1530 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1533 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1535 $$ = scm_cons ($3, $2);
1537 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1540 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1542 // This is going to flag a syntax error, we
1543 // know the predicate to be false.
1544 check_scheme_arg (PARSER, @3,
1548 | function_arglist_common_lyric REPARSE lyric_element_arg
1550 // This should never be false
1551 $$ = check_scheme_arg (PARSER, @3,
1556 function_arglist_common_minus:
1557 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1559 SCM n = scm_difference ($4, SCM_UNDEFINED);
1560 if (scm_is_true (scm_call_1 ($1, n))) {
1562 MYREPARSE (@4, $1, REAL, n);
1564 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1565 t->set_property ("digit", $4);
1566 $$ = t->unprotect ();
1567 if (scm_is_true (scm_call_1 ($1, $$)))
1568 $$ = scm_cons ($$, $2);
1570 $$ = check_scheme_arg (PARSER, @3, n, $2, $1);
1574 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1577 SCM n = scm_difference ($4, SCM_UNDEFINED);
1578 MYREPARSE (@4, $1, REAL, n);
1580 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1582 SCM n = scm_difference ($4, SCM_UNDEFINED);
1583 $$ = check_scheme_arg (PARSER, @4, n, $2, $1);
1585 | function_arglist_common_minus REPARSE bare_number
1587 $$ = check_scheme_arg (PARSER, @3, $3, $1, $2);
1591 function_arglist_closed:
1592 function_arglist_closed_common
1593 | function_arglist_nonbackup
1596 function_arglist_closed_common:
1597 function_arglist_bare
1598 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1600 $$ = check_scheme_arg (PARSER, @3,
1603 | EXPECT_SCM function_arglist_closed_optional bare_number
1605 $$ = check_scheme_arg (PARSER, @3,
1608 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1610 SCM n = scm_difference ($4, SCM_UNDEFINED);
1611 if (scm_is_true (scm_call_1 ($1, n))) {
1612 $$ = scm_cons (n, $2);
1614 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1615 t->set_property ("digit", $4);
1616 $$ = t->unprotect ();
1617 if (scm_is_true (scm_call_1 ($1, $$)))
1618 $$ = scm_cons ($$, $2);
1620 $$ = check_scheme_arg (PARSER, @3, n, $2, $1);
1624 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1626 $$ = check_scheme_arg (PARSER, @3,
1627 scm_difference ($4, SCM_UNDEFINED),
1630 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1632 $$ = check_scheme_arg (PARSER, @3,
1633 scm_difference ($4, SCM_UNDEFINED),
1636 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1638 $$ = check_scheme_arg (PARSER, @3,
1641 | EXPECT_SCM function_arglist_closed_optional fraction
1643 $$ = check_scheme_arg (PARSER, @3,
1646 | EXPECT_SCM function_arglist_optional lyric_element
1648 $$ = check_scheme_arg (PARSER, @3,
1653 function_arglist_optional:
1654 function_arglist_keep %prec FUNCTION_ARGLIST
1655 | function_arglist_backup BACKUP
1656 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1658 $$ = scm_cons ($1, $3);
1660 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1662 $$ = scm_cons ($1, $3);
1666 function_arglist_closed_optional:
1667 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1668 | function_arglist_backup BACKUP
1669 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1671 $$ = scm_cons ($1, $3);
1673 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1675 $$ = scm_cons ($1, $3);
1679 embedded_scm_closed:
1681 | scm_function_call_closed
1684 embedded_scm_arg_closed:
1685 embedded_scm_bare_arg
1686 | scm_function_call_closed
1690 scm_function_call_closed:
1691 SCM_FUNCTION function_arglist_closed {
1692 $$ = MAKE_SYNTAX ("music-function", @$,
1694 } %prec FUNCTION_ARGLIST
1697 function_arglist_bare:
1698 EXPECT_NO_MORE_ARGS {
1701 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1702 $$ = scm_cons ($3, $2);
1704 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1705 $$ = scm_cons ($3, $2);
1707 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1708 $$ = scm_cons ($1, $3);
1710 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1711 $$ = scm_cons ($1, $3);
1713 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1714 $$ = scm_cons ($1, $3);
1718 music_function_call:
1719 MUSIC_FUNCTION function_arglist {
1720 $$ = MAKE_SYNTAX ("music-function", @$,
1727 /**/ { $$ = SCM_EOL; }
1728 | '=' simple_string {
1735 | repeated_music { $$ = $1; }
1736 | re_rhythmed_music { $$ = $1; }
1737 | complex_music_prefix music
1739 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1743 complex_music_prefix:
1744 CONTEXT 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_F);
1751 | NEWCONTEXT simple_string optional_id optional_context_mod {
1752 Context_mod *ctxmod = unsmob_context_mod ($4);
1755 mods = ctxmod->get_mods ();
1756 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1761 mode_changing_head grouped_music_list {
1762 if ($1 == ly_symbol2scm ("chords"))
1764 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1770 PARSER->lexer_->pop_state ();
1772 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1773 Context_mod *ctxmod = unsmob_context_mod ($2);
1776 mods = ctxmod->get_mods ();
1777 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1778 if ($1 == ly_symbol2scm ("ChordNames"))
1780 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1782 PARSER->lexer_->pop_state ();
1788 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1789 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1791 $$ = ly_symbol2scm ("notes");
1795 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1796 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1798 $$ = ly_symbol2scm ("drums");
1801 PARSER->lexer_->push_figuredbass_state ();
1803 $$ = ly_symbol2scm ("figures");
1806 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1807 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1808 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1809 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1810 $$ = ly_symbol2scm ("chords");
1814 { PARSER->lexer_->push_lyric_state ();
1815 $$ = ly_symbol2scm ("lyrics");
1819 mode_changing_head_with_context:
1821 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1822 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1824 $$ = ly_symbol2scm ("DrumStaff");
1827 PARSER->lexer_->push_figuredbass_state ();
1829 $$ = ly_symbol2scm ("FiguredBass");
1832 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1833 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1834 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1835 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1836 $$ = ly_symbol2scm ("ChordNames");
1839 { PARSER->lexer_->push_lyric_state ();
1840 $$ = ly_symbol2scm ("Lyrics");
1845 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1848 /* Can also use music at the expensive of two S/Rs similar to
1849 \repeat \alternative */
1850 PARSER->lexer_->pop_state ();
1852 $$ = scm_cons ($3, SCM_EOL);
1854 | new_lyrics ADDLYRICS {
1855 PARSER->lexer_->push_lyric_state ();
1857 PARSER->lexer_->pop_state ();
1858 $$ = scm_cons ($4, $1);
1863 composite_music new_lyrics {
1864 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1866 | LYRICSTO simple_string {
1867 PARSER->lexer_->push_lyric_state ();
1869 PARSER->lexer_->pop_state ();
1870 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1875 CHANGE STRING '=' STRING {
1876 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1881 property_path_revved:
1882 embedded_scm_closed {
1883 $$ = scm_cons ($1, SCM_EOL);
1885 | property_path_revved embedded_scm_closed {
1886 $$ = scm_cons ($2, $1);
1891 property_path_revved {
1892 $$ = scm_reverse_x ($1, SCM_EOL);
1898 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1899 scm_string_to_symbol ($1), $3);
1901 | UNSET simple_string {
1902 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1903 scm_string_to_symbol ($2));
1905 | OVERRIDE simple_string property_path '=' scalar {
1906 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1907 scm_string_to_symbol ($2), $5),
1910 | REVERT simple_string embedded_scm {
1911 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1912 scm_string_to_symbol ($2), $3);
1917 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1918 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1920 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1921 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1922 | DENIES { $$ = ly_symbol2scm ("denies"); }
1924 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1925 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1926 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1927 | NAME { $$ = ly_symbol2scm ("context-name"); }
1931 property_operation { $$ = $1; }
1932 | context_def_mod STRING {
1933 $$ = scm_list_2 ($1, $2);
1935 | context_def_mod embedded_scm {
1936 if (ly_symbol2scm ("consists") != $1)
1939 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1943 $$ = scm_list_2 ($1, $2);
1950 if (!is_regular_identifier ($1))
1952 @$.error (_("Grob name should be alphanumeric"));
1955 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1956 scm_string_to_symbol ($1));
1958 | simple_string '.' simple_string {
1959 $$ = scm_list_2 (scm_string_to_symbol ($1),
1960 scm_string_to_symbol ($3));
1964 simple_music_property_def:
1965 OVERRIDE context_prop_spec property_path '=' scalar {
1966 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1967 ly_symbol2scm ("OverrideProperty"),
1972 | REVERT context_prop_spec embedded_scm {
1973 $$ = scm_list_4 (scm_car ($2),
1974 ly_symbol2scm ("RevertProperty"),
1978 | SET context_prop_spec '=' scalar {
1979 $$ = scm_list_4 (scm_car ($2),
1980 ly_symbol2scm ("PropertySet"),
1984 | UNSET context_prop_spec {
1985 $$ = scm_list_3 (scm_car ($2),
1986 ly_symbol2scm ("PropertyUnset"),
1992 simple_music_property_def {
1993 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (PARSER->self_scm (), make_input (@$), $1));
2001 | STRING_IDENTIFIER {
2004 | string '+' string {
2005 $$ = scm_string_append (scm_list_2 ($1, $3));
2009 simple_string: STRING {
2015 | STRING_IDENTIFIER {
2027 embedded_scm_arg_closed
2034 /* TODO: Create a special case that avoids the creation of
2035 EventChords around simple_elements that have no post_events?
2037 simple_chord_elements post_events {
2038 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2041 /* why is this giving wrong start location? -ns
2043 i.set_location (@1, @2);
2044 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2046 | CHORD_REPETITION optional_notemode_duration post_events {
2048 i.set_location (@1, @3);
2049 $$ = MAKE_SYNTAX ("repetition-chord", i,
2050 PARSER->lexer_->chord_repetition_.last_chord_,
2051 PARSER->lexer_->chord_repetition_.repetition_function_,
2052 $2, scm_reverse_x ($3, SCM_EOL));
2054 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2056 i.set_location (@1, @3);
2057 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2058 scm_reverse_x ($3, SCM_EOL));
2061 /* note chord elements are memorized into
2062 PARSER->lexer_->chord_repetition_ so that the chord repetition
2063 mechanism copy them when a chord repetition symbol is found
2065 | note_chord_element {
2066 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
2072 chord_body optional_notemode_duration post_events
2074 Music *m = unsmob_music ($1);
2075 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2076 SCM es = m->get_property ("elements");
2077 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2079 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2080 unsmob_music (scm_car (s))->set_property ("duration", dur);
2081 es = ly_append2 (es, postevs);
2083 m-> set_property ("elements", es);
2085 $$ = m->self_scm ();
2090 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2092 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2096 chord_body_elements:
2097 /* empty */ { $$ = SCM_EOL; }
2098 | chord_body_elements chord_body_element {
2099 $$ = scm_cons ($2, $1);
2104 pitch exclamations questions octave_check post_events
2111 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2112 n->set_property ("pitch", $1);
2114 n->set_property ("cautionary", SCM_BOOL_T);
2115 if (ex % 2 || q % 2)
2116 n->set_property ("force-accidental", SCM_BOOL_T);
2118 if (scm_is_pair (post)) {
2119 SCM arts = scm_reverse_x (post, SCM_EOL);
2120 n->set_property ("articulations", arts);
2122 if (scm_is_number (check))
2124 int q = scm_to_int (check);
2125 n->set_property ("absolute-octave", scm_from_int (q-1));
2128 $$ = n->unprotect ();
2130 | DRUM_PITCH post_events {
2131 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2132 n->set_property ("drum-type", $1);
2134 if (scm_is_pair ($2)) {
2135 SCM arts = scm_reverse_x ($2, SCM_EOL);
2136 n->set_property ("articulations", arts);
2138 $$ = n->unprotect ();
2140 | music_function_chord_body
2143 /* We can't accept a music argument, not even a closed one,
2144 * immediately before chord_body_elements, otherwise a function \fun
2145 * with a signature of two music arguments can't be sorted out
2146 * properly in a construct like
2147 * <\fun { c } \fun { c } c>
2148 * The second call could be interpreted either as a chord constituent
2149 * or a music expression.
2152 music_function_chord_body_arglist:
2153 function_arglist_bare
2154 | EXPECT_SCM music_function_chord_body_arglist embedded_scm_chord_body
2156 $$ = check_scheme_arg (PARSER, @3,
2161 embedded_scm_chord_body:
2162 embedded_scm_bare_arg
2163 | SCM_FUNCTION music_function_chord_body_arglist {
2164 $$ = MAKE_SYNTAX ("music-function", @$,
2170 | chord_body_element
2173 music_function_chord_body:
2174 MUSIC_FUNCTION music_function_chord_body_arglist {
2175 $$ = MAKE_SYNTAX ("music-function", @$,
2180 // Event functions may only take closed arglists, otherwise it would
2181 // not be clear whether a following postevent should be associated
2182 // with the last argument of the event function or with the expression
2183 // for which the function call acts itself as event.
2185 music_function_event:
2186 MUSIC_FUNCTION function_arglist_closed {
2187 $$ = MAKE_SYNTAX ("music-function", @$,
2192 event_function_event:
2193 EVENT_FUNCTION function_arglist_closed {
2194 $$ = MAKE_SYNTAX ("music-function", @$,
2204 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2205 m->set_property ("span-direction", scm_from_int (START));
2206 $$ = m->unprotect();
2209 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2210 m->set_property ("span-direction", scm_from_int (STOP));
2211 $$ = m->unprotect ();
2214 $$ = MAKE_SYNTAX ("voice-separator", @$);
2217 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
2219 Music *m = unsmob_music (pipe);
2224 $$ = m->unprotect ();
2227 $$ = MAKE_SYNTAX ("bar-check", @$);
2234 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2246 | post_events post_event {
2247 unsmob_music ($2)->set_spot (@2);
2248 $$ = scm_cons ($2, $$);
2252 post_event_nofinger:
2253 direction_less_event {
2256 | script_dir music_function_event {
2260 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2264 if (!PARSER->lexer_->is_lyric_state ())
2265 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2266 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2269 if (!PARSER->lexer_->is_lyric_state ())
2270 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2271 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2273 | script_dir direction_reqd_event {
2276 Music *m = unsmob_music ($2);
2277 m->set_property ("direction", scm_from_int ($1));
2281 | script_dir direction_less_event {
2284 Music *m = unsmob_music ($2);
2285 m->set_property ("direction", scm_from_int ($1));
2289 | string_number_event
2293 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2298 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2309 string_number_event:
2311 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2312 s->set_property ("string-number", scm_from_int ($1));
2313 $$ = s->unprotect ();
2317 direction_less_char:
2319 $$ = ly_symbol2scm ("bracketOpenSymbol");
2322 $$ = ly_symbol2scm ("bracketCloseSymbol");
2325 $$ = ly_symbol2scm ("tildeSymbol");
2328 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2331 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2334 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2337 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2340 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2343 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2346 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2350 direction_less_event:
2351 direction_less_char {
2352 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
2354 if (unsmob_music (predefd))
2356 m = unsmob_music (predefd)->clone ();
2361 m = MY_MAKE_MUSIC ("Music", @$);
2363 $$ = m->unprotect ();
2365 | EVENT_IDENTIFIER {
2369 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2370 a->set_property ("tremolo-type", scm_from_int ($1));
2371 $$ = a->unprotect ();
2373 | event_function_event
2376 direction_reqd_event:
2380 | script_abbreviation {
2381 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2382 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2383 if (scm_is_string (s))
2384 a->set_property ("articulation-type", s);
2385 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
2386 $$ = a->unprotect ();
2391 /**/ { $$ = SCM_EOL; }
2392 | '=' { $$ = scm_from_int (0); }
2393 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2394 | '=' sup_quotes { $$ = scm_from_int ($2); }
2419 | NOTENAME_PITCH sup_quotes {
2420 Pitch p = *unsmob_pitch ($1);
2421 p = p.transposed (Pitch ($2,0,0));
2422 $$ = p.smobbed_copy ();
2424 | NOTENAME_PITCH sub_quotes {
2425 Pitch p =* unsmob_pitch ($1);
2426 p = p.transposed (Pitch (-$2,0,0));
2427 $$ = p.smobbed_copy ();
2439 | TONICNAME_PITCH sup_quotes {
2440 Pitch p = *unsmob_pitch ($1);
2441 p = p.transposed (Pitch ($2,0,0));
2442 $$ = p.smobbed_copy ();
2444 | TONICNAME_PITCH sub_quotes {
2445 Pitch p = *unsmob_pitch ($1);
2447 p = p.transposed (Pitch (-$2,0,0));
2448 $$ = p.smobbed_copy ();
2459 pitch_also_in_chords:
2466 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2467 t->set_property ("text", $1);
2468 $$ = t->unprotect ();
2471 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2472 t->set_property ("text",
2473 make_simple_markup ($1));
2474 $$ = t->unprotect ();
2480 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2481 t->set_property ("digit", $1);
2482 $$ = t->unprotect ();
2486 script_abbreviation:
2488 $$ = scm_from_locale_string ("Hat");
2491 $$ = scm_from_locale_string ("Plus");
2494 $$ = scm_from_locale_string ("Dash");
2497 $$ = scm_from_locale_string ("Bar");
2500 $$ = scm_from_locale_string ("Larger");
2503 $$ = scm_from_locale_string ("Dot");
2506 $$ = scm_from_locale_string ("Underscore");
2513 | '-' { $$ = CENTER; }
2517 multiplied_duration {
2522 optional_notemode_duration:
2524 Duration dd = PARSER->default_duration_;
2525 $$ = dd.smobbed_copy ();
2527 | multiplied_duration {
2529 PARSER->default_duration_ = *unsmob_duration ($$);
2534 bare_unsigned dots {
2536 if (!is_duration ($1))
2537 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
2541 $$ = Duration (len, $2).smobbed_copy ();
2543 | DURATION_IDENTIFIER dots {
2544 Duration *d = unsmob_duration ($1);
2545 Duration k (d->duration_log (), d->dot_count () + $2);
2546 k = k.compressed (d->factor ());
2552 multiplied_duration:
2556 | multiplied_duration '*' bare_unsigned {
2557 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2559 | multiplied_duration '*' FRACTION {
2560 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2562 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2567 FRACTION { $$ = $1; }
2568 | UNSIGNED '/' UNSIGNED {
2569 $$ = scm_cons ($1, $3);
2586 | ':' bare_unsigned {
2587 if (!is_duration ($2))
2588 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2594 UNSIGNED { $$ = $1; }
2595 | STRING { $$ = $1; }
2596 | full_markup { $$ = $1; }
2599 figured_bass_alteration:
2600 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2601 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2602 | '!' { $$ = scm_from_int (0); }
2607 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2608 $$ = bfr->unprotect ();
2611 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2612 $$ = bfr->self_scm ();
2614 if (scm_is_number ($1))
2615 bfr->set_property ("figure", $1);
2616 else if (Text_interface::is_markup ($1))
2617 bfr->set_property ("text", $1);
2623 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2625 | bass_figure figured_bass_alteration {
2626 Music *m = unsmob_music ($1);
2627 if (scm_to_double ($2)) {
2628 SCM salter = m->get_property ("alteration");
2629 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2630 m->set_property ("alteration",
2631 scm_sum (alter, $2));
2633 m->set_property ("alteration", scm_from_int (0));
2636 | bass_figure figured_bass_modification {
2637 Music *m = unsmob_music ($1);
2638 if ($2 == ly_symbol2scm ("plus"))
2640 m->set_property ("augmented", SCM_BOOL_T);
2642 else if ($2 == ly_symbol2scm ("slash"))
2644 m->set_property ("diminished", SCM_BOOL_T);
2646 else if ($2 == ly_symbol2scm ("exclamation"))
2648 m->set_property ("no-continuation", SCM_BOOL_T);
2650 else if ($2 == ly_symbol2scm ("backslash"))
2652 m->set_property ("augmented-slash", SCM_BOOL_T);
2658 figured_bass_modification:
2660 $$ = ly_symbol2scm ("plus");
2663 $$ = ly_symbol2scm ("exclamation");
2666 $$ = ly_symbol2scm ("slash");
2669 $$ = ly_symbol2scm ("backslash");
2679 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2687 | figure_list br_bass_figure {
2688 $$ = scm_cons ($2, $1);
2693 FIGURE_OPEN figure_list FIGURE_CLOSE {
2694 $$ = scm_reverse_x ($2, SCM_EOL);
2705 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2706 if (!PARSER->lexer_->is_note_state ())
2707 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2711 n = MY_MAKE_MUSIC ("RestEvent", @$);
2713 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2715 n->set_property ("pitch", $1);
2716 n->set_property ("duration", $5);
2718 if (scm_is_number ($4))
2720 int q = scm_to_int ($4);
2721 n->set_property ("absolute-octave", scm_from_int (q-1));
2725 n->set_property ("cautionary", SCM_BOOL_T);
2726 if ($2 % 2 || $3 % 2)
2727 n->set_property ("force-accidental", SCM_BOOL_T);
2729 $$ = n->unprotect ();
2731 | DRUM_PITCH optional_notemode_duration {
2732 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2733 n->set_property ("duration", $2);
2734 n->set_property ("drum-type", $1);
2736 $$ = n->unprotect ();
2738 | RESTNAME optional_notemode_duration {
2740 if (ly_scm2string ($1) == "s") {
2742 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2745 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2748 ev->set_property ("duration", $2);
2749 $$ = ev->unprotect ();
2753 simple_chord_elements:
2755 $$ = scm_list_1 ($1);
2758 if (!PARSER->lexer_->is_chord_state ())
2759 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2762 | figure_spec optional_notemode_duration {
2763 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2765 unsmob_music (scm_car (s))->set_property ("duration", $2);
2782 | lyric_element multiplied_duration post_events {
2783 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2784 $$ = MAKE_SYNTAX ("event-chord", @$,
2785 scm_cons (lyric_event,
2786 scm_reverse_x ($3, SCM_EOL)));
2788 | lyric_element post_event post_events {
2790 MAKE_SYNTAX ("lyric-event", @$, $1,
2791 PARSER->default_duration_.smobbed_copy ());
2792 $$ = MAKE_SYNTAX ("event-chord", @$,
2793 scm_cons2 (lyric_event, $2,
2794 scm_reverse_x ($3, SCM_EOL)));
2797 | LYRIC_ELEMENT optional_notemode_duration post_events {
2798 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2799 $$ = MAKE_SYNTAX ("event-chord", @$,
2800 scm_cons (lyric_event,
2801 scm_reverse_x ($3, SCM_EOL)));
2806 lyric_element_music:
2807 lyric_element optional_notemode_duration post_events {
2808 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2809 $$ = MAKE_SYNTAX ("event-chord", @$,
2810 scm_cons (lyric_event,
2811 scm_reverse_x ($3, SCM_EOL)));
2816 steno_tonic_pitch optional_notemode_duration {
2817 $$ = make_chord_elements ($1, $2, SCM_EOL);
2819 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2820 SCM its = scm_reverse_x ($4, SCM_EOL);
2821 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2829 | chord_items chord_item {
2830 $$ = scm_cons ($2, $$);
2836 $$ = ly_symbol2scm ("chord-colon");
2839 $$ = ly_symbol2scm ("chord-caret");
2841 | CHORD_SLASH steno_tonic_pitch {
2842 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2844 | CHORD_BASS steno_tonic_pitch {
2845 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2854 $$ = scm_reverse_x ($1, SCM_EOL);
2862 step_number { $$ = scm_cons ($1, SCM_EOL); }
2863 | step_numbers '.' step_number {
2864 $$ = scm_cons ($3, $$);
2870 $$ = make_chord_step ($1, 0);
2872 | bare_unsigned '+' {
2873 $$ = make_chord_step ($1, SHARP_ALTERATION);
2875 | bare_unsigned CHORD_MINUS {
2876 $$ = make_chord_step ($1, FLAT_ALTERATION);
2882 $$ = scm_from_int ($1);
2884 | bare_unsigned '~' bare_unsigned {
2885 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2892 TODO: should deprecate in favor of Scheme?
2896 number_expression '+' number_term {
2897 $$ = scm_sum ($1, $3);
2899 | number_expression '-' number_term {
2900 $$ = scm_difference ($1, $3);
2909 | number_factor '*' number_factor {
2910 $$ = scm_product ($1, $3);
2912 | number_factor '/' number_factor {
2913 $$ = scm_divide ($1, $3);
2918 '-' number_factor { /* %prec UNARY_MINUS */
2919 $$ = scm_difference ($2, SCM_UNDEFINED);
2927 | UNSIGNED NUMBER_IDENTIFIER {
2928 $$ = scm_product ($1, $2)
2930 | REAL NUMBER_IDENTIFIER {
2931 $$ = scm_product ($1, $2)
2943 $$ = scm_to_int ($1);
2954 | exclamations '!' { $$ ++; }
2959 | questions '?' { $$ ++; }
2963 This should be done more dynamically if possible.
2967 LYRIC_MARKUP_IDENTIFIER {
2971 { PARSER->lexer_->push_markup_state (); }
2974 PARSER->lexer_->pop_state ();
2979 MARKUPLIST_IDENTIFIER {
2983 { PARSER->lexer_->push_markup_state (); }
2986 PARSER->lexer_->pop_state ();
2995 { PARSER->lexer_->push_markup_state (); }
2998 PARSER->lexer_->pop_state ();
3004 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3006 | markup_head_1_list simple_markup {
3007 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3017 if (Text_interface::is_markup ($1))
3018 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3019 else if (Text_interface::is_markup_list ($1))
3020 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3022 PARSER->parser_error (@1, _ ("not a markup"));
3023 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3030 MARKUPLIST_IDENTIFIER {
3033 | markup_composed_list {
3036 | markup_braced_list {
3039 | markup_command_list {
3040 $$ = scm_list_1 ($1);
3042 | markup_scm MARKUPLIST_IDENTIFIER
3048 markup_composed_list:
3049 markup_head_1_list markup_braced_list {
3050 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3056 '{' markup_braced_list_body '}' {
3057 $$ = scm_reverse_x ($2, SCM_EOL);
3061 markup_braced_list_body:
3062 /* empty */ { $$ = SCM_EOL; }
3063 | markup_braced_list_body markup {
3064 $$ = scm_cons ($2, $1);
3066 | markup_braced_list_body markup_list {
3067 $$ = scm_reverse_x ($2, $1);
3071 markup_command_list:
3072 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3073 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3077 markup_command_basic_arguments:
3078 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3079 $$ = scm_cons ($3, $2);
3081 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3082 $$ = check_scheme_arg (PARSER, @3, $3, $2, $1);
3084 | EXPECT_NO_MORE_ARGS {
3089 markup_command_list_arguments:
3090 markup_command_basic_arguments { $$ = $1; }
3091 | EXPECT_MARKUP markup_command_list_arguments markup {
3092 $$ = scm_cons ($3, $2);
3097 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3098 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3103 markup_head_1_item {
3104 $$ = scm_list_1 ($1);
3106 | markup_head_1_list markup_head_1_item {
3107 $$ = scm_cons ($2, $1);
3113 $$ = make_simple_markup ($1);
3115 | MARKUP_IDENTIFIER {
3118 | LYRIC_MARKUP_IDENTIFIER {
3121 | STRING_IDENTIFIER {
3125 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
3126 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
3127 } '{' score_body '}' {
3129 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3131 PARSER->lexer_->pop_state ();
3133 | MARKUP_FUNCTION markup_command_basic_arguments {
3134 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3136 | markup_scm MARKUP_IDENTIFIER
3143 markup_head_1_list simple_markup {
3144 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3145 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3155 Lily_parser::set_yydebug (bool x)
3161 Lily_parser::do_yyparse ()
3163 yyparse ((void*)this);
3172 It is a little strange to have this function in this file, but
3173 otherwise, we have to import music classes into the lexer.
3177 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3179 if (scm_is_string (sid)) {
3181 return STRING_IDENTIFIER;
3182 } else if (unsmob_book (sid)) {
3183 Book *book = unsmob_book (sid)->clone ();
3184 *destination = book->self_scm ();
3187 return BOOK_IDENTIFIER;
3188 } else if (scm_is_number (sid)) {
3190 return NUMBER_IDENTIFIER;
3191 } else if (unsmob_context_def (sid)) {
3192 Context_def *def= unsmob_context_def (sid)->clone ();
3194 *destination = def->self_scm ();
3197 return CONTEXT_DEF_IDENTIFIER;
3198 } else if (unsmob_context_mod (sid)) {
3199 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3201 return CONTEXT_MOD_IDENTIFIER;
3202 } else if (unsmob_score (sid)) {
3203 Score *score = new Score (*unsmob_score (sid));
3204 *destination = score->self_scm ();
3206 score->unprotect ();
3207 return SCORE_IDENTIFIER;
3208 } else if (Music *mus = unsmob_music (sid)) {
3209 mus = mus->clone ();
3210 *destination = mus->self_scm ();
3211 unsmob_music (*destination)->
3212 set_property ("origin", make_input (last_input_));
3214 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
3218 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3219 } else if (unsmob_pitch (sid)) {
3220 *destination = unsmob_pitch (sid)->smobbed_copy ();
3221 return PITCH_IDENTIFIER;
3222 } else if (unsmob_duration (sid)) {
3223 *destination = unsmob_duration (sid)->smobbed_copy ();
3224 return DURATION_IDENTIFIER;
3225 } else if (unsmob_output_def (sid)) {
3226 Output_def *p = unsmob_output_def (sid);
3229 *destination = p->self_scm ();
3231 return OUTPUT_DEF_IDENTIFIER;
3232 } else if (Text_interface::is_markup (sid)) {
3234 if (is_lyric_state ())
3235 return LYRIC_MARKUP_IDENTIFIER;
3236 return MARKUP_IDENTIFIER;
3237 } else if (Text_interface::is_markup_list (sid)) {
3239 return MARKUPLIST_IDENTIFIER;
3246 get_next_unique_context_id ()
3248 return scm_from_locale_string ("$uniqueContextId");
3253 get_next_unique_lyrics_context_id ()
3255 static int new_context_count;
3257 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3258 return scm_from_locale_string (s);
3261 SCM check_scheme_arg (Lily_parser *my_lily_parser, Input loc,
3262 SCM arg, SCM args, SCM pred)
3264 args = scm_cons (arg, args);
3265 if (scm_is_true (scm_call_1 (pred, arg)))
3267 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3268 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3269 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3273 SCM loc_on_music (Input loc, SCM arg)
3275 if (Music *m = unsmob_music (arg))
3279 return m->unprotect ();
3285 is_regular_identifier (SCM id)
3287 string str = ly_scm2string (id);
3288 char const *s = str.c_str ();
3297 v = v && isalnum (*s);
3304 make_music_with_input (SCM name, Input where)
3306 Music *m = make_music_by_name (name);
3307 m->set_spot (where);
3312 make_simple_markup (SCM a)
3320 return t && t == 1 << intlog2 (t);
3324 set_music_properties (Music *p, SCM a)
3326 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3327 p->set_property (scm_caar (k), scm_cdar (k));
3332 make_chord_step (int step, Rational alter)
3335 alter += FLAT_ALTERATION;
3339 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3340 return m.smobbed_copy ();
3345 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
3347 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3348 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
3352 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
3354 Lily_parser *pars = (Lily_parser*) v;
3355 Lily_lexer *lex = pars->lexer_;
3357 lex->lexval_ = (void*) s;
3359 lex->prepare_for_next_token ();
3360 return lex->yylex ();