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 get_first_context_id (SCM type, Music *m);
212 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
213 SCM make_chord_step (int step, Rational alter);
214 SCM make_simple_markup (SCM a);
215 bool is_duration (int t);
216 bool is_regular_identifier (SCM id);
217 bool ly_input_procedure_p (SCM x);
218 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
219 void set_music_properties (Music *p, SCM a);
223 /* The third option is an alias that will be used to display the
224 syntax error. Bison CVS now correctly handles backslash escapes.
226 FIXME: Bison needs to translate some of these, eg, STRING.
230 /* Keyword tokens with plain escaped name. */
231 %token ACCEPTS "\\accepts"
232 %token ADDLYRICS "\\addlyrics"
233 %token ALIAS "\\alias"
234 %token ALTERNATIVE "\\alternative"
236 %token BOOKPART "\\bookpart"
237 %token CHANGE "\\change"
238 %token CHORDMODE "\\chordmode"
239 %token CHORDS "\\chords"
240 %token CONSISTS "\\consists"
241 %token CONTEXT "\\context"
242 %token DEFAULT "\\default"
243 %token DEFAULTCHILD "\\defaultchild"
244 %token DENIES "\\denies"
245 %token DESCRIPTION "\\description"
246 %token DRUMMODE "\\drummode"
247 %token DRUMS "\\drums"
248 %token FIGUREMODE "\\figuremode"
249 %token FIGURES "\\figures"
250 %token GROBDESCRIPTIONS "\\grobdescriptions"
251 %token HEADER "\\header"
252 %token INVALID "\\version-error"
253 %token LAYOUT "\\layout"
254 %token LYRICMODE "\\lyricmode"
255 %token LYRICS "\\lyrics"
256 %token LYRICSTO "\\lyricsto"
257 %token MARKUP "\\markup"
258 %token MARKUPLIST "\\markuplist"
261 %token NOTEMODE "\\notemode"
262 %token OVERRIDE "\\override"
263 %token PAPER "\\paper"
264 %token REMOVE "\\remove"
265 %token REPEAT "\\repeat"
267 %token REVERT "\\revert"
268 %token SCORE "\\score"
269 %token SEQUENTIAL "\\sequential"
271 %token SIMULTANEOUS "\\simultaneous"
272 %token TEMPO "\\tempo"
274 %token UNSET "\\unset"
277 /* Keyword token exceptions. */
278 %token NEWCONTEXT "\\new"
281 /* Other string tokens. */
283 %token CHORD_BASS "/+"
284 %token CHORD_CARET "^"
285 %token CHORD_COLON ":"
286 %token CHORD_MINUS "-"
287 %token CHORD_SLASH "/"
288 %token ANGLE_OPEN "<"
289 %token ANGLE_CLOSE ">"
290 %token DOUBLE_ANGLE_OPEN "<<"
291 %token DOUBLE_ANGLE_CLOSE ">>"
292 %token E_BACKSLASH "\\"
293 %token E_ANGLE_CLOSE "\\>"
294 %token E_CHAR "\\C[haracter]"
296 %token E_EXCLAMATION "\\!"
297 %token E_BRACKET_OPEN "\\["
299 %token E_BRACKET_CLOSE "\\]"
300 %token E_ANGLE_OPEN "\\<"
306 If we give names, Bison complains.
308 %token FIGURE_CLOSE /* "\\>" */
309 %token FIGURE_OPEN /* "\\<" */
310 %token FIGURE_SPACE "_"
313 %token CHORDMODIFIERS
315 %token MULTI_MEASURE_REST
318 %token <i> E_UNSIGNED
319 %token <scm> UNSIGNED
321 /* Artificial tokens, for more generic function syntax */
322 %token <i> EXPECT_MARKUP "markup?"
323 %token <i> EXPECT_PITCH "ly:pitch?"
324 %token <i> EXPECT_DURATION "ly:duration?"
325 %token <scm> EXPECT_SCM "scheme?"
326 %token <scm> BACKUP "(backed-up?)"
327 %token <scm> REPARSE "(reparsed?)"
328 %token <i> EXPECT_MARKUP_LIST "markup-list?"
329 %token <scm> EXPECT_OPTIONAL "optional?"
330 /* After the last argument. */
331 %token <i> EXPECT_NO_MORE_ARGS;
333 /* An artificial token for parsing embedded Lilypond */
334 %token <i> EMBEDDED_LILY "#{"
336 %token <scm> BOOK_IDENTIFIER
337 %token <scm> CHORDMODIFIER_PITCH
338 %token <scm> CHORD_MODIFIER
339 %token <scm> CHORD_REPETITION
340 %token <scm> CONTEXT_DEF_IDENTIFIER
341 %token <scm> CONTEXT_MOD_IDENTIFIER
342 %token <scm> DRUM_PITCH
343 %token <scm> PITCH_IDENTIFIER
344 %token <scm> DURATION_IDENTIFIER
345 %token <scm> EVENT_IDENTIFIER
346 %token <scm> EVENT_FUNCTION
347 %token <scm> FRACTION
348 %token <scm> LYRICS_STRING
349 %token <scm> LYRIC_ELEMENT
350 %token <scm> LYRIC_ELEMENT_P
351 %token <scm> LYRIC_MARKUP_IDENTIFIER
352 %token <scm> MARKUP_FUNCTION
353 %token <scm> MARKUP_LIST_FUNCTION
354 %token <scm> MARKUP_IDENTIFIER
355 %token <scm> MARKUPLIST_IDENTIFIER
356 %token <scm> MUSIC_FUNCTION
357 %token <scm> MUSIC_IDENTIFIER
358 %token <scm> NOTENAME_PITCH
359 %token <scm> NUMBER_IDENTIFIER
360 %token <scm> OUTPUT_DEF_IDENTIFIER
362 %token <scm> RESTNAME
363 %token <scm> SCM_FUNCTION
364 %token <scm> SCM_IDENTIFIER
365 %token <scm> SCM_TOKEN
366 %token <scm> SCORE_IDENTIFIER
368 %token <scm> STRING_IDENTIFIER
369 %token <scm> TONICNAME_PITCH
372 %type <book> book_block
373 %type <book> book_body
374 %type <book> bookpart_block
375 %type <book> bookpart_body
377 %type <i> bare_unsigned
378 %type <scm> figured_bass_alteration
380 %type <i> exclamations
381 %type <i> optional_rest
386 %type <i> tremolo_type
389 %type <scm> composite_music
390 %type <scm> grouped_music_list
391 %type <scm> braced_music_list
392 %type <scm> closed_music
394 %type <scm> music_bare
395 %type <scm> music_arg
396 %type <scm> complex_music
397 %type <scm> complex_music_prefix
398 %type <scm> mode_changed_music
399 %type <scm> repeated_music
400 %type <scm> sequential_music
401 %type <scm> simple_music
402 %type <scm> simultaneous_music
403 %type <scm> chord_body
404 %type <scm> chord_body_element
405 %type <scm> command_element
406 %type <scm> command_event
407 %type <scm> context_modification
408 %type <scm> context_change
409 %type <scm> direction_less_event
410 %type <scm> direction_reqd_event
411 %type <scm> embedded_lilypond
412 %type <scm> event_chord
413 %type <scm> fingering
414 %type <scm> gen_text_def
415 %type <scm> music_property_def
416 %type <scm> note_chord_element
417 %type <scm> post_event
418 %type <scm> post_event_nofinger
419 %type <scm> re_rhythmed_music
420 %type <scm> simple_element
421 %type <scm> simple_music_property_def
422 %type <scm> start_symbol
423 %type <scm> string_number_event
424 %type <scm> tempo_event
426 %type <outputdef> output_def_body
427 %type <outputdef> output_def_head
428 %type <outputdef> output_def_head_with_mode_switch
429 %type <outputdef> output_def
430 %type <outputdef> paper_block
432 %type <scm> music_function_call
433 %type <scm> music_list
434 %type <scm> assignment_id
435 %type <scm> bare_number
436 %type <scm> bare_number_closed
437 %type <scm> unsigned_number
438 %type <scm> bass_figure
439 %type <scm> figured_bass_modification
440 %type <scm> br_bass_figure
441 %type <scm> bass_number
442 %type <scm> chord_body_elements
443 %type <scm> chord_item
444 %type <scm> chord_items
445 %type <scm> chord_separator
446 %type <scm> context_def_mod
447 %type <scm> context_def_spec_block
448 %type <scm> context_def_spec_body
449 %type <scm> context_mod
450 %type <scm> context_mod_list
451 %type <scm> context_prop_spec
452 %type <scm> direction_less_char
453 %type <scm> duration_length
454 %type <scm> embedded_scm
455 %type <scm> embedded_scm_arg
456 %type <scm> embedded_scm_arg_closed
457 %type <scm> embedded_scm_bare
458 %type <scm> embedded_scm_bare_arg
459 %type <scm> embedded_scm_closed
460 %type <scm> embedded_scm_chord_body
461 %type <scm> event_function_event
462 %type <scm> figure_list
463 %type <scm> figure_spec
465 %type <scm> full_markup
466 %type <scm> full_markup_list
467 %type <scm> function_arglist
468 %type <scm> function_arglist_optional
469 %type <scm> function_arglist_backup
470 %type <scm> function_arglist_nonbackup
471 %type <scm> function_arglist_skip
472 %type <scm> function_arglist_bare
473 %type <scm> function_arglist_closed
474 %type <scm> function_arglist_closed_optional
475 %type <scm> function_arglist_common
476 %type <scm> function_arglist_common_lyric
477 %type <scm> function_arglist_common_minus
478 %type <scm> function_arglist_closed_common
479 %type <scm> function_arglist_keep
480 %type <scm> function_arglist_closed_keep
481 %type <scm> identifier_init
483 %type <scm> lilypond_header
484 %type <scm> lilypond_header_body
485 %type <scm> lyric_element
486 %type <scm> lyric_element_arg
487 %type <scm> lyric_element_music
488 %type <scm> lyric_markup
490 %type <scm> markup_braced_list
491 %type <scm> markup_braced_list_body
492 %type <scm> markup_composed_list
493 %type <scm> markup_command_list
494 %type <scm> markup_command_list_arguments
495 %type <scm> markup_command_basic_arguments
496 %type <scm> markup_head_1_item
497 %type <scm> markup_head_1_list
498 %type <scm> markup_list
499 %type <scm> markup_top
500 %type <scm> mode_changing_head
501 %type <scm> mode_changing_head_with_context
502 %type <scm> multiplied_duration
503 %type <scm> music_function_event
504 %type <scm> music_function_chord_body
505 %type <scm> music_function_chord_body_arglist
506 %type <scm> new_chord
507 %type <scm> new_lyrics
508 %type <scm> number_expression
509 %type <scm> number_factor
510 %type <scm> number_term
511 %type <scm> octave_check
512 %type <scm> optional_context_mod
513 %type <scm> optional_id
514 %type <scm> optional_notemode_duration
516 %type <scm> pitch_also_in_chords
517 %type <scm> post_events
518 %type <scm> property_operation
519 %type <scm> property_path property_path_revved
521 %type <scm> scalar_closed
522 %type <scm> scm_function_call
523 %type <scm> scm_function_call_closed
524 %type <scm> script_abbreviation
525 %type <scm> simple_chord_elements
526 %type <scm> simple_markup
527 %type <scm> simple_string
528 %type <scm> steno_duration
529 %type <scm> steno_pitch
530 %type <scm> steno_tonic_pitch
531 %type <scm> step_number
532 %type <scm> step_numbers
534 %type <scm> tempo_range
536 %type <score> score_block
537 %type <score> score_body
542 /* We don't assign precedence to / and *, because we might need varied
543 prec levels in different prods */
552 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
553 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
554 } embedded_lilypond {
555 PARSER->lexer_->pop_state ();
556 PARSER->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
560 lilypond: /* empty */ { }
561 | lilypond toplevel_expression {
563 | lilypond assignment {
566 PARSER->error_level_ = 1;
569 PARSER->error_level_ = 1;
576 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
580 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
581 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
586 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
587 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
588 bookpart->unprotect ();
593 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
594 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
598 Music *music = unsmob_music ($1);
599 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
600 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
603 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
604 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
607 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
608 scm_call_2 (proc, PARSER->self_scm (), $1);
612 Output_def * od = $1;
614 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
615 id = ly_symbol2scm ("$defaultpaper");
616 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
617 id = ly_symbol2scm ("$defaultmidi");
618 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
619 id = ly_symbol2scm ("$defaultlayout");
621 PARSER->lexer_->set_identifier (id, od->self_scm ());
629 $$ = PARSER->lexer_->eval_scm ($1);
634 embedded_scm_bare_arg:
640 | context_modification
643 $$ = $1->self_scm ();
646 | context_def_spec_block
649 $$ = $1->self_scm ();
654 $$ = $1->self_scm ();
659 $$ = $1->self_scm ();
664 /* The generic version may end in music, or not */
672 embedded_scm_bare_arg
678 SCM_FUNCTION function_arglist {
679 $$ = MAKE_SYNTAX ("music-function", @$,
687 $$ = MAKE_SYNTAX ("void-music", @$);
690 | music music music_list {
691 $$ = MAKE_SYNTAX ("sequential-music", @$,
692 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
695 PARSER->error_level_ = 1;
697 | INVALID embedded_lilypond {
698 PARSER->error_level_ = 1;
703 lilypond_header_body:
705 $$ = get_header (PARSER);
706 PARSER->lexer_->add_scope ($$);
708 | lilypond_header_body assignment {
714 HEADER '{' lilypond_header_body '}' {
715 $$ = PARSER->lexer_->remove_scope ();
724 | LYRICS_STRING { $$ = $1; }
728 assignment_id '=' identifier_init {
729 PARSER->lexer_->set_identifier ($1, $3);
731 | assignment_id property_path '=' identifier_init {
732 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
733 PARSER->lexer_->set_identifier (path, $4);
736 TODO: devise standard for protection in parser.
738 The parser stack lives on the C-stack, which means that
739 all objects can be unprotected as soon as they're here.
749 $$ = $1->self_scm ();
753 $$ = $1->self_scm ();
757 $$ = $1->self_scm ();
761 $$ = $1->self_scm ();
764 | context_def_spec_block {
768 /* Hack: Create event-chord around standalone events.
769 Prevents the identifier from being interpreted as a post-event. */
770 Music *mus = unsmob_music ($1);
771 bool is_event = mus &&
772 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
777 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
779 | post_event_nofinger {
782 | number_expression {
797 | context_modification {
802 context_def_spec_block:
803 CONTEXT '{' context_def_spec_body '}'
809 context_def_spec_body:
811 $$ = Context_def::make_scm ();
812 unsmob_context_def ($$)->origin ()->set_spot (@$);
814 | CONTEXT_DEF_IDENTIFIER {
816 unsmob_context_def ($$)->origin ()->set_spot (@$);
818 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
819 Context_def*td = unsmob_context_def ($$);
821 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
822 SCM tag = scm_caar (p);
824 /* TODO: should make new tag "grob-definition" ? */
825 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
826 tag, scm_cons (scm_cdar (p), SCM_EOL)));
829 | context_def_spec_body context_mod {
830 unsmob_context_def ($$)->add_context_mod ($2);
832 | context_def_spec_body context_modification {
833 Context_def *td = unsmob_context_def ($$);
834 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
835 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
836 td->add_context_mod (scm_car (m));
844 BOOK '{' book_body '}' {
847 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
852 * Use 'handlers' like for toplevel-* stuff?
853 * grok \layout and \midi? */
857 init_papers (PARSER);
858 $$->origin ()->set_spot (@$);
859 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
860 $$->paper_->unprotect ();
861 push_paper (PARSER, $$->paper_);
862 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
863 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
864 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
865 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
868 $$ = unsmob_book ($1);
870 $$->origin ()->set_spot (@$);
871 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
873 | book_body paper_block {
876 set_paper (PARSER, $2);
878 | book_body bookpart_block {
880 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
881 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
882 bookpart->unprotect ();
884 | book_body score_block {
886 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
887 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
890 | book_body composite_music {
891 Music *music = unsmob_music ($2);
892 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
893 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
895 | book_body full_markup {
896 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
897 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
899 | book_body full_markup_list {
900 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
901 scm_call_2 (proc, $$->self_scm (), $2);
903 | book_body lilypond_header {
906 | book_body embedded_scm { }
909 $$->scores_ = SCM_EOL;
910 $$->bookparts_ = SCM_EOL;
915 BOOKPART '{' bookpart_body '}' {
917 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
924 $$->origin ()->set_spot (@$);
925 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
928 $$ = unsmob_book ($1);
930 $$->origin ()->set_spot (@$);
931 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
933 | bookpart_body paper_block {
937 | bookpart_body score_block {
939 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
940 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
943 | bookpart_body composite_music {
944 Music *music = unsmob_music ($2);
945 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
946 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
948 | bookpart_body full_markup {
949 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
950 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
952 | bookpart_body full_markup_list {
953 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
954 scm_call_2 (proc, $$->self_scm (), $2);
956 | bookpart_body lilypond_header {
959 | bookpart_body embedded_scm { }
960 | bookpart_body error {
962 $$->scores_ = SCM_EOL;
967 SCORE '{' score_body '}' {
975 SCM scorify = ly_lily_module_constant ("scorify-music");
976 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
978 // pass ownernship to C++ again.
979 $$ = unsmob_score (score);
981 $$->origin ()->set_spot (@$);
984 $$ = unsmob_score ($1);
986 $$->origin ()->set_spot (@$);
988 | score_body lilypond_header {
991 | score_body output_def {
992 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
994 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
999 $$->add_output_def ($2);
1003 | score_body error {
1004 $$->error_found_ = true;
1016 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1018 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
1020 $$ = get_paper (PARSER);
1027 output_def_body '}' {
1030 PARSER->lexer_->remove_scope ();
1031 PARSER->lexer_->pop_state ();
1037 $$ = get_paper (PARSER);
1038 $$->input_origin_ = @$;
1039 PARSER->lexer_->add_scope ($$->scope_);
1042 Output_def *p = get_midi (PARSER);
1044 PARSER->lexer_->add_scope (p->scope_);
1047 Output_def *p = get_layout (PARSER);
1049 PARSER->lexer_->add_scope (p->scope_);
1054 output_def_head_with_mode_switch:
1056 PARSER->lexer_->push_initial_state ();
1062 output_def_head_with_mode_switch '{' {
1064 $$->input_origin_.set_spot (@$);
1066 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1069 Output_def *o = unsmob_output_def ($3);
1070 o->input_origin_.set_spot (@$);
1073 PARSER->lexer_->remove_scope ();
1074 PARSER->lexer_->add_scope (o->scope_);
1076 | output_def_body assignment {
1079 | output_def_body context_def_spec_block {
1080 assign_context_def ($$, $2);
1082 | output_def_body error {
1088 TEMPO steno_duration '=' tempo_range {
1089 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1091 | TEMPO scalar_closed steno_duration '=' tempo_range {
1092 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1095 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1100 The representation of a list is reversed to have efficient append. */
1106 | music_list music {
1107 $$ = scm_cons ($2, $1);
1109 | music_list embedded_scm {
1112 | music_list error {
1113 Music *m = MY_MAKE_MUSIC("Music", @$);
1115 m->set_property ("error-found", SCM_BOOL_T);
1116 $$ = scm_cons (m->self_scm (), $1);
1117 m->unprotect (); /* UGH */
1124 $$ = scm_reverse_x ($2, SCM_EOL);
1129 | lyric_element_music
1130 | composite_music %prec COMPOSITE
1135 | composite_music %prec COMPOSITE
1139 REPEAT simple_string unsigned_number music
1141 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1143 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1145 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1150 SEQUENTIAL braced_music_list {
1151 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1153 | braced_music_list {
1154 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1159 SIMULTANEOUS braced_music_list {
1160 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1162 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1163 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1169 | music_property_def
1173 context_modification:
1174 WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1176 PARSER->lexer_->pop_state ();
1179 | WITH CONTEXT_MOD_IDENTIFIER
1183 | CONTEXT_MOD_IDENTIFIER
1189 optional_context_mod:
1193 | context_modification
1201 $$ = Context_mod ().smobbed_copy ();
1203 | context_mod_list context_mod {
1204 unsmob_context_mod ($1)->add_context_mod ($2);
1206 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1207 Context_mod *md = unsmob_context_mod ($2);
1209 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1218 /* Music that can be parsed without lookahead */
1221 | complex_music_prefix closed_music
1223 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1230 | grouped_music_list
1234 simultaneous_music { $$ = $1; }
1235 | sequential_music { $$ = $1; }
1238 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1239 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1240 and this rule returns the reversed list of arguments. */
1242 function_arglist_skip:
1243 function_arglist_common
1244 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1246 $$ = scm_cons ($1, $3);
1247 } %prec FUNCTION_ARGLIST
1248 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1250 $$ = scm_cons ($1, $3);
1251 } %prec FUNCTION_ARGLIST
1252 | EXPECT_SCM EXPECT_DURATION function_arglist_skip
1254 $$ = scm_cons ($1, $3);
1255 } %prec FUNCTION_ARGLIST
1259 function_arglist_nonbackup:
1260 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1261 $$ = scm_cons ($4, $3);
1263 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1264 $$ = scm_cons ($4, $3);
1266 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1268 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1270 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1272 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1274 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1276 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1278 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1280 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1282 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1284 SCM n = scm_difference ($5, SCM_UNDEFINED);
1285 if (scm_is_true (scm_call_1 ($2, n)))
1286 $$ = scm_cons (n, $3);
1288 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1289 t->set_property ("digit", $5);
1290 $$ = t->unprotect ();
1291 if (scm_is_true (scm_call_1 ($2, $$)))
1292 $$ = scm_cons ($$, $3);
1294 $$ = check_scheme_arg (PARSER, @4, n, $3, $2);
1298 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1300 $$ = check_scheme_arg (PARSER, @4,
1301 scm_difference ($5, SCM_UNDEFINED),
1304 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1306 $$ = check_scheme_arg (PARSER, @4,
1307 scm_difference ($5, SCM_UNDEFINED),
1313 function_arglist_keep:
1314 function_arglist_common
1315 | function_arglist_backup
1318 function_arglist_closed_keep:
1319 function_arglist_closed_common
1320 | function_arglist_backup
1323 function_arglist_backup:
1324 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1326 if (scm_is_true (scm_call_1 ($2, $4)))
1328 $$ = scm_cons ($4, $3);
1330 $$ = scm_cons (loc_on_music (@3, $1), $3);
1331 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1334 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1336 if (scm_is_true (scm_call_1 ($2, $4)))
1338 $$ = scm_cons ($4, $3);
1340 $$ = scm_cons (loc_on_music (@3, $1), $3);
1341 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1344 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1346 // There is no point interpreting a lyrics string as
1347 // an event, since we don't allow music possibly
1348 // followed by durations or postevent into closed
1349 // music, and we only accept closed music in optional
1350 // arguments at the moment. If this changes, more
1351 // complex schemes might become interesting here as
1352 // well: see how we do this at the mandatory argument
1354 if (scm_is_true (scm_call_1 ($2, $4)))
1355 $$ = scm_cons ($3, $2);
1357 $$ = scm_cons (loc_on_music (@3, $1), $3);
1358 MYBACKUP (LYRIC_MARKUP_IDENTIFIER, $4, @4);
1361 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1363 if (scm_is_true (scm_call_1 ($2, $4)))
1366 MYREPARSE (@4, $2, UNSIGNED, $4);
1368 $$ = scm_cons (loc_on_music (@3, $1), $3);
1369 MYBACKUP (UNSIGNED, $4, @4);
1372 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1374 if (scm_is_true (scm_call_1 ($2, $4)))
1377 MYREPARSE (@4, $2, REAL, $4);
1379 $$ = scm_cons (loc_on_music (@3, $1), $3);
1380 MYBACKUP (REAL, $4, @4);
1383 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1385 if (scm_is_true (scm_call_1 ($2, $4)))
1387 $$ = scm_cons ($4, $3);
1389 $$ = scm_cons (loc_on_music (@3, $1), $3);
1390 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1393 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1395 if (scm_is_true (scm_call_1 ($2, $4)))
1397 $$ = scm_cons ($4, $3);
1399 $$ = scm_cons (loc_on_music (@3, $1), $3);
1400 MYBACKUP (FRACTION, $4, @4);
1403 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1405 SCM n = scm_difference ($5, SCM_UNDEFINED);
1406 if (scm_is_true (scm_call_1 ($2, n))) {
1408 MYREPARSE (@5, $2, REAL, n);
1410 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1411 t->set_property ("digit", $5);
1412 $$ = t->unprotect ();
1413 if (scm_is_true (scm_call_1 ($2, $$)))
1414 $$ = scm_cons ($$, $3);
1416 $$ = scm_cons (loc_on_music (@3, $1), $3);
1417 MYBACKUP (UNSIGNED, $5, @5);
1418 PARSER->lexer_->push_extra_token ('-');
1423 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1425 SCM n = scm_difference ($5, SCM_UNDEFINED);
1426 if (scm_is_true (scm_call_1 ($2, n))) {
1427 MYREPARSE (@5, $2, REAL, n);
1430 MYBACKUP (REAL, n, @5);
1433 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1435 SCM n = scm_difference ($5, SCM_UNDEFINED);
1436 if (scm_is_true (scm_call_1 ($2, n))) {
1437 $$ = scm_cons (n, $3);
1439 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1442 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1444 $$ = scm_cons ($4, $3);
1446 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1448 $$ = scm_cons ($4, $3);
1450 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1452 $$ = scm_cons ($1, $3);
1453 MYBACKUP(0, SCM_UNDEFINED, @3);
1455 | function_arglist_backup REPARSE embedded_scm_arg_closed
1457 $$ = check_scheme_arg (PARSER, @3,
1460 | function_arglist_backup REPARSE bare_number
1462 $$ = check_scheme_arg (PARSER, @3,
1465 | function_arglist_backup REPARSE fraction
1467 $$ = check_scheme_arg (PARSER, @3,
1473 function_arglist_common
1474 | function_arglist_nonbackup
1477 function_arglist_common:
1478 function_arglist_bare
1479 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1481 $$ = check_scheme_arg (PARSER, @3,
1484 | EXPECT_SCM function_arglist_closed_optional bare_number
1486 $$ = check_scheme_arg (PARSER, @3,
1489 | EXPECT_SCM function_arglist_closed_optional fraction
1491 $$ = check_scheme_arg (PARSER, @3,
1494 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1496 $$ = check_scheme_arg (PARSER, @3,
1499 | function_arglist_common_minus
1500 | function_arglist_common_lyric
1503 function_arglist_common_lyric:
1504 EXPECT_SCM function_arglist_optional lyric_element
1506 // We check how the predicate thinks about a lyrics
1507 // event or about a markup. If it accepts neither, we
1508 // backup the original token. Otherwise we commit to
1509 // taking the token. Depending on what the predicate
1510 // is willing to accept, we interpret as a string, as
1511 // a lyric event, or ambiguously (meaning that if
1512 // something looking like a duration or post event
1513 // follows, we take the event, otherwise the string).
1514 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1515 PARSER->default_duration_.smobbed_copy ());
1516 if (scm_is_true (scm_call_1 ($1, $3)))
1517 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1520 MYREPARSE (@3, $1, LYRIC_ELEMENT_P, $3);
1522 $$ = scm_cons ($3, $2);
1524 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1527 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1529 // This is going to flag a syntax error, we
1530 // know the predicate to be false.
1531 check_scheme_arg (PARSER, @3,
1535 | function_arglist_common_lyric REPARSE lyric_element_arg
1537 // This should never be false
1538 $$ = check_scheme_arg (PARSER, @3,
1543 function_arglist_common_minus:
1544 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1546 SCM n = scm_difference ($4, SCM_UNDEFINED);
1547 if (scm_is_true (scm_call_1 ($1, n))) {
1549 MYREPARSE (@4, $1, REAL, n);
1551 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1552 t->set_property ("digit", $4);
1553 $$ = t->unprotect ();
1554 if (scm_is_true (scm_call_1 ($1, $$)))
1555 $$ = scm_cons ($$, $2);
1557 $$ = check_scheme_arg (PARSER, @3, n, $2, $1);
1561 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1564 SCM n = scm_difference ($4, SCM_UNDEFINED);
1565 MYREPARSE (@4, $1, REAL, n);
1567 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1569 SCM n = scm_difference ($4, SCM_UNDEFINED);
1570 $$ = check_scheme_arg (PARSER, @4, n, $2, $1);
1572 | function_arglist_common_minus REPARSE bare_number
1574 $$ = check_scheme_arg (PARSER, @3, $3, $1, $2);
1578 function_arglist_closed:
1579 function_arglist_closed_common
1580 | function_arglist_nonbackup
1583 function_arglist_closed_common:
1584 function_arglist_bare
1585 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1587 $$ = check_scheme_arg (PARSER, @3,
1590 | EXPECT_SCM function_arglist_closed_optional bare_number
1592 $$ = check_scheme_arg (PARSER, @3,
1595 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1597 SCM n = scm_difference ($4, SCM_UNDEFINED);
1598 if (scm_is_true (scm_call_1 ($1, n))) {
1599 $$ = scm_cons (n, $2);
1601 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1602 t->set_property ("digit", $4);
1603 $$ = t->unprotect ();
1604 if (scm_is_true (scm_call_1 ($1, $$)))
1605 $$ = scm_cons ($$, $2);
1607 $$ = check_scheme_arg (PARSER, @3, n, $2, $1);
1611 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1613 $$ = check_scheme_arg (PARSER, @3,
1614 scm_difference ($4, SCM_UNDEFINED),
1617 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1619 $$ = check_scheme_arg (PARSER, @3,
1620 scm_difference ($4, SCM_UNDEFINED),
1623 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1625 $$ = check_scheme_arg (PARSER, @3,
1628 | EXPECT_SCM function_arglist_closed_optional fraction
1630 $$ = check_scheme_arg (PARSER, @3,
1633 | EXPECT_SCM function_arglist_optional lyric_element
1635 $$ = check_scheme_arg (PARSER, @3,
1640 function_arglist_optional:
1641 function_arglist_keep %prec FUNCTION_ARGLIST
1642 | function_arglist_backup BACKUP
1643 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1645 $$ = scm_cons ($1, $3);
1647 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1649 $$ = scm_cons ($1, $3);
1653 function_arglist_closed_optional:
1654 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1655 | function_arglist_backup BACKUP
1656 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1658 $$ = scm_cons ($1, $3);
1660 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1662 $$ = scm_cons ($1, $3);
1666 embedded_scm_closed:
1668 | scm_function_call_closed
1671 embedded_scm_arg_closed:
1672 embedded_scm_bare_arg
1673 | scm_function_call_closed
1677 scm_function_call_closed:
1678 SCM_FUNCTION function_arglist_closed {
1679 $$ = MAKE_SYNTAX ("music-function", @$,
1681 } %prec FUNCTION_ARGLIST
1684 function_arglist_bare:
1685 EXPECT_NO_MORE_ARGS {
1688 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1689 $$ = scm_cons ($3, $2);
1691 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1692 $$ = scm_cons ($3, $2);
1694 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1695 $$ = scm_cons ($1, $3);
1697 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1698 $$ = scm_cons ($1, $3);
1700 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1701 $$ = scm_cons ($1, $3);
1705 music_function_call:
1706 MUSIC_FUNCTION function_arglist {
1707 $$ = MAKE_SYNTAX ("music-function", @$,
1714 /**/ { $$ = SCM_EOL; }
1715 | '=' simple_string {
1722 | repeated_music { $$ = $1; }
1723 | re_rhythmed_music { $$ = $1; }
1724 | complex_music_prefix music
1726 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1730 complex_music_prefix:
1731 CONTEXT simple_string optional_id optional_context_mod {
1732 Context_mod *ctxmod = unsmob_context_mod ($4);
1735 mods = ctxmod->get_mods ();
1736 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1738 | NEWCONTEXT simple_string optional_id optional_context_mod {
1739 Context_mod *ctxmod = unsmob_context_mod ($4);
1742 mods = ctxmod->get_mods ();
1743 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1748 mode_changing_head grouped_music_list {
1749 if ($1 == ly_symbol2scm ("chords"))
1751 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1757 PARSER->lexer_->pop_state ();
1759 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1760 Context_mod *ctxmod = unsmob_context_mod ($2);
1763 mods = ctxmod->get_mods ();
1764 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1765 if ($1 == ly_symbol2scm ("ChordNames"))
1767 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1769 PARSER->lexer_->pop_state ();
1775 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1776 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1778 $$ = ly_symbol2scm ("notes");
1782 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1783 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1785 $$ = ly_symbol2scm ("drums");
1788 PARSER->lexer_->push_figuredbass_state ();
1790 $$ = ly_symbol2scm ("figures");
1793 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1794 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1795 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1796 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1797 $$ = ly_symbol2scm ("chords");
1801 { PARSER->lexer_->push_lyric_state ();
1802 $$ = ly_symbol2scm ("lyrics");
1806 mode_changing_head_with_context:
1808 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1809 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1811 $$ = ly_symbol2scm ("DrumStaff");
1814 PARSER->lexer_->push_figuredbass_state ();
1816 $$ = ly_symbol2scm ("FiguredBass");
1819 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1820 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1821 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1822 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1823 $$ = ly_symbol2scm ("ChordNames");
1826 { PARSER->lexer_->push_lyric_state ();
1827 $$ = ly_symbol2scm ("Lyrics");
1832 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1835 /* Can also use music at the expensive of two S/Rs similar to
1836 \repeat \alternative */
1837 PARSER->lexer_->pop_state ();
1839 $$ = scm_cons ($3, SCM_EOL);
1841 | new_lyrics ADDLYRICS {
1842 PARSER->lexer_->push_lyric_state ();
1844 PARSER->lexer_->pop_state ();
1845 $$ = scm_cons ($4, $1);
1850 composite_music new_lyrics {
1851 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1853 | LYRICSTO simple_string {
1854 PARSER->lexer_->push_lyric_state ();
1856 PARSER->lexer_->pop_state ();
1857 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1862 CHANGE STRING '=' STRING {
1863 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1868 property_path_revved:
1869 embedded_scm_closed {
1870 $$ = scm_cons ($1, SCM_EOL);
1872 | property_path_revved embedded_scm_closed {
1873 $$ = scm_cons ($2, $1);
1878 property_path_revved {
1879 $$ = scm_reverse_x ($1, SCM_EOL);
1885 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1886 scm_string_to_symbol ($1), $3);
1888 | UNSET simple_string {
1889 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1890 scm_string_to_symbol ($2));
1892 | OVERRIDE simple_string property_path '=' scalar {
1893 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1894 scm_string_to_symbol ($2), $5),
1897 | REVERT simple_string embedded_scm {
1898 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1899 scm_string_to_symbol ($2), $3);
1904 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1905 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1907 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1908 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1909 | DENIES { $$ = ly_symbol2scm ("denies"); }
1911 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1912 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1913 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1914 | NAME { $$ = ly_symbol2scm ("context-name"); }
1918 property_operation { $$ = $1; }
1919 | context_def_mod STRING {
1920 $$ = scm_list_2 ($1, $2);
1922 | context_def_mod embedded_scm {
1923 if (ly_symbol2scm ("consists") != $1)
1926 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1930 $$ = scm_list_2 ($1, $2);
1937 if (!is_regular_identifier ($1))
1939 @$.error (_("Grob name should be alphanumeric"));
1942 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1943 scm_string_to_symbol ($1));
1945 | simple_string '.' simple_string {
1946 $$ = scm_list_2 (scm_string_to_symbol ($1),
1947 scm_string_to_symbol ($3));
1951 simple_music_property_def:
1952 OVERRIDE context_prop_spec property_path '=' scalar {
1953 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1954 ly_symbol2scm ("OverrideProperty"),
1959 | REVERT context_prop_spec embedded_scm {
1960 $$ = scm_list_4 (scm_car ($2),
1961 ly_symbol2scm ("RevertProperty"),
1965 | SET context_prop_spec '=' scalar {
1966 $$ = scm_list_4 (scm_car ($2),
1967 ly_symbol2scm ("PropertySet"),
1971 | UNSET context_prop_spec {
1972 $$ = scm_list_3 (scm_car ($2),
1973 ly_symbol2scm ("PropertyUnset"),
1979 simple_music_property_def {
1980 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (PARSER->self_scm (), make_input (@$), $1));
1988 | STRING_IDENTIFIER {
1991 | string '+' string {
1992 $$ = scm_string_append (scm_list_2 ($1, $3));
1996 simple_string: STRING {
2002 | STRING_IDENTIFIER {
2014 embedded_scm_arg_closed
2021 /* TODO: Create a special case that avoids the creation of
2022 EventChords around simple_elements that have no post_events?
2024 simple_chord_elements post_events {
2025 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2028 /* why is this giving wrong start location? -ns
2030 i.set_location (@1, @2);
2031 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2033 | CHORD_REPETITION optional_notemode_duration post_events {
2035 i.set_location (@1, @3);
2036 $$ = MAKE_SYNTAX ("repetition-chord", i,
2037 PARSER->lexer_->chord_repetition_.last_chord_,
2038 PARSER->lexer_->chord_repetition_.repetition_function_,
2039 $2, scm_reverse_x ($3, SCM_EOL));
2041 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2043 i.set_location (@1, @3);
2044 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2045 scm_reverse_x ($3, SCM_EOL));
2048 /* note chord elements are memorized into
2049 PARSER->lexer_->chord_repetition_ so that the chord repetition
2050 mechanism copy them when a chord repetition symbol is found
2052 | note_chord_element {
2053 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
2059 chord_body optional_notemode_duration post_events
2061 Music *m = unsmob_music ($1);
2062 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2063 SCM es = m->get_property ("elements");
2064 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2066 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2067 unsmob_music (scm_car (s))->set_property ("duration", dur);
2068 es = ly_append2 (es, postevs);
2070 m-> set_property ("elements", es);
2072 $$ = m->self_scm ();
2077 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2079 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2083 chord_body_elements:
2084 /* empty */ { $$ = SCM_EOL; }
2085 | chord_body_elements chord_body_element {
2086 $$ = scm_cons ($2, $1);
2091 pitch exclamations questions octave_check post_events
2098 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2099 n->set_property ("pitch", $1);
2101 n->set_property ("cautionary", SCM_BOOL_T);
2102 if (ex % 2 || q % 2)
2103 n->set_property ("force-accidental", SCM_BOOL_T);
2105 if (scm_is_pair (post)) {
2106 SCM arts = scm_reverse_x (post, SCM_EOL);
2107 n->set_property ("articulations", arts);
2109 if (scm_is_number (check))
2111 int q = scm_to_int (check);
2112 n->set_property ("absolute-octave", scm_from_int (q-1));
2115 $$ = n->unprotect ();
2117 | DRUM_PITCH post_events {
2118 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2119 n->set_property ("drum-type", $1);
2121 if (scm_is_pair ($2)) {
2122 SCM arts = scm_reverse_x ($2, SCM_EOL);
2123 n->set_property ("articulations", arts);
2125 $$ = n->unprotect ();
2127 | music_function_chord_body
2130 /* We can't accept a music argument, not even a closed one,
2131 * immediately before chord_body_elements, otherwise a function \fun
2132 * with a signature of two music arguments can't be sorted out
2133 * properly in a construct like
2134 * <\fun { c } \fun { c } c>
2135 * The second call could be interpreted either as a chord constituent
2136 * or a music expression.
2139 music_function_chord_body_arglist:
2140 function_arglist_bare
2141 | EXPECT_SCM music_function_chord_body_arglist embedded_scm_chord_body
2143 $$ = check_scheme_arg (PARSER, @3,
2148 embedded_scm_chord_body:
2149 embedded_scm_bare_arg
2150 | SCM_FUNCTION music_function_chord_body_arglist {
2151 $$ = MAKE_SYNTAX ("music-function", @$,
2157 | chord_body_element
2160 music_function_chord_body:
2161 MUSIC_FUNCTION music_function_chord_body_arglist {
2162 $$ = MAKE_SYNTAX ("music-function", @$,
2167 // Event functions may only take closed arglists, otherwise it would
2168 // not be clear whether a following postevent should be associated
2169 // with the last argument of the event function or with the expression
2170 // for which the function call acts itself as event.
2172 music_function_event:
2173 MUSIC_FUNCTION function_arglist_closed {
2174 $$ = MAKE_SYNTAX ("music-function", @$,
2179 event_function_event:
2180 EVENT_FUNCTION function_arglist_closed {
2181 $$ = MAKE_SYNTAX ("music-function", @$,
2191 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2192 m->set_property ("span-direction", scm_from_int (START));
2193 $$ = m->unprotect();
2196 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2197 m->set_property ("span-direction", scm_from_int (STOP));
2198 $$ = m->unprotect ();
2201 $$ = MAKE_SYNTAX ("voice-separator", @$);
2204 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
2206 Music *m = unsmob_music (pipe);
2211 $$ = m->unprotect ();
2214 $$ = MAKE_SYNTAX ("bar-check", @$);
2221 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2233 | post_events post_event {
2234 unsmob_music ($2)->set_spot (@2);
2235 $$ = scm_cons ($2, $$);
2239 post_event_nofinger:
2240 direction_less_event {
2243 | script_dir music_function_event {
2247 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2251 if (!PARSER->lexer_->is_lyric_state ())
2252 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2253 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2256 if (!PARSER->lexer_->is_lyric_state ())
2257 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2258 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2260 | script_dir direction_reqd_event {
2263 Music *m = unsmob_music ($2);
2264 m->set_property ("direction", scm_from_int ($1));
2268 | script_dir direction_less_event {
2271 Music *m = unsmob_music ($2);
2272 m->set_property ("direction", scm_from_int ($1));
2276 | string_number_event
2280 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2285 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2296 string_number_event:
2298 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2299 s->set_property ("string-number", scm_from_int ($1));
2300 $$ = s->unprotect ();
2304 direction_less_char:
2306 $$ = ly_symbol2scm ("bracketOpenSymbol");
2309 $$ = ly_symbol2scm ("bracketCloseSymbol");
2312 $$ = ly_symbol2scm ("tildeSymbol");
2315 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2318 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2321 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2324 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2327 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2330 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2333 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2337 direction_less_event:
2338 direction_less_char {
2339 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
2341 if (unsmob_music (predefd))
2343 m = unsmob_music (predefd)->clone ();
2348 m = MY_MAKE_MUSIC ("Music", @$);
2350 $$ = m->unprotect ();
2352 | EVENT_IDENTIFIER {
2356 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2357 a->set_property ("tremolo-type", scm_from_int ($1));
2358 $$ = a->unprotect ();
2360 | event_function_event
2363 direction_reqd_event:
2367 | script_abbreviation {
2368 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2369 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2370 if (scm_is_string (s))
2371 a->set_property ("articulation-type", s);
2372 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
2373 $$ = a->unprotect ();
2378 /**/ { $$ = SCM_EOL; }
2379 | '=' { $$ = scm_from_int (0); }
2380 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2381 | '=' sup_quotes { $$ = scm_from_int ($2); }
2406 | NOTENAME_PITCH sup_quotes {
2407 Pitch p = *unsmob_pitch ($1);
2408 p = p.transposed (Pitch ($2,0,0));
2409 $$ = p.smobbed_copy ();
2411 | NOTENAME_PITCH sub_quotes {
2412 Pitch p =* unsmob_pitch ($1);
2413 p = p.transposed (Pitch (-$2,0,0));
2414 $$ = p.smobbed_copy ();
2426 | TONICNAME_PITCH sup_quotes {
2427 Pitch p = *unsmob_pitch ($1);
2428 p = p.transposed (Pitch ($2,0,0));
2429 $$ = p.smobbed_copy ();
2431 | TONICNAME_PITCH sub_quotes {
2432 Pitch p = *unsmob_pitch ($1);
2434 p = p.transposed (Pitch (-$2,0,0));
2435 $$ = p.smobbed_copy ();
2446 pitch_also_in_chords:
2453 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2454 t->set_property ("text", $1);
2455 $$ = t->unprotect ();
2458 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2459 t->set_property ("text",
2460 make_simple_markup ($1));
2461 $$ = t->unprotect ();
2467 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2468 t->set_property ("digit", $1);
2469 $$ = t->unprotect ();
2473 script_abbreviation:
2475 $$ = scm_from_locale_string ("Hat");
2478 $$ = scm_from_locale_string ("Plus");
2481 $$ = scm_from_locale_string ("Dash");
2484 $$ = scm_from_locale_string ("Bar");
2487 $$ = scm_from_locale_string ("Larger");
2490 $$ = scm_from_locale_string ("Dot");
2493 $$ = scm_from_locale_string ("Underscore");
2500 | '-' { $$ = CENTER; }
2504 multiplied_duration {
2509 optional_notemode_duration:
2511 Duration dd = PARSER->default_duration_;
2512 $$ = dd.smobbed_copy ();
2514 | multiplied_duration {
2516 PARSER->default_duration_ = *unsmob_duration ($$);
2521 bare_unsigned dots {
2523 if (!is_duration ($1))
2524 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
2528 $$ = Duration (len, $2).smobbed_copy ();
2530 | DURATION_IDENTIFIER dots {
2531 Duration *d = unsmob_duration ($1);
2532 Duration k (d->duration_log (), d->dot_count () + $2);
2533 k = k.compressed (d->factor ());
2539 multiplied_duration:
2543 | multiplied_duration '*' bare_unsigned {
2544 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2546 | multiplied_duration '*' FRACTION {
2547 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2549 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2554 FRACTION { $$ = $1; }
2555 | UNSIGNED '/' UNSIGNED {
2556 $$ = scm_cons ($1, $3);
2573 | ':' bare_unsigned {
2574 if (!is_duration ($2))
2575 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2581 UNSIGNED { $$ = $1; }
2582 | STRING { $$ = $1; }
2583 | full_markup { $$ = $1; }
2586 figured_bass_alteration:
2587 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2588 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2589 | '!' { $$ = scm_from_int (0); }
2594 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2595 $$ = bfr->unprotect ();
2598 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2599 $$ = bfr->self_scm ();
2601 if (scm_is_number ($1))
2602 bfr->set_property ("figure", $1);
2603 else if (Text_interface::is_markup ($1))
2604 bfr->set_property ("text", $1);
2610 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2612 | bass_figure figured_bass_alteration {
2613 Music *m = unsmob_music ($1);
2614 if (scm_to_double ($2)) {
2615 SCM salter = m->get_property ("alteration");
2616 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2617 m->set_property ("alteration",
2618 scm_sum (alter, $2));
2620 m->set_property ("alteration", scm_from_int (0));
2623 | bass_figure figured_bass_modification {
2624 Music *m = unsmob_music ($1);
2625 if ($2 == ly_symbol2scm ("plus"))
2627 m->set_property ("augmented", SCM_BOOL_T);
2629 else if ($2 == ly_symbol2scm ("slash"))
2631 m->set_property ("diminished", SCM_BOOL_T);
2633 else if ($2 == ly_symbol2scm ("exclamation"))
2635 m->set_property ("no-continuation", SCM_BOOL_T);
2637 else if ($2 == ly_symbol2scm ("backslash"))
2639 m->set_property ("augmented-slash", SCM_BOOL_T);
2645 figured_bass_modification:
2647 $$ = ly_symbol2scm ("plus");
2650 $$ = ly_symbol2scm ("exclamation");
2653 $$ = ly_symbol2scm ("slash");
2656 $$ = ly_symbol2scm ("backslash");
2666 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2674 | figure_list br_bass_figure {
2675 $$ = scm_cons ($2, $1);
2680 FIGURE_OPEN figure_list FIGURE_CLOSE {
2681 $$ = scm_reverse_x ($2, SCM_EOL);
2692 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2693 if (!PARSER->lexer_->is_note_state ())
2694 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2698 n = MY_MAKE_MUSIC ("RestEvent", @$);
2700 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2702 n->set_property ("pitch", $1);
2703 n->set_property ("duration", $5);
2705 if (scm_is_number ($4))
2707 int q = scm_to_int ($4);
2708 n->set_property ("absolute-octave", scm_from_int (q-1));
2712 n->set_property ("cautionary", SCM_BOOL_T);
2713 if ($2 % 2 || $3 % 2)
2714 n->set_property ("force-accidental", SCM_BOOL_T);
2716 $$ = n->unprotect ();
2718 | DRUM_PITCH optional_notemode_duration {
2719 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2720 n->set_property ("duration", $2);
2721 n->set_property ("drum-type", $1);
2723 $$ = n->unprotect ();
2725 | RESTNAME optional_notemode_duration {
2727 if (ly_scm2string ($1) == "s") {
2729 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2732 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2735 ev->set_property ("duration", $2);
2736 $$ = ev->unprotect ();
2740 simple_chord_elements:
2742 $$ = scm_list_1 ($1);
2745 if (!PARSER->lexer_->is_chord_state ())
2746 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2749 | figure_spec optional_notemode_duration {
2750 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2752 unsmob_music (scm_car (s))->set_property ("duration", $2);
2770 | lyric_element multiplied_duration post_events {
2771 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2772 $$ = MAKE_SYNTAX ("event-chord", @$,
2773 scm_cons (lyric_event,
2774 scm_reverse_x ($3, SCM_EOL)));
2776 | lyric_element post_event post_events {
2778 MAKE_SYNTAX ("lyric-event", @$, $1,
2779 PARSER->default_duration_.smobbed_copy ());
2780 $$ = MAKE_SYNTAX ("event-chord", @$,
2781 scm_cons2 (lyric_event, $2,
2782 scm_reverse_x ($3, SCM_EOL)));
2785 | LYRIC_ELEMENT optional_notemode_duration post_events {
2786 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2787 $$ = MAKE_SYNTAX ("event-chord", @$,
2788 scm_cons (lyric_event,
2789 scm_reverse_x ($3, SCM_EOL)));
2794 lyric_element_music:
2795 lyric_element optional_notemode_duration post_events {
2796 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2797 $$ = MAKE_SYNTAX ("event-chord", @$,
2798 scm_cons (lyric_event,
2799 scm_reverse_x ($3, SCM_EOL)));
2804 steno_tonic_pitch optional_notemode_duration {
2805 $$ = make_chord_elements ($1, $2, SCM_EOL);
2807 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2808 SCM its = scm_reverse_x ($4, SCM_EOL);
2809 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2817 | chord_items chord_item {
2818 $$ = scm_cons ($2, $$);
2824 $$ = ly_symbol2scm ("chord-colon");
2827 $$ = ly_symbol2scm ("chord-caret");
2829 | CHORD_SLASH steno_tonic_pitch {
2830 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2832 | CHORD_BASS steno_tonic_pitch {
2833 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2842 $$ = scm_reverse_x ($1, SCM_EOL);
2850 step_number { $$ = scm_cons ($1, SCM_EOL); }
2851 | step_numbers '.' step_number {
2852 $$ = scm_cons ($3, $$);
2858 $$ = make_chord_step ($1, 0);
2860 | bare_unsigned '+' {
2861 $$ = make_chord_step ($1, SHARP_ALTERATION);
2863 | bare_unsigned CHORD_MINUS {
2864 $$ = make_chord_step ($1, FLAT_ALTERATION);
2870 $$ = scm_from_int ($1);
2872 | bare_unsigned '~' bare_unsigned {
2873 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2880 TODO: should deprecate in favor of Scheme?
2884 number_expression '+' number_term {
2885 $$ = scm_sum ($1, $3);
2887 | number_expression '-' number_term {
2888 $$ = scm_difference ($1, $3);
2897 | number_factor '*' number_factor {
2898 $$ = scm_product ($1, $3);
2900 | number_factor '/' number_factor {
2901 $$ = scm_divide ($1, $3);
2906 '-' number_factor { /* %prec UNARY_MINUS */
2907 $$ = scm_difference ($2, SCM_UNDEFINED);
2915 | UNSIGNED NUMBER_IDENTIFIER {
2916 $$ = scm_product ($1, $2)
2918 | REAL NUMBER_IDENTIFIER {
2919 $$ = scm_product ($1, $2)
2931 $$ = scm_to_int ($1);
2942 | exclamations '!' { $$ ++; }
2947 | questions '?' { $$ ++; }
2951 This should be done more dynamically if possible.
2955 LYRIC_MARKUP_IDENTIFIER {
2959 { PARSER->lexer_->push_markup_state (); }
2962 PARSER->lexer_->pop_state ();
2967 MARKUPLIST_IDENTIFIER {
2971 { PARSER->lexer_->push_markup_state (); }
2974 PARSER->lexer_->pop_state ();
2983 { PARSER->lexer_->push_markup_state (); }
2986 PARSER->lexer_->pop_state ();
2992 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2994 | markup_head_1_list simple_markup {
2995 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3005 if (Text_interface::is_markup ($1))
3006 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3007 else if (Text_interface::is_markup_list ($1))
3008 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3010 PARSER->parser_error (@1, _("markup expected"));
3011 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3018 MARKUPLIST_IDENTIFIER {
3021 | markup_composed_list {
3024 | markup_braced_list {
3027 | markup_command_list {
3028 $$ = scm_list_1 ($1);
3030 | markup_scm MARKUPLIST_IDENTIFIER
3036 markup_composed_list:
3037 markup_head_1_list markup_braced_list {
3038 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3044 '{' markup_braced_list_body '}' {
3045 $$ = scm_reverse_x ($2, SCM_EOL);
3049 markup_braced_list_body:
3050 /* empty */ { $$ = SCM_EOL; }
3051 | markup_braced_list_body markup {
3052 $$ = scm_cons ($2, $1);
3054 | markup_braced_list_body markup_list {
3055 $$ = scm_reverse_x ($2, $1);
3059 markup_command_list:
3060 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3061 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3065 markup_command_basic_arguments:
3066 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3067 $$ = scm_cons ($3, $2);
3069 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3070 $$ = check_scheme_arg (PARSER, @3, $3, $2, $1);
3072 | EXPECT_NO_MORE_ARGS {
3077 markup_command_list_arguments:
3078 markup_command_basic_arguments { $$ = $1; }
3079 | EXPECT_MARKUP markup_command_list_arguments markup {
3080 $$ = scm_cons ($3, $2);
3085 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3086 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3091 markup_head_1_item {
3092 $$ = scm_list_1 ($1);
3094 | markup_head_1_list markup_head_1_item {
3095 $$ = scm_cons ($2, $1);
3101 $$ = make_simple_markup ($1);
3103 | MARKUP_IDENTIFIER {
3106 | LYRIC_MARKUP_IDENTIFIER {
3109 | STRING_IDENTIFIER {
3113 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
3114 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
3115 } '{' score_body '}' {
3117 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3119 PARSER->lexer_->pop_state ();
3121 | MARKUP_FUNCTION markup_command_basic_arguments {
3122 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3124 | markup_scm MARKUP_IDENTIFIER
3131 markup_head_1_list simple_markup {
3132 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3133 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3143 Lily_parser::set_yydebug (bool x)
3149 Lily_parser::do_yyparse ()
3151 yyparse ((void*)this);
3160 It is a little strange to have this function in this file, but
3161 otherwise, we have to import music classes into the lexer.
3165 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3167 if (scm_is_string (sid)) {
3169 return STRING_IDENTIFIER;
3170 } else if (unsmob_book (sid)) {
3171 Book *book = unsmob_book (sid)->clone ();
3172 *destination = book->self_scm ();
3175 return BOOK_IDENTIFIER;
3176 } else if (scm_is_number (sid)) {
3178 return NUMBER_IDENTIFIER;
3179 } else if (unsmob_context_def (sid)) {
3180 Context_def *def= unsmob_context_def (sid)->clone ();
3182 *destination = def->self_scm ();
3185 return CONTEXT_DEF_IDENTIFIER;
3186 } else if (unsmob_context_mod (sid)) {
3187 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3189 return CONTEXT_MOD_IDENTIFIER;
3190 } else if (unsmob_score (sid)) {
3191 Score *score = new Score (*unsmob_score (sid));
3192 *destination = score->self_scm ();
3194 score->unprotect ();
3195 return SCORE_IDENTIFIER;
3196 } else if (Music *mus = unsmob_music (sid)) {
3197 mus = mus->clone ();
3198 *destination = mus->self_scm ();
3199 unsmob_music (*destination)->
3200 set_property ("origin", make_input (last_input_));
3202 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
3206 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3207 } else if (unsmob_pitch (sid)) {
3208 *destination = unsmob_pitch (sid)->smobbed_copy ();
3209 return PITCH_IDENTIFIER;
3210 } else if (unsmob_duration (sid)) {
3211 *destination = unsmob_duration (sid)->smobbed_copy ();
3212 return DURATION_IDENTIFIER;
3213 } else if (unsmob_output_def (sid)) {
3214 Output_def *p = unsmob_output_def (sid);
3217 *destination = p->self_scm ();
3219 return OUTPUT_DEF_IDENTIFIER;
3220 } else if (Text_interface::is_markup (sid)) {
3222 if (is_lyric_state ())
3223 return LYRIC_MARKUP_IDENTIFIER;
3224 return MARKUP_IDENTIFIER;
3225 } else if (Text_interface::is_markup_list (sid)) {
3227 return MARKUPLIST_IDENTIFIER;
3234 get_next_unique_context_id ()
3236 return scm_from_locale_string ("$uniqueContextId");
3241 get_next_unique_lyrics_context_id ()
3243 static int new_context_count;
3245 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3246 return scm_from_locale_string (s);
3249 SCM check_scheme_arg (Lily_parser *my_lily_parser, Input loc,
3250 SCM arg, SCM args, SCM pred)
3252 args = scm_cons (arg, args);
3253 if (scm_is_true (scm_call_1 (pred, arg)))
3255 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3256 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3257 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3261 SCM loc_on_music (Input loc, SCM arg)
3263 if (Music *m = unsmob_music (arg))
3267 return m->unprotect ();
3273 is_regular_identifier (SCM id)
3275 string str = ly_scm2string (id);
3276 char const *s = str.c_str ();
3285 v = v && isalnum (*s);
3292 make_music_with_input (SCM name, Input where)
3294 Music *m = make_music_by_name (name);
3295 m->set_spot (where);
3300 get_first_context_id (SCM type, Music *m)
3302 SCM id = m->get_property ("context-id");
3303 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
3304 && scm_is_string (m->get_property ("context-id"))
3305 && scm_c_string_length (id) > 0)
3313 make_simple_markup (SCM a)
3321 return t && t == 1 << intlog2 (t);
3325 set_music_properties (Music *p, SCM a)
3327 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3328 p->set_property (scm_caar (k), scm_cdar (k));
3333 make_chord_step (int step, Rational alter)
3336 alter += FLAT_ALTERATION;
3340 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3341 return m.smobbed_copy ();
3346 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
3348 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3349 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
3353 try_unpack_lyrics (SCM pred, SCM arg)
3355 if (Music *m = unsmob_music (arg))
3356 if (m->is_mus_type ("lyric-event")) {
3357 SCM text = m->get_property ("text");
3358 if (scm_is_true (scm_call_1 (pred, text)))
3361 return SCM_UNDEFINED;
3364 /* Todo: actually also use apply iso. call too ... */
3366 ly_input_procedure_p (SCM x)
3368 return ly_is_procedure (x)
3369 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
3373 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
3375 Lily_parser *pars = (Lily_parser*) v;
3376 Lily_lexer *lex = pars->lexer_;
3378 lex->lexval_ = (void*) s;
3380 lex->prepare_for_next_token ();
3381 return lex->yylex ();