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. */
49 /* One shift/reduce problem
52 \repeat .. \alternative
54 \repeat { \repeat .. \alternative }
58 \repeat { \repeat } \alternative
67 %{ // -*-Fundamental-*-
72 * The rules for who is protecting what are very shady. Uniformise
75 * There are too many lexical modes?
86 #include "context-def.hh"
87 #include "context-mod.hh"
88 #include "dimensions.hh"
89 #include "file-path.hh"
91 #include "international.hh"
92 #include "lily-guile.hh"
93 #include "lily-lexer.hh"
94 #include "lily-parser.hh"
99 #include "output-def.hh"
100 #include "paper-book.hh"
101 #include "program-option.hh"
102 #include "scm-hash.hh"
104 #include "text-interface.hh"
112 Output_def *outputdef;
122 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
125 - Don't use lily module, create a new module instead.
126 - delay application of the function
128 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
129 scm_apply_0 (proc, args)
130 /* Syntactic Sugar. */
131 #define MAKE_SYNTAX(name, location, ...) \
132 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location), __VA_ARGS__, SCM_UNDEFINED));
134 SCM get_next_unique_context_id ();
135 SCM get_next_unique_lyrics_context_id ();
142 #define _(x) gettext (x)
146 static Music *make_music_with_input (SCM name, Input where);
147 SCM make_music_relative (Pitch start, SCM music, Input loc);
148 SCM run_music_function (Lily_parser *, SCM expr);
149 SCM get_first_context_id (SCM type, Music *m);
150 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
151 SCM make_chord_step (int step, Rational alter);
152 SCM make_simple_markup (SCM a);
153 bool is_duration (int t);
154 bool is_regular_identifier (SCM id);
155 bool ly_input_procedure_p (SCM x);
156 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
157 void set_music_properties (Music *p, SCM a);
161 /* The third option is an alias that will be used to display the
162 syntax error. Bison CVS now correctly handles backslash escapes.
164 FIXME: Bison needs to translate some of these, eg, STRING.
168 /* Keyword tokens with plain escaped name. */
169 %token ACCEPTS "\\accepts"
170 %token ADDLYRICS "\\addlyrics"
171 %token ALIAS "\\alias"
172 %token ALTERNATIVE "\\alternative"
174 %token BOOKPART "\\bookpart"
175 %token CHANGE "\\change"
176 %token CHORDMODE "\\chordmode"
177 %token CHORDS "\\chords"
178 %token CONSISTS "\\consists"
179 %token CONTEXT "\\context"
180 %token DEFAULT "\\default"
181 %token DEFAULTCHILD "\\defaultchild"
182 %token DENIES "\\denies"
183 %token DESCRIPTION "\\description"
184 %token DRUMMODE "\\drummode"
185 %token DRUMS "\\drums"
186 %token FIGUREMODE "\\figuremode"
187 %token FIGURES "\\figures"
188 %token GROBDESCRIPTIONS "\\grobdescriptions"
189 %token HEADER "\\header"
190 %token INVALID "\\invalid"
192 %token LAYOUT "\\layout"
193 %token LYRICMODE "\\lyricmode"
194 %token LYRICS "\\lyrics"
195 %token LYRICSTO "\\lyricsto"
197 %token MARKUP "\\markup"
198 %token MARKUPLINES "\\markuplines"
201 %token NOTEMODE "\\notemode"
202 %token OCTAVE "\\octave"
204 %token OVERRIDE "\\override"
205 %token PAPER "\\paper"
206 %token PARTIAL "\\partial"
207 %token RELATIVE "\\relative"
208 %token REMOVE "\\remove"
209 %token REPEAT "\\repeat"
211 %token REVERT "\\revert"
212 %token SCORE "\\score"
213 %token SEQUENTIAL "\\sequential"
215 %token SIMULTANEOUS "\\simultaneous"
217 %token TEMPO "\\tempo"
218 %token TIMES "\\times"
219 %token TRANSPOSE "\\transpose"
221 %token UNSET "\\unset"
224 /* Keyword token exceptions. */
225 %token TIME_T "\\time"
226 %token NEWCONTEXT "\\new"
229 /* Other string tokens. */
231 %token CHORD_BASS "/+"
232 %token CHORD_CARET "^"
233 %token CHORD_COLON ":"
234 %token CHORD_MINUS "-"
235 %token CHORD_SLASH "/"
236 %token ANGLE_OPEN "<"
237 %token ANGLE_CLOSE ">"
238 %token DOUBLE_ANGLE_OPEN "<<"
239 %token DOUBLE_ANGLE_CLOSE ">>"
240 %token E_BACKSLASH "\\"
241 %token E_ANGLE_CLOSE "\\>"
242 %token E_CHAR "\\C[haracter]"
244 %token E_EXCLAMATION "\\!"
245 %token E_BRACKET_OPEN "\\["
247 %token E_BRACKET_CLOSE "\\]"
248 %token E_ANGLE_OPEN "\\<"
254 If we give names, Bison complains.
256 %token FIGURE_CLOSE /* "\\>" */
257 %token FIGURE_OPEN /* "\\<" */
258 %token FIGURE_SPACE "_"
261 %token CHORDMODIFIERS
263 %token MULTI_MEASURE_REST
267 %token <i> E_UNSIGNED
270 /* Artificial tokens, for more generic function syntax */
271 %token <i> EXPECT_MARKUP;
272 %token <i> EXPECT_MUSIC;
273 %token <i> EXPECT_PITCH;
274 %token <i> EXPECT_DURATION;
275 %token <i> EXPECT_SCM;
276 %token <i> EXPECT_MARKUP_LIST
277 /* After the last argument. */
278 %token <i> EXPECT_NO_MORE_ARGS;
280 %token <scm> BOOK_IDENTIFIER
281 %token <scm> CHORDMODIFIER_PITCH
282 %token <scm> CHORD_MODIFIER
283 %token <scm> CHORD_REPETITION
284 %token <scm> CONTEXT_DEF_IDENTIFIER
285 %token <scm> CONTEXT_MOD_IDENTIFIER
286 %token <scm> DRUM_PITCH
287 %token <scm> DURATION_IDENTIFIER
288 %token <scm> EVENT_IDENTIFIER
289 %token <scm> FRACTION
290 %token <scm> LYRICS_STRING
291 %token <scm> LYRIC_MARKUP_IDENTIFIER
292 %token <scm> MARKUP_FUNCTION
293 %token <scm> MARKUP_LIST_FUNCTION
294 %token <scm> MARKUP_IDENTIFIER
295 %token <scm> MARKUPLINES_IDENTIFIER
296 %token <scm> MUSIC_FUNCTION
297 %token <scm> MUSIC_IDENTIFIER
298 %token <scm> NOTENAME_PITCH
299 %token <scm> NUMBER_IDENTIFIER
300 %token <scm> OUTPUT_DEF_IDENTIFIER
302 %token <scm> RESTNAME
303 %token <scm> SCM_IDENTIFIER
304 %token <scm> SCM_TOKEN
305 %token <scm> SCORE_IDENTIFIER
307 %token <scm> STRING_IDENTIFIER
308 %token <scm> TONICNAME_PITCH
311 %type <book> book_block
312 %type <book> book_body
313 %type <book> bookpart_block
314 %type <book> bookpart_body
316 %type <i> bare_unsigned
317 %type <scm> figured_bass_alteration
319 %type <i> exclamations
320 %type <i> optional_rest
325 %type <i> tremolo_type
328 %type <scm> composite_music
329 %type <scm> grouped_music_list
330 %type <scm> closed_music
331 %type <scm> open_music
333 %type <scm> prefix_composite_music
334 %type <scm> repeated_music
335 %type <scm> sequential_music
336 %type <scm> simple_music
337 %type <scm> simultaneous_music
338 %type <scm> chord_body
339 %type <scm> chord_body_element
340 %type <scm> command_element
341 %type <scm> command_event
342 %type <scm> context_modification
343 %type <scm> context_change
344 %type <scm> direction_less_event
345 %type <scm> direction_reqd_event
346 %type <scm> event_chord
347 %type <scm> gen_text_def
348 %type <scm> music_property_def
349 %type <scm> note_chord_element
350 %type <scm> post_event
351 %type <scm> re_rhythmed_music
352 %type <scm> relative_music
353 %type <scm> simple_element
354 %type <scm> simple_music_property_def
355 %type <scm> string_number_event
356 %type <scm> tempo_event
358 %type <outputdef> output_def_body
359 %type <outputdef> output_def_head
360 %type <outputdef> output_def_head_with_mode_switch
361 %type <outputdef> output_def
362 %type <outputdef> paper_block
364 %type <scm> alternative_music
365 %type <scm> generic_prefix_music_scm
366 %type <scm> music_list
367 %type <scm> absolute_pitch
368 %type <scm> assignment_id
369 %type <scm> bare_number
370 %type <scm> unsigned_number
371 %type <scm> bass_figure
372 %type <scm> figured_bass_modification
373 %type <scm> br_bass_figure
374 %type <scm> bass_number
375 %type <scm> chord_body_elements
376 %type <scm> chord_item
377 %type <scm> chord_items
378 %type <scm> chord_separator
379 %type <scm> context_def_mod
380 %type <scm> context_def_spec_block
381 %type <scm> context_def_spec_body
382 %type <scm> context_mod
383 %type <scm> context_mod_list
384 %type <scm> context_prop_spec
385 %type <scm> direction_less_char
386 %type <scm> duration_length
387 %type <scm> embedded_scm
388 %type <scm> figure_list
389 %type <scm> figure_spec
391 %type <scm> full_markup
392 %type <scm> full_markup_list
393 %type <scm> function_scm_argument
394 %type <scm> function_arglist
395 %type <scm> function_arglist_nonmusic_last
396 %type <scm> closed_function_arglist
397 %type <scm> open_function_arglist
398 %type <scm> identifier_init
399 %type <scm> lilypond_header
400 %type <scm> lilypond_header_body
401 %type <scm> lyric_element
402 %type <scm> lyric_markup
404 %type <scm> markup_braced_list
405 %type <scm> markup_braced_list_body
406 %type <scm> markup_composed_list
407 %type <scm> markup_command_list
408 %type <scm> markup_command_list_arguments
409 %type <scm> markup_command_basic_arguments
410 %type <scm> markup_head_1_item
411 %type <scm> markup_head_1_list
412 %type <scm> markup_list
413 %type <scm> markup_top
414 %type <scm> mode_changing_head
415 %type <scm> mode_changing_head_with_context
416 %type <scm> multiplied_duration
417 %type <scm> music_function_event
418 %type <scm> music_function_event_arglist
419 %type <scm> music_function_chord_body
420 %type <scm> music_function_chord_body_arglist
421 %type <scm> new_chord
422 %type <scm> new_lyrics
423 %type <scm> number_expression
424 %type <scm> number_factor
425 %type <scm> number_term
426 %type <scm> octave_check
427 %type <scm> optional_context_mod
428 %type <scm> optional_id
429 %type <scm> optional_notemode_duration
431 %type <scm> pitch_also_in_chords
432 %type <scm> post_events
433 %type <scm> property_operation
434 %type <scm> property_path property_path_revved
436 %type <scm> script_abbreviation
437 %type <scm> simple_chord_elements
438 %type <scm> simple_markup
439 %type <scm> simple_string
440 %type <scm> steno_duration
441 %type <scm> steno_pitch
442 %type <scm> steno_tonic_pitch
443 %type <scm> step_number
444 %type <scm> step_numbers
446 %type <scm> tempo_range
448 %type <score> score_block
449 %type <score> score_body
454 /* We don't assign precedence to / and *, because we might need varied
455 prec levels in different prods */
461 lilypond: /* empty */
462 | lilypond toplevel_expression {
464 | lilypond assignment {
467 PARSER->error_level_ = 1;
470 PARSER->error_level_ = 1;
477 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
481 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
482 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
487 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
488 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
489 bookpart->unprotect ();
494 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
495 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
499 Music *music = unsmob_music ($1);
500 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
501 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
504 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
505 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
508 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
509 scm_call_2 (proc, PARSER->self_scm (), $1);
513 Output_def * od = $1;
515 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
516 id = ly_symbol2scm ("$defaultpaper");
517 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
518 id = ly_symbol2scm ("$defaultmidi");
519 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
520 id = ly_symbol2scm ("$defaultlayout");
522 PARSER->lexer_->set_identifier (id, od->self_scm ());
533 lilypond_header_body:
535 $$ = get_header (PARSER);
536 PARSER->lexer_->add_scope ($$);
538 | lilypond_header_body assignment {
544 HEADER '{' lilypond_header_body '}' {
545 $$ = PARSER->lexer_->remove_scope ();
554 | LYRICS_STRING { $$ = $1; }
558 assignment_id '=' identifier_init {
559 PARSER->lexer_->set_identifier ($1, $3);
561 | assignment_id property_path '=' identifier_init {
562 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
563 PARSER->lexer_->set_identifier (path, $4);
566 TODO: devise standard for protection in parser.
568 The parser stack lives on the C-stack, which means that
569 all objects can be unprotected as soon as they're here.
579 $$ = $1->self_scm ();
583 $$ = $1->self_scm ();
587 $$ = $1->self_scm ();
591 $$ = $1->self_scm ();
594 | context_def_spec_block {
598 /* Hack: Create event-chord around standalone events.
599 Prevents the identifier from being interpreted as a post-event. */
600 Music *mus = unsmob_music ($1);
601 bool is_event = mus &&
602 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
607 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
612 | number_expression {
628 $$ = scm_from_int ($1);
630 | context_modification {
635 context_def_spec_block:
636 CONTEXT '{' context_def_spec_body '}'
642 context_def_spec_body:
644 $$ = Context_def::make_scm ();
645 unsmob_context_def ($$)->origin ()->set_spot (@$);
647 | CONTEXT_DEF_IDENTIFIER {
649 unsmob_context_def ($$)->origin ()->set_spot (@$);
651 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
652 Context_def*td = unsmob_context_def ($$);
654 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
655 SCM tag = scm_caar (p);
657 /* TODO: should make new tag "grob-definition" ? */
658 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
659 tag, scm_cons (scm_cdar (p), SCM_EOL)));
662 | context_def_spec_body context_mod {
663 unsmob_context_def ($$)->add_context_mod ($2);
665 | context_def_spec_body context_modification {
666 Context_def *td = unsmob_context_def ($$);
667 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
668 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
669 td->add_context_mod (scm_car (m));
677 BOOK '{' book_body '}' {
680 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
685 * Use 'handlers' like for toplevel-* stuff?
686 * grok \layout and \midi? */
690 init_papers (PARSER);
691 $$->origin ()->set_spot (@$);
692 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
693 $$->paper_->unprotect ();
694 push_paper (PARSER, $$->paper_);
695 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
696 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
697 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
698 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
701 $$ = unsmob_book ($1);
703 $$->origin ()->set_spot (@$);
704 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
706 | book_body paper_block {
709 set_paper (PARSER, $2);
711 | book_body bookpart_block {
713 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
714 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
715 bookpart->unprotect ();
717 | book_body score_block {
719 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
720 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
723 | book_body composite_music {
724 Music *music = unsmob_music ($2);
725 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
726 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
728 | book_body full_markup {
729 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
730 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
732 | book_body full_markup_list {
733 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
734 scm_call_2 (proc, $$->self_scm (), $2);
736 | book_body lilypond_header {
741 $$->scores_ = SCM_EOL;
742 $$->bookparts_ = SCM_EOL;
747 BOOKPART '{' bookpart_body '}' {
749 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
756 $$->origin ()->set_spot (@$);
757 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
760 $$ = unsmob_book ($1);
762 $$->origin ()->set_spot (@$);
763 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
765 | bookpart_body paper_block {
769 | bookpart_body score_block {
771 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
772 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
775 | bookpart_body composite_music {
776 Music *music = unsmob_music ($2);
777 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
778 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
780 | bookpart_body full_markup {
781 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
782 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
784 | bookpart_body full_markup_list {
785 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
786 scm_call_2 (proc, $$->self_scm (), $2);
788 | bookpart_body lilypond_header {
791 | bookpart_body error {
793 $$->scores_ = SCM_EOL;
798 SCORE '{' score_body '}' {
806 SCM scorify = ly_lily_module_constant ("scorify-music");
807 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
809 // pass ownernship to C++ again.
810 $$ = unsmob_score (score);
812 $$->origin ()->set_spot (@$);
815 $$ = unsmob_score ($1);
817 $$->origin ()->set_spot (@$);
819 | score_body lilypond_header {
822 | score_body output_def {
823 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
825 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
830 $$->add_output_def ($2);
835 $$->error_found_ = true;
847 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
849 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
851 $$ = get_paper (PARSER);
858 output_def_body '}' {
861 PARSER->lexer_->remove_scope ();
862 PARSER->lexer_->pop_state ();
868 $$ = get_paper (PARSER);
869 $$->input_origin_ = @$;
870 PARSER->lexer_->add_scope ($$->scope_);
873 Output_def *p = get_midi (PARSER);
875 PARSER->lexer_->add_scope (p->scope_);
878 Output_def *p = get_layout (PARSER);
880 PARSER->lexer_->add_scope (p->scope_);
885 output_def_head_with_mode_switch:
887 PARSER->lexer_->push_initial_state ();
893 output_def_head_with_mode_switch '{' {
895 $$->input_origin_.set_spot (@$);
897 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
900 Output_def *o = unsmob_output_def ($3);
901 o->input_origin_.set_spot (@$);
904 PARSER->lexer_->remove_scope ();
905 PARSER->lexer_->add_scope (o->scope_);
907 | output_def_body assignment {
910 | output_def_body context_def_spec_block {
911 assign_context_def ($$, $2);
913 | output_def_body error {
919 TEMPO steno_duration '=' tempo_range {
920 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
922 | TEMPO scalar steno_duration '=' tempo_range {
923 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
926 $$ = MAKE_SYNTAX ("tempo", @$, $2);
931 The representation of a list is reversed to have efficient append. */
938 $$ = scm_cons ($2, $1);
940 | music_list embedded_scm {
944 Music *m = MY_MAKE_MUSIC("Music", @$);
946 m->set_property ("error-found", SCM_BOOL_T);
947 $$ = scm_cons (m->self_scm (), $1);
948 m->unprotect (); /* UGH */
962 | ALTERNATIVE '{' music_list '}' {
963 $$ = scm_reverse_x ($3, SCM_EOL);
969 REPEAT simple_string unsigned_number music alternative_music
971 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $5);
976 SEQUENTIAL '{' music_list '}' {
977 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_reverse_x ($3, SCM_EOL));
979 | '{' music_list '}' {
980 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_reverse_x ($2, SCM_EOL));
985 SIMULTANEOUS '{' music_list '}'{
986 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($3, SCM_EOL));
988 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
989 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
999 context_modification:
1000 WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1002 PARSER->lexer_->pop_state ();
1005 | WITH CONTEXT_MOD_IDENTIFIER
1009 | CONTEXT_MOD_IDENTIFIER
1015 optional_context_mod:
1019 | context_modification
1027 $$ = Context_mod ().smobbed_copy ();
1029 | context_mod_list context_mod {
1030 unsmob_context_mod ($1)->add_context_mod ($2);
1032 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1033 Context_mod *md = unsmob_context_mod ($2);
1035 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1040 prefix_composite_music { $$ = $1; }
1041 | grouped_music_list { $$ = $1; }
1044 /* Music that can't be followed by additional events or durations */
1047 | grouped_music_list
1050 /* Music that potentially accepts additional events or durations */
1053 | prefix_composite_music
1057 simultaneous_music { $$ = $1; }
1058 | sequential_music { $$ = $1; }
1061 function_scm_argument:
1066 /* An argument list. If a function \foo expects scm scm music, then the lexer expands \foo into the token sequence:
1067 MUSIC_FUNCTION EXPECT_MUSIC EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1068 and this rule returns the reversed list of arguments. */
1072 closed_function_arglist
1073 | open_function_arglist
1076 open_function_arglist:
1077 EXPECT_MUSIC function_arglist open_music {
1078 $$ = scm_cons ($3, $2);
1082 /* a closed argument list is one that does not end in a music
1083 expression that could still take a duration or event */
1085 closed_function_arglist:
1086 function_arglist_nonmusic_last
1087 | EXPECT_MUSIC function_arglist closed_music {
1088 $$ = scm_cons ($3, $2);
1092 function_arglist_nonmusic_last:
1093 EXPECT_NO_MORE_ARGS {
1094 /* This is for 0-ary functions, so they don't need to
1095 read a lookahead token */
1098 | EXPECT_MARKUP function_arglist full_markup {
1099 $$ = scm_cons ($3, $2);
1101 | EXPECT_MARKUP function_arglist simple_string {
1102 $$ = scm_cons ($3, $2);
1104 | EXPECT_PITCH function_arglist pitch {
1105 $$ = scm_cons ($3, $2);
1107 | EXPECT_DURATION closed_function_arglist duration_length {
1108 $$ = scm_cons ($3, $2);
1110 | EXPECT_SCM function_arglist function_scm_argument {
1111 $$ = scm_cons ($3, $2);
1115 generic_prefix_music_scm:
1116 MUSIC_FUNCTION function_arglist {
1117 $$ = scm_cons2 ($1, make_input (@$), scm_reverse_x ($2, SCM_EOL));
1123 /**/ { $$ = SCM_EOL; }
1124 | '=' simple_string {
1130 prefix_composite_music:
1131 generic_prefix_music_scm {
1132 $$ = run_music_function (PARSER, $1);
1134 | CONTEXT simple_string optional_id optional_context_mod music {
1135 Context_mod *ctxmod = unsmob_context_mod ($4);
1138 mods = ctxmod->get_mods ();
1139 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, mods, SCM_BOOL_F);
1141 | NEWCONTEXT simple_string optional_id optional_context_mod music {
1142 Context_mod *ctxmod = unsmob_context_mod ($4);
1145 mods = ctxmod->get_mods ();
1146 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, mods, SCM_BOOL_T);
1149 | TIMES fraction music {
1150 $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3);
1152 | repeated_music { $$ = $1; }
1153 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords music {
1154 Pitch from = *unsmob_pitch ($2);
1155 Pitch to = *unsmob_pitch ($3);
1156 SCM pitch = pitch_interval (from, to).smobbed_copy ();
1157 $$ = MAKE_SYNTAX ("transpose-music", @$, pitch, $4);
1159 | mode_changing_head grouped_music_list {
1160 if ($1 == ly_symbol2scm ("chords"))
1162 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1168 PARSER->lexer_->pop_state ();
1170 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1171 Context_mod *ctxmod = unsmob_context_mod ($2);
1174 mods = ctxmod->get_mods ();
1175 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, $3, mods, SCM_BOOL_T);
1176 if ($1 == ly_symbol2scm ("ChordNames"))
1178 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1180 PARSER->lexer_->pop_state ();
1182 | relative_music { $$ = $1; }
1183 | re_rhythmed_music { $$ = $1; }
1188 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1189 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1191 $$ = ly_symbol2scm ("notes");
1195 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1196 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1198 $$ = ly_symbol2scm ("drums");
1201 PARSER->lexer_->push_figuredbass_state ();
1203 $$ = ly_symbol2scm ("figures");
1206 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1207 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1208 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1209 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1210 $$ = ly_symbol2scm ("chords");
1214 { PARSER->lexer_->push_lyric_state ();
1215 $$ = ly_symbol2scm ("lyrics");
1219 mode_changing_head_with_context:
1221 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1222 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1224 $$ = ly_symbol2scm ("DrumStaff");
1227 PARSER->lexer_->push_figuredbass_state ();
1229 $$ = ly_symbol2scm ("FiguredBass");
1232 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1233 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1234 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1235 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1236 $$ = ly_symbol2scm ("ChordNames");
1239 { PARSER->lexer_->push_lyric_state ();
1240 $$ = ly_symbol2scm ("Lyrics");
1246 RELATIVE absolute_pitch music {
1247 Pitch start = *unsmob_pitch ($2);
1248 $$ = make_music_relative (start, $3, @$);
1250 | RELATIVE composite_music {
1251 Pitch middle_c (0, 0, 0);
1252 $$ = make_music_relative (middle_c, $2, @$);
1257 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1260 /* Can also use music at the expensive of two S/Rs similar to
1261 \repeat \alternative */
1262 PARSER->lexer_->pop_state ();
1264 $$ = scm_cons ($3, SCM_EOL);
1266 | new_lyrics ADDLYRICS {
1267 PARSER->lexer_->push_lyric_state ();
1269 PARSER->lexer_->pop_state ();
1270 $$ = scm_cons ($4, $1);
1275 closed_music new_lyrics {
1276 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1278 | LYRICSTO simple_string {
1279 PARSER->lexer_->push_lyric_state ();
1281 PARSER->lexer_->pop_state ();
1282 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1287 CHANGE STRING '=' STRING {
1288 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1293 property_path_revved:
1295 $$ = scm_cons ($1, SCM_EOL);
1297 | property_path_revved embedded_scm {
1298 $$ = scm_cons ($2, $1);
1303 property_path_revved {
1304 $$ = scm_reverse_x ($1, SCM_EOL);
1310 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1311 scm_string_to_symbol ($1), $3);
1313 | UNSET simple_string {
1314 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1315 scm_string_to_symbol ($2));
1317 | OVERRIDE simple_string property_path '=' scalar {
1318 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1319 scm_string_to_symbol ($2), $5),
1322 | REVERT simple_string embedded_scm {
1323 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1324 scm_string_to_symbol ($2), $3);
1329 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1330 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1332 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1333 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1334 | DENIES { $$ = ly_symbol2scm ("denies"); }
1336 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1337 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1338 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1339 | NAME { $$ = ly_symbol2scm ("context-name"); }
1343 property_operation { $$ = $1; }
1344 | context_def_mod STRING {
1345 $$ = scm_list_2 ($1, $2);
1347 | context_def_mod embedded_scm {
1348 if (ly_symbol2scm ("consists") != $1)
1351 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1355 $$ = scm_list_2 ($1, $2);
1362 if (!is_regular_identifier ($1))
1364 @$.error (_("Grob name should be alphanumeric"));
1367 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1368 scm_string_to_symbol ($1));
1370 | simple_string '.' simple_string {
1371 $$ = scm_list_2 (scm_string_to_symbol ($1),
1372 scm_string_to_symbol ($3));
1376 simple_music_property_def:
1377 OVERRIDE context_prop_spec property_path '=' scalar {
1378 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1379 ly_symbol2scm ("OverrideProperty"),
1384 | REVERT context_prop_spec embedded_scm {
1385 $$ = scm_list_4 (scm_car ($2),
1386 ly_symbol2scm ("RevertProperty"),
1390 | SET context_prop_spec '=' scalar {
1391 $$ = scm_list_4 (scm_car ($2),
1392 ly_symbol2scm ("PropertySet"),
1396 | UNSET context_prop_spec {
1397 $$ = scm_list_3 (scm_car ($2),
1398 ly_symbol2scm ("PropertyUnset"),
1404 simple_music_property_def {
1405 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1407 | ONCE simple_music_property_def {
1408 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1416 | STRING_IDENTIFIER {
1419 | string '+' string {
1420 $$ = scm_string_append (scm_list_2 ($1, $3));
1424 simple_string: STRING {
1430 | STRING_IDENTIFIER {
1451 $$ = scm_from_int ($1);
1456 /* TODO: Create a special case that avoids the creation of
1457 EventChords around simple_elements that have no post_events?
1459 simple_chord_elements post_events {
1460 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1463 /* why is this giving wrong start location? -ns
1465 i.set_location (@1, @2);
1466 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1468 | CHORD_REPETITION optional_notemode_duration post_events {
1470 i.set_location (@1, @3);
1471 $$ = MAKE_SYNTAX ("repetition-chord", i,
1472 PARSER->lexer_->chord_repetition_.last_chord_,
1473 PARSER->lexer_->chord_repetition_.repetition_function_,
1474 $2, scm_reverse_x ($3, SCM_EOL));
1476 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1478 i.set_location (@1, @3);
1479 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1480 scm_reverse_x ($3, SCM_EOL));
1483 /* note chord elements are memorized into
1484 PARSER->lexer_->chord_repetition_ so that the chord repetition
1485 mechanism copy them when a chord repetition symbol is found
1487 | note_chord_element {
1488 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
1494 chord_body optional_notemode_duration post_events
1496 Music *m = unsmob_music ($1);
1497 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1498 SCM es = m->get_property ("elements");
1499 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1501 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1502 unsmob_music (scm_car (s))->set_property ("duration", dur);
1503 es = ly_append2 (es, postevs);
1505 m-> set_property ("elements", es);
1507 $$ = m->self_scm ();
1512 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1514 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1518 chord_body_elements:
1519 /* empty */ { $$ = SCM_EOL; }
1520 | chord_body_elements chord_body_element {
1521 $$ = scm_cons ($2, $1);
1526 pitch exclamations questions octave_check post_events
1533 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1534 n->set_property ("pitch", $1);
1536 n->set_property ("cautionary", SCM_BOOL_T);
1537 if (ex % 2 || q % 2)
1538 n->set_property ("force-accidental", SCM_BOOL_T);
1540 if (scm_is_pair (post)) {
1541 SCM arts = scm_reverse_x (post, SCM_EOL);
1542 n->set_property ("articulations", arts);
1544 if (scm_is_number (check))
1546 int q = scm_to_int (check);
1547 n->set_property ("absolute-octave", scm_from_int (q-1));
1550 $$ = n->unprotect ();
1552 | DRUM_PITCH post_events {
1553 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1554 n->set_property ("drum-type", $1);
1556 if (scm_is_pair ($2)) {
1557 SCM arts = scm_reverse_x ($2, SCM_EOL);
1558 n->set_property ("articulations", arts);
1560 $$ = n->unprotect ();
1562 | music_function_chord_body {
1563 $$ = run_music_function (PARSER, $1);
1567 /* We can't accept a music argument, not even a closed one,
1568 * immediately before chord_body_elements, otherwise a function \fun
1569 * with a signature of two music arguments can't be sorted out
1570 * properly in a construct like
1571 * <\fun { c } \fun { c } c>
1572 * The second call could be interpreted either as a chord constituent
1573 * or a music expression.
1576 music_function_chord_body_arglist:
1577 function_arglist_nonmusic_last
1578 | EXPECT_MUSIC music_function_chord_body_arglist chord_body_element {
1579 $$ = scm_cons ($3, $2);
1583 music_function_chord_body:
1584 MUSIC_FUNCTION music_function_chord_body_arglist {
1585 $$ = scm_cons2 ($1, make_input (@$), scm_reverse_x ($2, SCM_EOL));
1589 /* We could accept a closed music argument before the post events
1590 * indicated by a trailing argument list. For symmetry with chord
1591 * bodies and in order to avoid too tricky and complex behavior, we
1592 * refrain from doing so.
1594 music_function_event_arglist:
1595 function_arglist_nonmusic_last
1596 | EXPECT_MUSIC music_function_event_arglist post_event {
1597 $$ = scm_cons ($3, $2);
1601 music_function_event:
1602 MUSIC_FUNCTION music_function_event_arglist {
1603 $$ = scm_cons2 ($1, make_input (@$), scm_reverse_x ($2, SCM_EOL));
1611 | SKIP duration_length {
1612 $$ = MAKE_SYNTAX ("skip-music", @$, $2);
1615 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1616 m->set_property ("span-direction", scm_from_int (START));
1617 $$ = m->unprotect();
1620 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1621 m->set_property ("span-direction", scm_from_int (STOP));
1622 $$ = m->unprotect ();
1625 $$ = MAKE_SYNTAX ("voice-separator", @$, SCM_UNDEFINED);
1628 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1630 Music *m = unsmob_music (pipe);
1635 $$ = m->unprotect ();
1638 $$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
1641 | PARTIAL duration_length {
1642 $$ = MAKE_SYNTAX ("partial", @$, $2);
1646 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1648 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1651 $$ = MAKE_SYNTAX ("make-mark-set", @$, $2);
1657 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
1660 Music *m = MY_MAKE_MUSIC ("MarkEvent", @$);
1661 $$ = m->unprotect ();
1667 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1668 $$ = key->unprotect ();
1670 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1672 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1673 if (scm_ilength ($3) > 0)
1675 key->set_property ("pitch-alist", $3);
1676 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1677 key->transpose (* unsmob_pitch ($2));
1679 PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1682 $$ = key->unprotect ();
1691 | post_events post_event {
1692 unsmob_music ($2)->set_spot (@2);
1693 $$ = scm_cons ($2, $$);
1698 direction_less_event {
1701 | script_dir music_function_event {
1702 $$ = run_music_function (PARSER, $2);
1705 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
1709 if (!PARSER->lexer_->is_lyric_state ())
1710 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1711 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
1714 if (!PARSER->lexer_->is_lyric_state ())
1715 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1716 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
1718 | script_dir direction_reqd_event {
1721 Music *m = unsmob_music ($2);
1722 m->set_property ("direction", scm_from_int ($1));
1726 | script_dir direction_less_event {
1729 Music *m = unsmob_music ($2);
1730 m->set_property ("direction", scm_from_int ($1));
1734 | string_number_event
1737 string_number_event:
1739 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
1740 s->set_property ("string-number", scm_from_int ($1));
1741 $$ = s->unprotect ();
1745 direction_less_char:
1747 $$ = ly_symbol2scm ("bracketOpenSymbol");
1750 $$ = ly_symbol2scm ("bracketCloseSymbol");
1753 $$ = ly_symbol2scm ("tildeSymbol");
1756 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1759 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1762 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1765 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1768 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1771 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1774 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1778 direction_less_event:
1779 direction_less_char {
1780 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
1782 if (unsmob_music (predefd))
1784 m = unsmob_music (predefd)->clone ();
1789 m = MY_MAKE_MUSIC ("Music", @$);
1791 $$ = m->unprotect ();
1793 | EVENT_IDENTIFIER {
1797 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
1798 a->set_property ("tremolo-type", scm_from_int ($1));
1799 $$ = a->unprotect ();
1803 direction_reqd_event:
1807 | script_abbreviation {
1808 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1809 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
1810 if (scm_is_string (s))
1811 a->set_property ("articulation-type", s);
1812 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
1813 $$ = a->unprotect ();
1818 /**/ { $$ = SCM_EOL; }
1819 | '=' { $$ = scm_from_int (0); }
1820 | '=' sub_quotes { $$ = scm_from_int (-$2); }
1821 | '=' sup_quotes { $$ = scm_from_int ($2); }
1846 | NOTENAME_PITCH sup_quotes {
1847 Pitch p = *unsmob_pitch ($1);
1848 p = p.transposed (Pitch ($2,0,0));
1849 $$ = p.smobbed_copy ();
1851 | NOTENAME_PITCH sub_quotes {
1852 Pitch p =* unsmob_pitch ($1);
1853 p = p.transposed (Pitch (-$2,0,0));
1854 $$ = p.smobbed_copy ();
1866 | TONICNAME_PITCH sup_quotes {
1867 Pitch p = *unsmob_pitch ($1);
1868 p = p.transposed (Pitch ($2,0,0));
1869 $$ = p.smobbed_copy ();
1871 | TONICNAME_PITCH sub_quotes {
1872 Pitch p = *unsmob_pitch ($1);
1874 p = p.transposed (Pitch (-$2,0,0));
1875 $$ = p.smobbed_copy ();
1885 pitch_also_in_chords:
1892 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1893 t->set_property ("text", $1);
1894 $$ = t->unprotect ();
1897 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1898 t->set_property ("text",
1899 make_simple_markup ($1));
1900 $$ = t->unprotect ();
1903 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
1904 t->set_property ("digit", scm_from_int ($1));
1905 $$ = t->unprotect ();
1909 script_abbreviation:
1911 $$ = scm_from_locale_string ("Hat");
1914 $$ = scm_from_locale_string ("Plus");
1917 $$ = scm_from_locale_string ("Dash");
1920 $$ = scm_from_locale_string ("Bar");
1923 $$ = scm_from_locale_string ("Larger");
1926 $$ = scm_from_locale_string ("Dot");
1929 $$ = scm_from_locale_string ("Underscore");
1936 | '-' { $$ = CENTER; }
1947 multiplied_duration {
1952 optional_notemode_duration:
1954 Duration dd = PARSER->default_duration_;
1955 $$ = dd.smobbed_copy ();
1957 | multiplied_duration {
1959 PARSER->default_duration_ = *unsmob_duration ($$);
1964 bare_unsigned dots {
1966 if (!is_duration ($1))
1967 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
1971 $$ = Duration (len, $2).smobbed_copy ();
1973 | DURATION_IDENTIFIER dots {
1974 Duration *d = unsmob_duration ($1);
1975 Duration k (d->duration_log (), d->dot_count () + $2);
1976 k = k.compressed (d->factor ());
1982 multiplied_duration:
1986 | multiplied_duration '*' bare_unsigned {
1987 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1989 | multiplied_duration '*' FRACTION {
1990 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1992 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1997 FRACTION { $$ = $1; }
1998 | UNSIGNED '/' UNSIGNED {
1999 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2016 | ':' bare_unsigned {
2017 if (!is_duration ($2))
2018 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2025 $$ = scm_from_int ($1);
2028 $$ = scm_from_int ($1);
2030 | STRING { $$ = $1; }
2031 | full_markup { $$ = $1; }
2034 figured_bass_alteration:
2035 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2036 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2037 | '!' { $$ = scm_from_int (0); }
2042 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2043 $$ = bfr->unprotect ();
2046 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2047 $$ = bfr->self_scm ();
2049 if (scm_is_number ($1))
2050 bfr->set_property ("figure", $1);
2051 else if (Text_interface::is_markup ($1))
2052 bfr->set_property ("text", $1);
2058 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2060 | bass_figure figured_bass_alteration {
2061 Music *m = unsmob_music ($1);
2062 if (scm_to_double ($2)) {
2063 SCM salter = m->get_property ("alteration");
2064 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2065 m->set_property ("alteration",
2066 scm_sum (alter, $2));
2068 m->set_property ("alteration", scm_from_int (0));
2071 | bass_figure figured_bass_modification {
2072 Music *m = unsmob_music ($1);
2073 if ($2 == ly_symbol2scm ("plus"))
2075 m->set_property ("augmented", SCM_BOOL_T);
2077 else if ($2 == ly_symbol2scm ("slash"))
2079 m->set_property ("diminished", SCM_BOOL_T);
2081 else if ($2 == ly_symbol2scm ("exclamation"))
2083 m->set_property ("no-continuation", SCM_BOOL_T);
2085 else if ($2 == ly_symbol2scm ("backslash"))
2087 m->set_property ("augmented-slash", SCM_BOOL_T);
2093 figured_bass_modification:
2095 $$ = ly_symbol2scm ("plus");
2098 $$ = ly_symbol2scm ("exclamation");
2101 $$ = ly_symbol2scm ("slash");
2104 $$ = ly_symbol2scm ("backslash");
2114 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2122 | figure_list br_bass_figure {
2123 $$ = scm_cons ($2, $1);
2128 FIGURE_OPEN figure_list FIGURE_CLOSE {
2129 $$ = scm_reverse_x ($2, SCM_EOL);
2140 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2141 if (!PARSER->lexer_->is_note_state ())
2142 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2146 n = MY_MAKE_MUSIC ("RestEvent", @$);
2148 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2150 n->set_property ("pitch", $1);
2151 n->set_property ("duration", $5);
2153 if (scm_is_number ($4))
2155 int q = scm_to_int ($4);
2156 n->set_property ("absolute-octave", scm_from_int (q-1));
2160 n->set_property ("cautionary", SCM_BOOL_T);
2161 if ($2 % 2 || $3 % 2)
2162 n->set_property ("force-accidental", SCM_BOOL_T);
2164 $$ = n->unprotect ();
2166 | DRUM_PITCH optional_notemode_duration {
2167 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2168 n->set_property ("duration", $2);
2169 n->set_property ("drum-type", $1);
2171 $$ = n->unprotect ();
2173 | RESTNAME optional_notemode_duration {
2175 if (ly_scm2string ($1) == "s") {
2177 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2180 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2183 ev->set_property ("duration", $2);
2184 $$ = ev->unprotect ();
2186 | lyric_element optional_notemode_duration {
2187 if (!PARSER->lexer_->is_lyric_state ())
2188 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2190 Music *levent = MY_MAKE_MUSIC ("LyricEvent", @$);
2191 levent->set_property ("text", $1);
2192 levent->set_property ("duration",$2);
2193 $$= levent->unprotect ();
2197 simple_chord_elements:
2199 $$ = scm_list_1 ($1);
2202 if (!PARSER->lexer_->is_chord_state ())
2203 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2206 | figure_spec optional_notemode_duration {
2207 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2209 unsmob_music (scm_car (s))->set_property ("duration", $2);
2225 steno_tonic_pitch optional_notemode_duration {
2226 $$ = make_chord_elements ($1, $2, SCM_EOL);
2228 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2229 SCM its = scm_reverse_x ($4, SCM_EOL);
2230 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2238 | chord_items chord_item {
2239 $$ = scm_cons ($2, $$);
2245 $$ = ly_symbol2scm ("chord-colon");
2248 $$ = ly_symbol2scm ("chord-caret");
2250 | CHORD_SLASH steno_tonic_pitch {
2251 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2253 | CHORD_BASS steno_tonic_pitch {
2254 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2263 $$ = scm_reverse_x ($1, SCM_EOL);
2271 step_number { $$ = scm_cons ($1, SCM_EOL); }
2272 | step_numbers '.' step_number {
2273 $$ = scm_cons ($3, $$);
2279 $$ = make_chord_step ($1, 0);
2281 | bare_unsigned '+' {
2282 $$ = make_chord_step ($1, SHARP_ALTERATION);
2284 | bare_unsigned CHORD_MINUS {
2285 $$ = make_chord_step ($1, FLAT_ALTERATION);
2291 $$ = scm_from_int ($1);
2293 | bare_unsigned '~' bare_unsigned {
2294 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2301 TODO: should deprecate in favor of Scheme?
2305 number_expression '+' number_term {
2306 $$ = scm_sum ($1, $3);
2308 | number_expression '-' number_term {
2309 $$ = scm_difference ($1, $3);
2318 | number_factor '*' number_factor {
2319 $$ = scm_product ($1, $3);
2321 | number_factor '/' number_factor {
2322 $$ = scm_divide ($1, $3);
2327 '-' number_factor { /* %prec UNARY_MINUS */
2328 $$ = scm_difference ($2, SCM_UNDEFINED);
2336 $$ = scm_from_int ($1);
2341 | NUMBER_IDENTIFIER {
2344 | REAL NUMBER_IDENTIFIER {
2345 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2347 | UNSIGNED NUMBER_IDENTIFIER {
2348 $$ = scm_from_double ($1 *scm_to_double ($2));
2363 bare_unsigned { $$ = scm_from_int ($1); }
2364 | NUMBER_IDENTIFIER {
2371 | exclamations '!' { $$ ++; }
2376 | questions '?' { $$ ++; }
2380 This should be done more dynamically if possible.
2384 LYRIC_MARKUP_IDENTIFIER {
2388 { PARSER->lexer_->push_markup_state (); }
2391 PARSER->lexer_->pop_state ();
2396 MARKUPLINES_IDENTIFIER {
2400 { PARSER->lexer_->push_markup_state (); }
2403 PARSER->lexer_->pop_state ();
2412 { PARSER->lexer_->push_markup_state (); }
2415 PARSER->lexer_->pop_state ();
2421 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2423 | markup_head_1_list simple_markup {
2424 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2432 MARKUPLINES_IDENTIFIER {
2435 | markup_composed_list {
2438 | markup_braced_list {
2441 | markup_command_list {
2442 $$ = scm_list_1 ($1);
2446 markup_composed_list:
2447 markup_head_1_list markup_braced_list {
2448 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2454 '{' markup_braced_list_body '}' {
2455 $$ = scm_reverse_x ($2, SCM_EOL);
2459 markup_braced_list_body:
2460 /* empty */ { $$ = SCM_EOL; }
2461 | markup_braced_list_body markup {
2462 $$ = scm_cons ($2, $1);
2464 | markup_braced_list_body markup_list {
2465 $$ = scm_reverse_x ($2, $1);
2469 markup_command_list:
2470 MARKUP_LIST_FUNCTION markup_command_list_arguments {
2471 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
2475 markup_command_basic_arguments:
2476 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
2477 $$ = scm_cons ($3, $2);
2479 | EXPECT_SCM markup_command_list_arguments embedded_scm {
2480 $$ = scm_cons ($3, $2);
2482 | EXPECT_NO_MORE_ARGS {
2487 markup_command_list_arguments:
2488 markup_command_basic_arguments { $$ = $1; }
2489 | EXPECT_MARKUP markup_command_list_arguments markup {
2490 $$ = scm_cons ($3, $2);
2495 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
2496 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
2501 markup_head_1_item {
2502 $$ = scm_list_1 ($1);
2504 | markup_head_1_list markup_head_1_item {
2505 $$ = scm_cons ($2, $1);
2511 $$ = make_simple_markup ($1);
2513 | MARKUP_IDENTIFIER {
2516 | LYRIC_MARKUP_IDENTIFIER {
2519 | STRING_IDENTIFIER {
2523 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2524 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2525 } '{' score_body '}' {
2527 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2529 PARSER->lexer_->pop_state ();
2531 | MARKUP_FUNCTION markup_command_basic_arguments {
2532 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
2537 markup_head_1_list simple_markup {
2538 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2539 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2549 Lily_parser::set_yydebug (bool x)
2555 Lily_parser::do_yyparse ()
2557 yyparse ((void*)this);
2566 It is a little strange to have this function in this file, but
2567 otherwise, we have to import music classes into the lexer.
2571 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2573 if (scm_is_string (sid)) {
2575 return STRING_IDENTIFIER;
2576 } else if (unsmob_book (sid)) {
2577 Book *book = unsmob_book (sid)->clone ();
2578 *destination = book->self_scm ();
2581 return BOOK_IDENTIFIER;
2582 } else if (scm_is_number (sid)) {
2584 return NUMBER_IDENTIFIER;
2585 } else if (unsmob_context_def (sid)) {
2586 Context_def *def= unsmob_context_def (sid)->clone ();
2588 *destination = def->self_scm ();
2591 return CONTEXT_DEF_IDENTIFIER;
2592 } else if (unsmob_context_mod (sid)) {
2593 *destination = unsmob_context_mod (sid)->smobbed_copy ();
2595 return CONTEXT_MOD_IDENTIFIER;
2596 } else if (unsmob_score (sid)) {
2597 Score *score = new Score (*unsmob_score (sid));
2598 *destination = score->self_scm ();
2600 score->unprotect ();
2601 return SCORE_IDENTIFIER;
2602 } else if (Music *mus = unsmob_music (sid)) {
2603 mus = mus->clone ();
2604 *destination = mus->self_scm ();
2605 unsmob_music (*destination)->
2606 set_property ("origin", make_input (last_input_));
2608 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2612 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2613 } else if (unsmob_duration (sid)) {
2614 *destination = unsmob_duration (sid)->smobbed_copy ();
2615 return DURATION_IDENTIFIER;
2616 } else if (unsmob_output_def (sid)) {
2617 Output_def *p = unsmob_output_def (sid);
2620 *destination = p->self_scm ();
2622 return OUTPUT_DEF_IDENTIFIER;
2623 } else if (Text_interface::is_markup (sid)) {
2625 if (is_lyric_state ())
2626 return LYRIC_MARKUP_IDENTIFIER;
2627 return MARKUP_IDENTIFIER;
2628 } else if (Text_interface::is_markup_list (sid)) {
2630 return MARKUPLINES_IDENTIFIER;
2637 get_next_unique_context_id ()
2639 return scm_from_locale_string ("$uniqueContextId");
2644 get_next_unique_lyrics_context_id ()
2646 static int new_context_count;
2648 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2649 return scm_from_locale_string (s);
2654 run_music_function (Lily_parser *parser, SCM expr)
2656 SCM func = scm_car (expr);
2657 Input *loc = unsmob_input (scm_cadr (expr));
2658 SCM args = scm_cddr (expr);
2659 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2661 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2663 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2665 parser->error_level_ = 1;
2666 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (*loc)));
2669 SCM syntax_args = scm_list_4 (parser->self_scm (), make_input (*loc), func, args);
2670 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
2674 is_regular_identifier (SCM id)
2676 string str = ly_scm2string (id);
2677 char const *s = str.c_str ();
2686 v = v && isalnum (*s);
2693 make_music_with_input (SCM name, Input where)
2695 Music *m = make_music_by_name (name);
2696 m->set_spot (where);
2701 get_first_context_id (SCM type, Music *m)
2703 SCM id = m->get_property ("context-id");
2704 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2705 && scm_is_string (m->get_property ("context-id"))
2706 && scm_c_string_length (id) > 0)
2714 make_simple_markup (SCM a)
2722 return t && t == 1 << intlog2 (t);
2726 set_music_properties (Music *p, SCM a)
2728 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2729 p->set_property (scm_caar (k), scm_cdar (k));
2734 make_chord_step (int step, Rational alter)
2737 alter += FLAT_ALTERATION;
2741 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2742 return m.smobbed_copy ();
2747 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
2749 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
2750 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
2754 /* Todo: actually also use apply iso. call too ... */
2756 ly_input_procedure_p (SCM x)
2758 return ly_is_procedure (x)
2759 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2763 make_music_relative (Pitch start, SCM music, Input loc)
2765 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic", loc);
2766 relative->set_property ("element", music);
2768 Music *m = unsmob_music (music);
2769 Pitch last = m->to_relative_octave (start);
2770 if (lily_1_8_relative)
2771 m->set_property ("last-pitch", last.smobbed_copy ());
2772 return relative->unprotect ();
2776 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2778 Lily_parser *pars = (Lily_parser*) v;
2779 Lily_lexer *lex = pars->lexer_;
2781 lex->lexval_ = (void*) s;
2783 lex->prepare_for_next_token ();
2784 return lex->yylex ();