2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2010 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_SCM;
274 %token <i> EXPECT_MARKUP_LIST
275 /* After the last argument. */
276 %token <i> EXPECT_NO_MORE_ARGS;
278 %token <scm> BOOK_IDENTIFIER
279 %token <scm> CHORDMODIFIER_PITCH
280 %token <scm> CHORD_MODIFIER
281 %token <scm> CHORD_REPETITION
282 %token <scm> CONTEXT_DEF_IDENTIFIER
283 %token <scm> CONTEXT_MOD_IDENTIFIER
284 %token <scm> DRUM_PITCH
285 %token <scm> DURATION_IDENTIFIER
286 %token <scm> EVENT_IDENTIFIER
287 %token <scm> FRACTION
288 %token <scm> LYRICS_STRING
289 %token <scm> LYRIC_MARKUP_IDENTIFIER
290 %token <scm> MARKUP_FUNCTION
291 %token <scm> MARKUP_LIST_FUNCTION
292 %token <scm> MARKUP_IDENTIFIER
293 %token <scm> MUSIC_FUNCTION
294 %token <scm> MUSIC_IDENTIFIER
295 %token <scm> NOTENAME_PITCH
296 %token <scm> NUMBER_IDENTIFIER
297 %token <scm> OUTPUT_DEF_IDENTIFIER
299 %token <scm> RESTNAME
300 %token <scm> SCM_IDENTIFIER
301 %token <scm> SCM_TOKEN
302 %token <scm> SCORE_IDENTIFIER
304 %token <scm> STRING_IDENTIFIER
305 %token <scm> TONICNAME_PITCH
308 %type <book> book_block
309 %type <book> book_body
310 %type <book> bookpart_block
311 %type <book> bookpart_body
313 %type <i> bare_unsigned
314 %type <scm> figured_bass_alteration
316 %type <i> exclamations
317 %type <i> optional_rest
322 %type <i> tremolo_type
325 %type <scm> composite_music
326 %type <scm> grouped_music_list
328 %type <scm> prefix_composite_music
329 %type <scm> repeated_music
330 %type <scm> sequential_music
331 %type <scm> simple_music
332 %type <scm> simultaneous_music
333 %type <scm> chord_body
334 %type <scm> chord_body_element
335 %type <scm> command_element
336 %type <scm> command_event
337 %type <scm> context_modification
338 %type <scm> context_change
339 %type <scm> direction_less_event
340 %type <scm> direction_reqd_event
341 %type <scm> event_chord
342 %type <scm> gen_text_def
343 %type <scm> music_property_def
344 %type <scm> note_chord_element
345 %type <scm> post_event
346 %type <scm> re_rhythmed_music
347 %type <scm> relative_music
348 %type <scm> simple_element
349 %type <scm> simple_music_property_def
350 %type <scm> string_number_event
351 %type <scm> tempo_event
353 %type <outputdef> output_def_body
354 %type <outputdef> output_def_head
355 %type <outputdef> output_def_head_with_mode_switch
356 %type <outputdef> output_def
357 %type <outputdef> paper_block
359 %type <scm> alternative_music
360 %type <scm> generic_prefix_music_scm
361 %type <scm> music_list
362 %type <scm> absolute_pitch
363 %type <scm> assignment_id
364 %type <scm> bare_number
365 %type <scm> unsigned_number
366 %type <scm> bass_figure
367 %type <scm> figured_bass_modification
368 %type <scm> br_bass_figure
369 %type <scm> bass_number
370 %type <scm> chord_body_elements
371 %type <scm> chord_item
372 %type <scm> chord_items
373 %type <scm> chord_separator
374 %type <scm> context_def_mod
375 %type <scm> context_def_spec_block
376 %type <scm> context_def_spec_body
377 %type <scm> context_mod
378 %type <scm> context_mod_list
379 %type <scm> context_prop_spec
380 %type <scm> direction_less_char
381 %type <scm> duration_length
382 %type <scm> embedded_scm
383 %type <scm> figure_list
384 %type <scm> figure_spec
386 %type <scm> full_markup
387 %type <scm> full_markup_list
388 %type <scm> function_scm_argument
389 %type <scm> function_arglist
390 %type <scm> function_arglist_music_last
391 %type <scm> function_arglist_nonmusic_last
392 %type <scm> function_arglist_nonmusic
393 %type <scm> identifier_init
394 %type <scm> lilypond_header
395 %type <scm> lilypond_header_body
396 %type <scm> lyric_element
397 %type <scm> lyric_markup
399 %type <scm> markup_braced_list
400 %type <scm> markup_braced_list_body
401 %type <scm> markup_composed_list
402 %type <scm> markup_command_list
403 %type <scm> markup_command_list_arguments
404 %type <scm> markup_command_basic_arguments
405 %type <scm> markup_head_1_item
406 %type <scm> markup_head_1_list
407 %type <scm> markup_list
408 %type <scm> markup_top
409 %type <scm> mode_changing_head
410 %type <scm> mode_changing_head_with_context
411 %type <scm> multiplied_duration
412 %type <scm> music_function_identifier_musicless_prefix
413 %type <scm> music_function_event
414 %type <scm> music_function_chord_body
415 %type <scm> new_chord
416 %type <scm> new_lyrics
417 %type <scm> number_expression
418 %type <scm> number_factor
419 %type <scm> number_term
420 %type <scm> octave_check
421 %type <scm> optional_context_mod
422 %type <scm> optional_id
423 %type <scm> optional_notemode_duration
425 %type <scm> pitch_also_in_chords
426 %type <scm> post_events
427 %type <scm> property_operation
428 %type <scm> property_path property_path_revved
430 %type <scm> script_abbreviation
431 %type <scm> simple_chord_elements
432 %type <scm> simple_markup
433 %type <scm> simple_string
434 %type <scm> steno_duration
435 %type <scm> steno_pitch
436 %type <scm> steno_tonic_pitch
437 %type <scm> step_number
438 %type <scm> step_numbers
441 %type <score> score_block
442 %type <score> score_body
447 /* We don't assign precedence to / and *, because we might need varied
448 prec levels in different prods */
454 lilypond: /* empty */
455 | lilypond toplevel_expression {
457 | lilypond assignment {
460 PARSER->error_level_ = 1;
463 PARSER->error_level_ = 1;
470 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
474 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
475 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
480 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
481 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
482 bookpart->unprotect ();
487 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
488 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
492 Music *music = unsmob_music ($1);
493 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
494 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
497 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
498 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
501 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
502 scm_call_2 (proc, PARSER->self_scm (), $1);
506 Output_def * od = $1;
508 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
509 id = ly_symbol2scm ("$defaultpaper");
510 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
511 id = ly_symbol2scm ("$defaultmidi");
512 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
513 id = ly_symbol2scm ("$defaultlayout");
515 PARSER->lexer_->set_identifier (id, od->self_scm ());
526 lilypond_header_body:
528 $$ = get_header (PARSER);
529 PARSER->lexer_->add_scope ($$);
531 | lilypond_header_body assignment {
537 HEADER '{' lilypond_header_body '}' {
538 $$ = PARSER->lexer_->remove_scope ();
547 | LYRICS_STRING { $$ = $1; }
551 assignment_id '=' identifier_init {
552 PARSER->lexer_->set_identifier ($1, $3);
554 | assignment_id property_path '=' identifier_init {
555 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
556 PARSER->lexer_->set_identifier (path, $4);
559 TODO: devise standard for protection in parser.
561 The parser stack lives on the C-stack, which means that
562 all objects can be unprotected as soon as they're here.
572 $$ = $1->self_scm ();
576 $$ = $1->self_scm ();
580 $$ = $1->self_scm ();
584 $$ = $1->self_scm ();
587 | context_def_spec_block {
591 /* Hack: Create event-chord around standalone events.
592 Prevents the identifier from being interpreted as a post-event. */
593 Music *mus = unsmob_music ($1);
594 bool is_event = mus &&
595 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
600 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
605 | number_expression {
618 $$ = scm_from_int ($1);
620 | context_modification {
625 context_def_spec_block:
626 CONTEXT '{' context_def_spec_body '}'
632 context_def_spec_body:
634 $$ = Context_def::make_scm ();
635 unsmob_context_def ($$)->origin ()->set_spot (@$);
637 | CONTEXT_DEF_IDENTIFIER {
639 unsmob_context_def ($$)->origin ()->set_spot (@$);
641 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
642 Context_def*td = unsmob_context_def ($$);
644 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
645 SCM tag = scm_caar (p);
647 /* TODO: should make new tag "grob-definition" ? */
648 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
649 tag, scm_cons (scm_cdar (p), SCM_EOL)));
652 | context_def_spec_body context_mod {
653 unsmob_context_def ($$)->add_context_mod ($2);
655 | context_def_spec_body context_modification {
656 Context_def *td = unsmob_context_def ($$);
657 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
658 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
659 td->add_context_mod (scm_car (m));
667 BOOK '{' book_body '}' {
670 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
675 * Use 'handlers' like for toplevel-* stuff?
676 * grok \layout and \midi? */
680 init_papers (PARSER);
681 $$->origin ()->set_spot (@$);
682 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
683 $$->paper_->unprotect ();
684 push_paper (PARSER, $$->paper_);
685 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
686 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
687 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
688 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
691 $$ = unsmob_book ($1);
693 $$->origin ()->set_spot (@$);
694 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
696 | book_body paper_block {
699 set_paper (PARSER, $2);
701 | book_body bookpart_block {
703 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
704 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
705 bookpart->unprotect ();
707 | book_body score_block {
709 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
710 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
713 | book_body composite_music {
714 Music *music = unsmob_music ($2);
715 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
716 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
718 | book_body full_markup {
719 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
720 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
722 | book_body full_markup_list {
723 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
724 scm_call_2 (proc, $$->self_scm (), $2);
726 | book_body lilypond_header {
731 $$->scores_ = SCM_EOL;
732 $$->bookparts_ = SCM_EOL;
737 BOOKPART '{' bookpart_body '}' {
739 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
746 $$->origin ()->set_spot (@$);
747 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
750 $$ = unsmob_book ($1);
752 $$->origin ()->set_spot (@$);
753 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
755 | bookpart_body paper_block {
759 | bookpart_body score_block {
761 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
762 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
765 | bookpart_body composite_music {
766 Music *music = unsmob_music ($2);
767 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
768 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
770 | bookpart_body full_markup {
771 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
772 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
774 | bookpart_body full_markup_list {
775 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
776 scm_call_2 (proc, $$->self_scm (), $2);
778 | bookpart_body lilypond_header {
781 | bookpart_body error {
783 $$->scores_ = SCM_EOL;
788 SCORE '{' score_body '}' {
796 SCM scorify = ly_lily_module_constant ("scorify-music");
797 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
799 // pass ownernship to C++ again.
800 $$ = unsmob_score (score);
802 $$->origin ()->set_spot (@$);
805 $$ = unsmob_score ($1);
807 $$->origin ()->set_spot (@$);
809 | score_body lilypond_header {
812 | score_body output_def {
813 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
815 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
820 $$->add_output_def ($2);
825 $$->error_found_ = true;
837 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
839 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
841 $$ = get_paper (PARSER);
848 output_def_body '}' {
851 PARSER->lexer_->remove_scope ();
852 PARSER->lexer_->pop_state ();
858 $$ = get_paper (PARSER);
859 $$->input_origin_ = @$;
860 PARSER->lexer_->add_scope ($$->scope_);
863 Output_def *p = get_midi (PARSER);
865 PARSER->lexer_->add_scope (p->scope_);
868 Output_def *p = get_layout (PARSER);
870 PARSER->lexer_->add_scope (p->scope_);
875 output_def_head_with_mode_switch:
877 PARSER->lexer_->push_initial_state ();
883 output_def_head_with_mode_switch '{' {
885 $$->input_origin_.set_spot (@$);
887 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
890 Output_def *o = unsmob_output_def ($3);
891 o->input_origin_.set_spot (@$);
894 PARSER->lexer_->remove_scope ();
895 PARSER->lexer_->add_scope (o->scope_);
897 | output_def_body assignment {
900 | output_def_body context_def_spec_block {
901 assign_context_def ($$, $2);
903 | output_def_body error {
909 TEMPO steno_duration '=' bare_unsigned {
910 $$ = MAKE_SYNTAX ("tempo", @$, SCM_BOOL_F, $2, scm_from_int ($4));
912 | TEMPO string steno_duration '=' bare_unsigned {
913 $$ = MAKE_SYNTAX ("tempo", @$, make_simple_markup($2), $3, scm_from_int ($5));
915 | TEMPO full_markup steno_duration '=' bare_unsigned {
916 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, scm_from_int ($5));
919 $$ = MAKE_SYNTAX ("tempoText", @$, make_simple_markup($2) );
921 | TEMPO full_markup {
922 $$ = MAKE_SYNTAX ("tempoText", @$, $2 );
927 The representation of a list is the
931 to have efficient append. */
935 $$ = scm_cons (SCM_EOL, SCM_EOL);
939 SCM c = scm_cons ($2, SCM_EOL);
941 if (scm_is_pair (scm_cdr (s)))
942 scm_set_cdr_x (scm_cdr (s), c); /* append */
944 scm_set_car_x (s, c); /* set first cons */
945 scm_set_cdr_x (s, c); /* remember last cell */
947 | music_list embedded_scm {
951 Music *m = MY_MAKE_MUSIC("Music", @$);
953 m->set_property ("error-found", SCM_BOOL_T);
955 SCM c = scm_cons (m->self_scm (), SCM_EOL);
956 m->unprotect (); /* UGH */
958 if (scm_is_pair (scm_cdr (s)))
959 scm_set_cdr_x (scm_cdr (s), c); /* append */
961 scm_set_car_x (s, c); /* set first cons */
962 scm_set_cdr_x (s, c); /* remember last cell */
975 | ALTERNATIVE '{' music_list '}' {
982 REPEAT simple_string unsigned_number music alternative_music
984 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $5);
989 SEQUENTIAL '{' music_list '}' {
990 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($3));
992 | '{' music_list '}' {
993 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($2));
998 SIMULTANEOUS '{' music_list '}'{
999 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($3));
1001 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1002 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($2));
1009 | music_property_def
1013 context_modification:
1014 WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1016 PARSER->lexer_->pop_state ();
1019 | WITH CONTEXT_MOD_IDENTIFIER
1023 | CONTEXT_MOD_IDENTIFIER
1029 optional_context_mod:
1033 | context_modification
1041 $$ = Context_mod ().smobbed_copy ();
1043 | context_mod_list context_mod {
1044 unsmob_context_mod ($1)->add_context_mod ($2);
1046 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1047 Context_mod *md = unsmob_context_mod ($2);
1049 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1054 prefix_composite_music { $$ = $1; }
1055 | grouped_music_list { $$ = $1; }
1059 simultaneous_music { $$ = $1; }
1060 | sequential_music { $$ = $1; }
1063 function_scm_argument:
1068 /* An argument list. If a function \foo expects scm scm music, then the lexer expands \foo into the token sequence:
1069 MUSIC_FUNCTION EXPECT_MUSIC EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1070 and this rule returns the reversed list of arguments. */
1072 function_arglist_music_last:
1073 EXPECT_MUSIC function_arglist music {
1074 $$ = scm_cons ($3, $2);
1078 function_arglist_nonmusic_last:
1079 EXPECT_MARKUP function_arglist full_markup {
1080 $$ = scm_cons ($3, $2);
1082 | EXPECT_MARKUP function_arglist simple_string {
1083 $$ = scm_cons ($3, $2);
1085 | EXPECT_SCM function_arglist function_scm_argument {
1086 $$ = scm_cons ($3, $2);
1090 function_arglist_nonmusic: EXPECT_NO_MORE_ARGS {
1093 | EXPECT_MARKUP function_arglist_nonmusic full_markup {
1094 $$ = scm_cons ($3, $2);
1096 | EXPECT_MARKUP function_arglist_nonmusic simple_string {
1097 $$ = scm_cons ($3, $2);
1099 | EXPECT_SCM function_arglist_nonmusic function_scm_argument {
1100 $$ = scm_cons ($3, $2);
1104 function_arglist: EXPECT_NO_MORE_ARGS {
1105 /* This is for 0-ary functions, so they don't need to
1106 read a lookahead token */
1109 | function_arglist_music_last
1110 | function_arglist_nonmusic_last
1113 generic_prefix_music_scm:
1114 MUSIC_FUNCTION function_arglist {
1115 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1121 /**/ { $$ = SCM_EOL; }
1122 | '=' simple_string {
1128 prefix_composite_music:
1129 generic_prefix_music_scm {
1130 $$ = run_music_function (PARSER, $1);
1132 | CONTEXT simple_string optional_id optional_context_mod music {
1133 Context_mod *ctxmod = unsmob_context_mod ($4);
1136 mods = ctxmod->get_mods ();
1137 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, mods, SCM_BOOL_F);
1139 | NEWCONTEXT simple_string optional_id optional_context_mod music {
1140 Context_mod *ctxmod = unsmob_context_mod ($4);
1143 mods = ctxmod->get_mods ();
1144 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, mods, SCM_BOOL_T);
1147 | TIMES fraction music {
1148 $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3);
1150 | repeated_music { $$ = $1; }
1151 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords music {
1152 Pitch from = *unsmob_pitch ($2);
1153 Pitch to = *unsmob_pitch ($3);
1154 SCM pitch = pitch_interval (from, to).smobbed_copy ();
1155 $$ = MAKE_SYNTAX ("transpose-music", @$, pitch, $4);
1157 | mode_changing_head grouped_music_list {
1158 if ($1 == ly_symbol2scm ("chords"))
1160 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1166 PARSER->lexer_->pop_state ();
1168 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1169 Context_mod *ctxmod = unsmob_context_mod ($2);
1172 mods = ctxmod->get_mods ();
1173 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, $3, mods, SCM_BOOL_T);
1174 if ($1 == ly_symbol2scm ("ChordNames"))
1176 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1178 PARSER->lexer_->pop_state ();
1180 | relative_music { $$ = $1; }
1181 | re_rhythmed_music { $$ = $1; }
1186 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1187 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1189 $$ = ly_symbol2scm ("notes");
1193 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1194 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1196 $$ = ly_symbol2scm ("drums");
1199 PARSER->lexer_->push_figuredbass_state ();
1201 $$ = ly_symbol2scm ("figures");
1204 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1205 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1206 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1207 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1208 $$ = ly_symbol2scm ("chords");
1212 { PARSER->lexer_->push_lyric_state ();
1213 $$ = ly_symbol2scm ("lyrics");
1217 mode_changing_head_with_context:
1219 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1220 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1222 $$ = ly_symbol2scm ("DrumStaff");
1225 PARSER->lexer_->push_figuredbass_state ();
1227 $$ = ly_symbol2scm ("FiguredBass");
1230 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1231 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1232 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1233 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1234 $$ = ly_symbol2scm ("ChordNames");
1237 { PARSER->lexer_->push_lyric_state ();
1238 $$ = ly_symbol2scm ("Lyrics");
1244 RELATIVE absolute_pitch music {
1245 Pitch start = *unsmob_pitch ($2);
1246 $$ = make_music_relative (start, $3, @$);
1248 | RELATIVE composite_music {
1249 Pitch middle_c (0, 0, 0);
1250 $$ = make_music_relative (middle_c, $2, @$);
1255 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1257 grouped_music_list {
1258 /* Can also use music at the expensive of two S/Rs similar to
1259 \repeat \alternative */
1260 PARSER->lexer_->pop_state ();
1262 $$ = scm_cons ($3, SCM_EOL);
1265 PARSER->lexer_->push_lyric_state (); }
1267 PARSER->lexer_->pop_state ();
1268 $$ = scm_cons ($3, SCM_EOL);
1270 | new_lyrics ADDLYRICS {
1271 PARSER->lexer_->push_lyric_state ();
1272 } grouped_music_list {
1273 PARSER->lexer_->pop_state ();
1274 $$ = scm_cons ($4, $1);
1276 | new_lyrics ADDLYRICS {
1277 PARSER->lexer_->push_lyric_state ();
1278 } MUSIC_IDENTIFIER {
1279 PARSER->lexer_->pop_state ();
1280 $$ = scm_cons ($4, $1);
1285 grouped_music_list new_lyrics {
1286 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1288 | MUSIC_IDENTIFIER new_lyrics {
1289 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1291 | LYRICSTO simple_string {
1292 PARSER->lexer_->push_lyric_state ();
1294 PARSER->lexer_->pop_state ();
1295 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1300 CHANGE STRING '=' STRING {
1301 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1306 property_path_revved:
1308 $$ = scm_cons ($1, SCM_EOL);
1310 | property_path_revved embedded_scm {
1311 $$ = scm_cons ($2, $1);
1316 property_path_revved {
1317 $$ = scm_reverse_x ($1, SCM_EOL);
1323 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1324 scm_string_to_symbol ($1), $3);
1326 | UNSET simple_string {
1327 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1328 scm_string_to_symbol ($2));
1330 | OVERRIDE simple_string property_path '=' scalar {
1331 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1332 scm_string_to_symbol ($2), $5),
1335 | REVERT simple_string embedded_scm {
1336 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1337 scm_string_to_symbol ($2), $3);
1342 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1343 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1345 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1346 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1347 | DENIES { $$ = ly_symbol2scm ("denies"); }
1349 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1350 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1351 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1352 | NAME { $$ = ly_symbol2scm ("context-name"); }
1356 property_operation { $$ = $1; }
1357 | context_def_mod STRING {
1358 $$ = scm_list_2 ($1, $2);
1360 | context_def_mod embedded_scm {
1361 if (ly_symbol2scm ("consists") != $1)
1364 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1368 $$ = scm_list_2 ($1, $2);
1375 if (!is_regular_identifier ($1))
1377 @$.error (_("Grob name should be alphanumeric"));
1380 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1381 scm_string_to_symbol ($1));
1383 | simple_string '.' simple_string {
1384 $$ = scm_list_2 (scm_string_to_symbol ($1),
1385 scm_string_to_symbol ($3));
1389 simple_music_property_def:
1390 OVERRIDE context_prop_spec property_path '=' scalar {
1391 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1392 ly_symbol2scm ("OverrideProperty"),
1397 | REVERT context_prop_spec embedded_scm {
1398 $$ = scm_list_4 (scm_car ($2),
1399 ly_symbol2scm ("RevertProperty"),
1403 | SET context_prop_spec '=' scalar {
1404 $$ = scm_list_4 (scm_car ($2),
1405 ly_symbol2scm ("PropertySet"),
1409 | UNSET context_prop_spec {
1410 $$ = scm_list_3 (scm_car ($2),
1411 ly_symbol2scm ("PropertyUnset"),
1417 simple_music_property_def {
1418 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1420 | ONCE simple_music_property_def {
1421 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1429 | STRING_IDENTIFIER {
1432 | string '+' string {
1433 $$ = scm_string_append (scm_list_2 ($1, $3));
1437 simple_string: STRING {
1443 | STRING_IDENTIFIER {
1464 $$ = scm_from_int ($1);
1469 /* TODO: Create a special case that avoids the creation of
1470 EventChords around simple_elements that have no post_events?
1472 simple_chord_elements post_events {
1473 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1476 /* why is this giving wrong start location? -ns
1478 i.set_location (@1, @2);
1479 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1481 | CHORD_REPETITION optional_notemode_duration post_events {
1483 i.set_location (@1, @3);
1484 $$ = MAKE_SYNTAX ("repetition-chord", i,
1485 PARSER->lexer_->chord_repetition_.last_chord_,
1486 PARSER->lexer_->chord_repetition_.repetition_function_,
1487 $2, scm_reverse_x ($3, SCM_EOL));
1489 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1491 i.set_location (@1, @3);
1492 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1493 scm_reverse_x ($3, SCM_EOL));
1496 /* note chord elements are memorized into
1497 PARSER->lexer_->chord_repetition_ so that the chord repetition
1498 mechanism copy them when a chord repetition symbol is found
1500 | note_chord_element {
1501 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
1507 chord_body optional_notemode_duration post_events
1509 Music *m = unsmob_music ($1);
1510 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1511 SCM es = m->get_property ("elements");
1512 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1514 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1515 unsmob_music (scm_car (s))->set_property ("duration", dur);
1516 es = ly_append2 (es, postevs);
1518 m-> set_property ("elements", es);
1520 $$ = m->self_scm ();
1525 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1527 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1531 chord_body_elements:
1532 /* empty */ { $$ = SCM_EOL; }
1533 | chord_body_elements chord_body_element {
1534 $$ = scm_cons ($2, $1);
1539 pitch exclamations questions octave_check post_events
1546 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1547 n->set_property ("pitch", $1);
1549 n->set_property ("cautionary", SCM_BOOL_T);
1550 if (ex % 2 || q % 2)
1551 n->set_property ("force-accidental", SCM_BOOL_T);
1553 if (scm_is_pair (post)) {
1554 SCM arts = scm_reverse_x (post, SCM_EOL);
1555 n->set_property ("articulations", arts);
1557 if (scm_is_number (check))
1559 int q = scm_to_int (check);
1560 n->set_property ("absolute-octave", scm_from_int (q-1));
1563 $$ = n->unprotect ();
1565 | DRUM_PITCH post_events {
1566 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1567 n->set_property ("duration", $2);
1568 n->set_property ("drum-type", $1);
1570 if (scm_is_pair ($2)) {
1571 SCM arts = scm_reverse_x ($2, SCM_EOL);
1572 n->set_property ("articulations", arts);
1574 $$ = n->unprotect ();
1576 | music_function_chord_body {
1577 $$ = run_music_function (PARSER, $1);
1581 music_function_identifier_musicless_prefix: MUSIC_FUNCTION {
1582 SCM sig = scm_object_property (yylval.scm, ly_symbol2scm ("music-function-signature"));
1583 if (scm_is_pair (sig) && to_boolean (scm_memq (ly_music_p_proc, scm_cdr (scm_reverse (sig)))))
1585 PARSER->parser_error (@$, "Music function applied to event may not have a Music argument, except as the last argument.");
1590 music_function_chord_body:
1591 /* We could allow chord functions to have multiple music arguments,
1592 but it's more consistent with music_function_event if we
1593 prohibit it here too */
1594 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic chord_body_element {
1595 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1597 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1598 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1602 music_function_event:
1603 /* Post-events can only have the last argument as music, without this
1604 restriction we get a shift/reduce conflict from e.g.
1605 c8-\partcombine c8 -. */
1606 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic post_event {
1607 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1609 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1610 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1618 | SKIP duration_length {
1619 $$ = MAKE_SYNTAX ("skip-music", @$, $2);
1622 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1623 m->set_property ("span-direction", scm_from_int (START));
1624 $$ = m->unprotect();
1627 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1628 m->set_property ("span-direction", scm_from_int (STOP));
1629 $$ = m->unprotect ();
1632 $$ = MAKE_SYNTAX ("voice-separator", @$, SCM_UNDEFINED);
1635 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1637 Music *m = unsmob_music (pipe);
1642 $$ = m->unprotect ();
1645 $$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
1648 | PARTIAL duration_length {
1649 $$ = MAKE_SYNTAX ("partial", @$, $2);
1653 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1655 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1658 $$ = MAKE_SYNTAX ("make-mark-set", @$, $2);
1664 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
1667 Music *m = MY_MAKE_MUSIC ("MarkEvent", @$);
1668 $$ = m->unprotect ();
1674 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1675 $$ = key->unprotect ();
1677 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1679 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1680 if (scm_ilength ($3) > 0)
1682 key->set_property ("pitch-alist", $3);
1683 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1684 key->transpose (* unsmob_pitch ($2));
1686 PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1689 $$ = key->unprotect ();
1698 | post_events post_event {
1699 unsmob_music ($2)->set_spot (@2);
1700 $$ = scm_cons ($2, $$);
1705 direction_less_event {
1708 | '-' music_function_event {
1709 $$ = run_music_function (PARSER, $2);
1712 if (!PARSER->lexer_->is_lyric_state ())
1713 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1714 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
1717 if (!PARSER->lexer_->is_lyric_state ())
1718 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1719 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
1721 | script_dir direction_reqd_event {
1724 Music *m = unsmob_music ($2);
1725 m->set_property ("direction", scm_from_int ($1));
1729 | script_dir direction_less_event {
1732 Music *m = unsmob_music ($2);
1733 m->set_property ("direction", scm_from_int ($1));
1737 | string_number_event
1740 string_number_event:
1742 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
1743 s->set_property ("string-number", scm_from_int ($1));
1744 $$ = s->unprotect ();
1748 direction_less_char:
1750 $$ = ly_symbol2scm ("bracketOpenSymbol");
1753 $$ = ly_symbol2scm ("bracketCloseSymbol");
1756 $$ = ly_symbol2scm ("tildeSymbol");
1759 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1762 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1765 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1768 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1771 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1774 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1777 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1781 direction_less_event:
1782 direction_less_char {
1783 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
1785 if (unsmob_music (predefd))
1787 m = unsmob_music (predefd)->clone ();
1792 m = MY_MAKE_MUSIC ("Music", @$);
1794 $$ = m->unprotect ();
1796 | EVENT_IDENTIFIER {
1800 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
1801 a->set_property ("tremolo-type", scm_from_int ($1));
1802 $$ = a->unprotect ();
1806 direction_reqd_event:
1810 | script_abbreviation {
1811 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1812 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
1813 if (scm_is_string (s))
1814 a->set_property ("articulation-type", s);
1815 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
1816 $$ = a->unprotect ();
1821 /**/ { $$ = SCM_EOL; }
1822 | '=' { $$ = scm_from_int (0); }
1823 | '=' sub_quotes { $$ = scm_from_int (-$2); }
1824 | '=' sup_quotes { $$ = scm_from_int ($2); }
1849 | NOTENAME_PITCH sup_quotes {
1850 Pitch p = *unsmob_pitch ($1);
1851 p = p.transposed (Pitch ($2,0,0));
1852 $$ = p.smobbed_copy ();
1854 | NOTENAME_PITCH sub_quotes {
1855 Pitch p =* unsmob_pitch ($1);
1856 p = p.transposed (Pitch (-$2,0,0));
1857 $$ = p.smobbed_copy ();
1869 | TONICNAME_PITCH sup_quotes {
1870 Pitch p = *unsmob_pitch ($1);
1871 p = p.transposed (Pitch ($2,0,0));
1872 $$ = p.smobbed_copy ();
1874 | TONICNAME_PITCH sub_quotes {
1875 Pitch p = *unsmob_pitch ($1);
1877 p = p.transposed (Pitch (-$2,0,0));
1878 $$ = p.smobbed_copy ();
1888 pitch_also_in_chords:
1895 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1896 t->set_property ("text", $1);
1897 $$ = t->unprotect ();
1900 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1901 t->set_property ("text",
1902 make_simple_markup ($1));
1903 $$ = t->unprotect ();
1906 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
1907 t->set_property ("digit", scm_from_int ($1));
1908 $$ = t->unprotect ();
1912 script_abbreviation:
1914 $$ = scm_from_locale_string ("Hat");
1917 $$ = scm_from_locale_string ("Plus");
1920 $$ = scm_from_locale_string ("Dash");
1923 $$ = scm_from_locale_string ("Bar");
1926 $$ = scm_from_locale_string ("Larger");
1929 $$ = scm_from_locale_string ("Dot");
1932 $$ = scm_from_locale_string ("Underscore");
1939 | '-' { $$ = CENTER; }
1950 multiplied_duration {
1955 optional_notemode_duration:
1957 Duration dd = PARSER->default_duration_;
1958 $$ = dd.smobbed_copy ();
1960 | multiplied_duration {
1962 PARSER->default_duration_ = *unsmob_duration ($$);
1967 bare_unsigned dots {
1969 if (!is_duration ($1))
1970 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
1974 $$ = Duration (len, $2).smobbed_copy ();
1976 | DURATION_IDENTIFIER dots {
1977 Duration *d = unsmob_duration ($1);
1978 Duration k (d->duration_log (), d->dot_count () + $2);
1979 k = k.compressed (d->factor ());
1985 multiplied_duration:
1989 | multiplied_duration '*' bare_unsigned {
1990 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1992 | multiplied_duration '*' FRACTION {
1993 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1995 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2000 FRACTION { $$ = $1; }
2001 | UNSIGNED '/' UNSIGNED {
2002 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2019 | ':' bare_unsigned {
2020 if (!is_duration ($2))
2021 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2028 $$ = scm_from_int ($1);
2031 $$ = scm_from_int ($1);
2033 | STRING { $$ = $1; }
2034 | full_markup { $$ = $1; }
2037 figured_bass_alteration:
2038 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2039 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2040 | '!' { $$ = scm_from_int (0); }
2045 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2046 $$ = bfr->unprotect ();
2049 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2050 $$ = bfr->self_scm ();
2052 if (scm_is_number ($1))
2053 bfr->set_property ("figure", $1);
2054 else if (Text_interface::is_markup ($1))
2055 bfr->set_property ("text", $1);
2061 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2063 | bass_figure figured_bass_alteration {
2064 Music *m = unsmob_music ($1);
2065 if (scm_to_double ($2)) {
2066 SCM salter = m->get_property ("alteration");
2067 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2068 m->set_property ("alteration",
2069 scm_sum (alter, $2));
2071 m->set_property ("alteration", scm_from_int (0));
2074 | bass_figure figured_bass_modification {
2075 Music *m = unsmob_music ($1);
2076 if ($2 == ly_symbol2scm ("plus"))
2078 m->set_property ("augmented", SCM_BOOL_T);
2080 else if ($2 == ly_symbol2scm ("slash"))
2082 m->set_property ("diminished", SCM_BOOL_T);
2084 else if ($2 == ly_symbol2scm ("exclamation"))
2086 m->set_property ("no-continuation", SCM_BOOL_T);
2088 else if ($2 == ly_symbol2scm ("backslash"))
2090 m->set_property ("augmented-slash", SCM_BOOL_T);
2096 figured_bass_modification:
2098 $$ = ly_symbol2scm ("plus");
2101 $$ = ly_symbol2scm ("exclamation");
2104 $$ = ly_symbol2scm ("slash");
2107 $$ = ly_symbol2scm ("backslash");
2117 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2125 | figure_list br_bass_figure {
2126 $$ = scm_cons ($2, $1);
2131 FIGURE_OPEN figure_list FIGURE_CLOSE {
2132 $$ = scm_reverse_x ($2, SCM_EOL);
2143 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2144 if (!PARSER->lexer_->is_note_state ())
2145 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2149 n = MY_MAKE_MUSIC ("RestEvent", @$);
2151 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2153 n->set_property ("pitch", $1);
2154 n->set_property ("duration", $5);
2156 if (scm_is_number ($4))
2158 int q = scm_to_int ($4);
2159 n->set_property ("absolute-octave", scm_from_int (q-1));
2163 n->set_property ("cautionary", SCM_BOOL_T);
2164 if ($2 % 2 || $3 % 2)
2165 n->set_property ("force-accidental", SCM_BOOL_T);
2167 $$ = n->unprotect ();
2169 | DRUM_PITCH optional_notemode_duration {
2170 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2171 n->set_property ("duration", $2);
2172 n->set_property ("drum-type", $1);
2174 $$ = n->unprotect ();
2176 | RESTNAME optional_notemode_duration {
2178 if (ly_scm2string ($1) == "s") {
2180 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2183 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2186 ev->set_property ("duration", $2);
2187 $$ = ev->unprotect ();
2189 | lyric_element optional_notemode_duration {
2190 if (!PARSER->lexer_->is_lyric_state ())
2191 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2193 Music *levent = MY_MAKE_MUSIC ("LyricEvent", @$);
2194 levent->set_property ("text", $1);
2195 levent->set_property ("duration",$2);
2196 $$= levent->unprotect ();
2200 simple_chord_elements:
2202 $$ = scm_list_1 ($1);
2205 if (!PARSER->lexer_->is_chord_state ())
2206 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2209 | figure_spec optional_notemode_duration {
2210 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2212 unsmob_music (scm_car (s))->set_property ("duration", $2);
2228 steno_tonic_pitch optional_notemode_duration {
2229 $$ = make_chord_elements ($1, $2, SCM_EOL);
2231 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2232 SCM its = scm_reverse_x ($4, SCM_EOL);
2233 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2241 | chord_items chord_item {
2242 $$ = scm_cons ($2, $$);
2248 $$ = ly_symbol2scm ("chord-colon");
2251 $$ = ly_symbol2scm ("chord-caret");
2253 | CHORD_SLASH steno_tonic_pitch {
2254 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2256 | CHORD_BASS steno_tonic_pitch {
2257 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2266 $$ = scm_reverse_x ($1, SCM_EOL);
2274 step_number { $$ = scm_cons ($1, SCM_EOL); }
2275 | step_numbers '.' step_number {
2276 $$ = scm_cons ($3, $$);
2282 $$ = make_chord_step ($1, 0);
2284 | bare_unsigned '+' {
2285 $$ = make_chord_step ($1, SHARP_ALTERATION);
2287 | bare_unsigned CHORD_MINUS {
2288 $$ = make_chord_step ($1, FLAT_ALTERATION);
2295 TODO: should deprecate in favor of Scheme?
2299 number_expression '+' number_term {
2300 $$ = scm_sum ($1, $3);
2302 | number_expression '-' number_term {
2303 $$ = scm_difference ($1, $3);
2312 | number_factor '*' number_factor {
2313 $$ = scm_product ($1, $3);
2315 | number_factor '/' number_factor {
2316 $$ = scm_divide ($1, $3);
2321 '-' number_factor { /* %prec UNARY_MINUS */
2322 $$ = scm_difference ($2, SCM_UNDEFINED);
2330 $$ = scm_from_int ($1);
2335 | NUMBER_IDENTIFIER {
2338 | REAL NUMBER_IDENTIFIER {
2339 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2341 | UNSIGNED NUMBER_IDENTIFIER {
2342 $$ = scm_from_double ($1 *scm_to_double ($2));
2357 bare_unsigned { $$ = scm_from_int ($1); }
2358 | NUMBER_IDENTIFIER {
2366 | exclamations '!' { $$ ++; }
2371 | questions '?' { $$ ++; }
2375 This should be done more dynamically if possible.
2379 LYRIC_MARKUP_IDENTIFIER {
2383 { PARSER->lexer_->push_markup_state (); }
2386 PARSER->lexer_->pop_state ();
2392 { PARSER->lexer_->push_markup_state (); }
2395 PARSER->lexer_->pop_state ();
2404 { PARSER->lexer_->push_markup_state (); }
2407 PARSER->lexer_->pop_state ();
2413 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2415 | markup_head_1_list simple_markup {
2416 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2424 markup_composed_list {
2427 | markup_braced_list {
2430 | markup_command_list {
2431 $$ = scm_list_1 ($1);
2435 markup_composed_list:
2436 markup_head_1_list markup_braced_list {
2437 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2443 '{' markup_braced_list_body '}' {
2444 $$ = scm_reverse_x ($2, SCM_EOL);
2448 markup_braced_list_body:
2449 /* empty */ { $$ = SCM_EOL; }
2450 | markup_braced_list_body markup {
2451 $$ = scm_cons ($2, $1);
2453 | markup_braced_list_body markup_list {
2454 $$ = scm_reverse_x ($2, $1);
2458 markup_command_list:
2459 MARKUP_LIST_FUNCTION markup_command_list_arguments {
2460 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
2464 markup_command_basic_arguments:
2465 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
2466 $$ = scm_cons ($3, $2);
2468 | EXPECT_SCM markup_command_list_arguments embedded_scm {
2469 $$ = scm_cons ($3, $2);
2471 | EXPECT_NO_MORE_ARGS {
2476 markup_command_list_arguments:
2477 markup_command_basic_arguments { $$ = $1; }
2478 | EXPECT_MARKUP markup_command_list_arguments markup {
2479 $$ = scm_cons ($3, $2);
2484 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
2485 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
2490 markup_head_1_item {
2491 $$ = scm_list_1 ($1);
2493 | markup_head_1_list markup_head_1_item {
2494 $$ = scm_cons ($2, $1);
2500 $$ = make_simple_markup ($1);
2502 | MARKUP_IDENTIFIER {
2505 | LYRIC_MARKUP_IDENTIFIER {
2508 | STRING_IDENTIFIER {
2512 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2513 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2514 } '{' score_body '}' {
2516 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2518 PARSER->lexer_->pop_state ();
2520 | MARKUP_FUNCTION markup_command_basic_arguments {
2521 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
2526 markup_head_1_list simple_markup {
2527 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2528 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2538 Lily_parser::set_yydebug (bool x)
2544 Lily_parser::do_yyparse ()
2546 yyparse ((void*)this);
2555 It is a little strange to have this function in this file, but
2556 otherwise, we have to import music classes into the lexer.
2560 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2562 if (scm_is_string (sid)) {
2564 return STRING_IDENTIFIER;
2565 } else if (unsmob_book (sid)) {
2566 Book *book = unsmob_book (sid)->clone ();
2567 *destination = book->self_scm ();
2570 return BOOK_IDENTIFIER;
2571 } else if (scm_is_number (sid)) {
2573 return NUMBER_IDENTIFIER;
2574 } else if (unsmob_context_def (sid)) {
2575 Context_def *def= unsmob_context_def (sid)->clone ();
2577 *destination = def->self_scm ();
2580 return CONTEXT_DEF_IDENTIFIER;
2581 } else if (unsmob_context_mod (sid)) {
2582 *destination = unsmob_context_mod (sid)->smobbed_copy ();
2584 return CONTEXT_MOD_IDENTIFIER;
2585 } else if (unsmob_score (sid)) {
2586 Score *score = new Score (*unsmob_score (sid));
2587 *destination = score->self_scm ();
2589 score->unprotect ();
2590 return SCORE_IDENTIFIER;
2591 } else if (Music *mus = unsmob_music (sid)) {
2592 mus = mus->clone ();
2593 *destination = mus->self_scm ();
2594 unsmob_music (*destination)->
2595 set_property ("origin", make_input (last_input_));
2597 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2601 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2602 } else if (unsmob_duration (sid)) {
2603 *destination = unsmob_duration (sid)->smobbed_copy ();
2604 return DURATION_IDENTIFIER;
2605 } else if (unsmob_output_def (sid)) {
2606 Output_def *p = unsmob_output_def (sid);
2609 *destination = p->self_scm ();
2611 return OUTPUT_DEF_IDENTIFIER;
2612 } else if (Text_interface::is_markup (sid)) {
2614 if (is_lyric_state ())
2615 return LYRIC_MARKUP_IDENTIFIER;
2616 return MARKUP_IDENTIFIER;
2623 get_next_unique_context_id ()
2625 return scm_from_locale_string ("$uniqueContextId");
2630 get_next_unique_lyrics_context_id ()
2632 static int new_context_count;
2634 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2635 return scm_from_locale_string (s);
2640 run_music_function (Lily_parser *parser, SCM expr)
2642 SCM func = scm_car (expr);
2643 Input *loc = unsmob_input (scm_cadr (expr));
2644 SCM args = scm_cddr (expr);
2645 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2647 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2649 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2651 parser->error_level_ = 1;
2652 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (*loc)));
2655 SCM syntax_args = scm_list_4 (parser->self_scm (), make_input (*loc), func, args);
2656 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
2660 is_regular_identifier (SCM id)
2662 string str = ly_scm2string (id);
2663 char const *s = str.c_str ();
2672 v = v && isalnum (*s);
2679 make_music_with_input (SCM name, Input where)
2681 Music *m = make_music_by_name (name);
2682 m->set_spot (where);
2687 get_first_context_id (SCM type, Music *m)
2689 SCM id = m->get_property ("context-id");
2690 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2691 && scm_is_string (m->get_property ("context-id"))
2692 && scm_c_string_length (id) > 0)
2700 make_simple_markup (SCM a)
2708 return t && t == 1 << intlog2 (t);
2712 set_music_properties (Music *p, SCM a)
2714 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2715 p->set_property (scm_caar (k), scm_cdar (k));
2720 make_chord_step (int step, Rational alter)
2723 alter += FLAT_ALTERATION;
2727 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2728 return m.smobbed_copy ();
2733 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
2735 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
2736 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
2740 /* Todo: actually also use apply iso. call too ... */
2742 ly_input_procedure_p (SCM x)
2744 return ly_is_procedure (x)
2745 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2749 make_music_relative (Pitch start, SCM music, Input loc)
2751 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic", loc);
2752 relative->set_property ("element", music);
2754 Music *m = unsmob_music (music);
2755 Pitch last = m->to_relative_octave (start);
2756 if (lily_1_8_relative)
2757 m->set_property ("last-pitch", last.smobbed_copy ());
2758 return relative->unprotect ();
2762 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2764 Lily_parser *pars = (Lily_parser*) v;
2765 Lily_lexer *lex = pars->lexer_;
2767 lex->lexval_ = (void*) s;
2769 lex->prepare_for_next_token ();
2770 return lex->yylex ();