2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2009 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 "dimensions.hh"
88 #include "file-path.hh"
90 #include "international.hh"
91 #include "lily-guile.hh"
92 #include "lily-lexer.hh"
93 #include "lily-parser.hh"
98 #include "output-def.hh"
99 #include "paper-book.hh"
100 #include "program-option.hh"
101 #include "scm-hash.hh"
103 #include "text-interface.hh"
111 Output_def *outputdef;
121 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
124 - Don't use lily module, create a new module instead.
125 - delay application of the function
127 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
128 scm_apply_0 (proc, args)
129 /* Syntactic Sugar. */
130 #define MAKE_SYNTAX(name, location, ...) \
131 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location), __VA_ARGS__, SCM_UNDEFINED));
133 SCM get_next_unique_context_id ();
134 SCM get_next_unique_lyrics_context_id ();
141 #define _(x) gettext (x)
145 static Music *make_music_with_input (SCM name, Input where);
146 SCM make_music_relative (Pitch start, SCM music, Input loc);
147 SCM run_music_function (Lily_parser *, SCM expr);
148 SCM get_first_context_id (SCM type, Music *m);
149 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
150 SCM make_chord_step (int step, Rational alter);
151 SCM make_simple_markup (SCM a);
152 bool is_duration (int t);
153 bool is_regular_identifier (SCM id);
154 bool ly_input_procedure_p (SCM x);
155 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
156 void set_music_properties (Music *p, SCM a);
160 /* The third option is an alias that will be used to display the
161 syntax error. Bison CVS now correctly handles backslash escapes.
163 FIXME: Bison needs to translate some of these, eg, STRING.
167 /* Keyword tokens with plain escaped name. */
168 %token ACCEPTS "\\accepts"
169 %token ADDLYRICS "\\addlyrics"
170 %token ALIAS "\\alias"
171 %token ALTERNATIVE "\\alternative"
173 %token BOOKPART "\\bookpart"
174 %token CHANGE "\\change"
175 %token CHORDMODE "\\chordmode"
176 %token CHORDS "\\chords"
177 %token CONSISTS "\\consists"
178 %token CONTEXT "\\context"
179 %token DEFAULT "\\default"
180 %token DEFAULTCHILD "\\defaultchild"
181 %token DENIES "\\denies"
182 %token DESCRIPTION "\\description"
183 %token DRUMMODE "\\drummode"
184 %token DRUMS "\\drums"
185 %token FIGUREMODE "\\figuremode"
186 %token FIGURES "\\figures"
187 %token GROBDESCRIPTIONS "\\grobdescriptions"
188 %token HEADER "\\header"
189 %token INVALID "\\invalid"
191 %token LAYOUT "\\layout"
192 %token LYRICMODE "\\lyricmode"
193 %token LYRICS "\\lyrics"
194 %token LYRICSTO "\\lyricsto"
196 %token MARKUP "\\markup"
197 %token MARKUPLINES "\\markuplines"
200 %token NOTEMODE "\\notemode"
201 %token OBJECTID "\\objectid"
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 /* After the last argument. */
275 %token <i> EXPECT_NO_MORE_ARGS;
277 %token <scm> BOOK_IDENTIFIER
278 %token <scm> CHORDMODIFIER_PITCH
279 %token <scm> CHORD_MODIFIER
280 %token <scm> CHORD_REPETITION
281 %token <scm> CONTEXT_DEF_IDENTIFIER
282 %token <scm> DRUM_PITCH
283 %token <scm> DURATION_IDENTIFIER
284 %token <scm> EVENT_IDENTIFIER
285 %token <scm> FRACTION
286 %token <scm> LYRICS_STRING
287 %token <scm> LYRIC_MARKUP_IDENTIFIER
288 %token <scm> MARKUP_HEAD_EMPTY
289 %token <scm> MARKUP_HEAD_LIST0
290 %token <scm> MARKUP_HEAD_MARKUP0
291 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
292 %token <scm> MARKUP_HEAD_SCM0
293 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
294 %token <scm> MARKUP_HEAD_SCM0_SCM1
295 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
296 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2_MARKUP3
297 %token <scm> MARKUP_HEAD_SCM0_MARKUP1_MARKUP2
298 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
299 %token <scm> MARKUP_LIST_HEAD_EMPTY
300 %token <scm> MARKUP_LIST_HEAD_LIST0
301 %token <scm> MARKUP_LIST_HEAD_SCM0
302 %token <scm> MARKUP_LIST_HEAD_SCM0_LIST1
303 %token <scm> MARKUP_LIST_HEAD_SCM0_SCM1_LIST2
304 %token <scm> MARKUP_IDENTIFIER
305 %token <scm> MUSIC_FUNCTION
306 %token <scm> MUSIC_IDENTIFIER
307 %token <scm> NOTENAME_PITCH
308 %token <scm> NUMBER_IDENTIFIER
309 %token <scm> OUTPUT_DEF_IDENTIFIER
311 %token <scm> RESTNAME
312 %token <scm> SCM_IDENTIFIER
313 %token <scm> SCM_TOKEN
314 %token <scm> SCORE_IDENTIFIER
316 %token <scm> STRING_IDENTIFIER
317 %token <scm> TONICNAME_PITCH
320 %type <book> book_block
321 %type <book> book_body
322 %type <book> bookpart_block
323 %type <book> bookpart_body
325 %type <i> bare_unsigned
326 %type <scm> figured_bass_alteration
328 %type <i> exclamations
329 %type <i> optional_rest
334 %type <i> tremolo_type
337 %type <scm> composite_music
338 %type <scm> grouped_music_list
340 %type <scm> prefix_composite_music
341 %type <scm> repeated_music
342 %type <scm> sequential_music
343 %type <scm> simple_music
344 %type <scm> simultaneous_music
345 %type <scm> chord_body
346 %type <scm> chord_body_element
347 %type <scm> command_element
348 %type <scm> command_event
349 %type <scm> context_change
350 %type <scm> direction_less_event
351 %type <scm> direction_reqd_event
352 %type <scm> event_chord
353 %type <scm> gen_text_def
354 %type <scm> music_property_def
355 %type <scm> note_chord_element
356 %type <scm> post_event
357 %type <scm> re_rhythmed_music
358 %type <scm> relative_music
359 %type <scm> simple_element
360 %type <scm> simple_music_property_def
361 %type <scm> string_number_event
362 %type <scm> tempo_event
364 %type <outputdef> output_def_body
365 %type <outputdef> output_def_head
366 %type <outputdef> output_def_head_with_mode_switch
367 %type <outputdef> output_def
368 %type <outputdef> paper_block
370 %type <scm> alternative_music
371 %type <scm> generic_prefix_music_scm
372 %type <scm> music_list
373 %type <scm> absolute_pitch
374 %type <scm> assignment_id
375 %type <scm> bare_number
376 %type <scm> unsigned_number
377 %type <scm> bass_figure
378 %type <scm> figured_bass_modification
379 %type <scm> br_bass_figure
380 %type <scm> bass_number
381 %type <scm> chord_body_elements
382 %type <scm> chord_item
383 %type <scm> chord_items
384 %type <scm> chord_separator
385 %type <scm> context_def_mod
386 %type <scm> context_def_spec_block
387 %type <scm> context_def_spec_body
388 %type <scm> context_mod
389 %type <scm> context_mod_list
390 %type <scm> context_prop_spec
391 %type <scm> direction_less_char
392 %type <scm> duration_length
393 %type <scm> embedded_scm
394 %type <scm> figure_list
395 %type <scm> figure_spec
397 %type <scm> full_markup
398 %type <scm> full_markup_list
399 %type <scm> function_scm_argument
400 %type <scm> function_arglist
401 %type <scm> function_arglist_music_last
402 %type <scm> function_arglist_nonmusic_last
403 %type <scm> function_arglist_nonmusic
404 %type <scm> identifier_init
405 %type <scm> lilypond_header
406 %type <scm> lilypond_header_body
407 %type <scm> lyric_element
408 %type <scm> lyric_markup
410 %type <scm> markup_braced_list
411 %type <scm> markup_braced_list_body
412 %type <scm> markup_composed_list
413 %type <scm> markup_command_list
414 %type <scm> markup_head_1_item
415 %type <scm> markup_head_1_list
416 %type <scm> markup_list
417 %type <scm> markup_top
418 %type <scm> mode_changing_head
419 %type <scm> mode_changing_head_with_context
420 %type <scm> multiplied_duration
421 %type <scm> music_function_identifier_musicless_prefix
422 %type <scm> music_function_event
423 %type <scm> music_function_chord_body
424 %type <scm> new_chord
425 %type <scm> new_lyrics
426 %type <scm> number_expression
427 %type <scm> number_factor
428 %type <scm> number_term
429 %type <scm> object_id_setting
430 %type <scm> octave_check
431 %type <scm> optional_context_mod
432 %type <scm> optional_id
433 %type <scm> optional_notemode_duration
435 %type <scm> pitch_also_in_chords
436 %type <scm> post_events
437 %type <scm> property_operation
438 %type <scm> property_path property_path_revved
440 %type <scm> script_abbreviation
441 %type <scm> simple_chord_elements
442 %type <scm> simple_markup
443 %type <scm> simple_string
444 %type <scm> steno_duration
445 %type <scm> steno_pitch
446 %type <scm> steno_tonic_pitch
447 %type <scm> step_number
448 %type <scm> step_numbers
451 %type <score> score_block
452 %type <score> score_body
457 /* We don't assign precedence to / and *, because we might need varied
458 prec levels in different prods */
464 lilypond: /* empty */
465 | lilypond toplevel_expression {
467 | lilypond assignment {
470 PARSER->error_level_ = 1;
473 PARSER->error_level_ = 1;
479 OBJECTID STRING { $$ = $2; }
484 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
488 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
489 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
494 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
495 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
496 bookpart->unprotect ();
501 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
502 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
506 Music *music = unsmob_music ($1);
507 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
508 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
511 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
512 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
515 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
516 scm_call_2 (proc, PARSER->self_scm (), $1);
520 Output_def * od = $1;
522 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
523 id = ly_symbol2scm ("$defaultpaper");
524 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
525 id = ly_symbol2scm ("$defaultmidi");
526 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
527 id = ly_symbol2scm ("$defaultlayout");
529 PARSER->lexer_->set_identifier (id, od->self_scm ());
540 lilypond_header_body:
542 $$ = get_header (PARSER);
543 PARSER->lexer_->add_scope ($$);
545 | lilypond_header_body assignment {
551 HEADER '{' lilypond_header_body '}' {
552 $$ = PARSER->lexer_->remove_scope ();
561 | LYRICS_STRING { $$ = $1; }
565 assignment_id '=' identifier_init {
566 PARSER->lexer_->set_identifier ($1, $3);
569 TODO: devise standard for protection in parser.
571 The parser stack lives on the C-stack, which means that
572 all objects can be unprotected as soon as they're here.
582 $$ = $1->self_scm ();
586 $$ = $1->self_scm ();
590 $$ = $1->self_scm ();
594 $$ = $1->self_scm ();
597 | context_def_spec_block {
601 /* Hack: Create event-chord around standalone events.
602 Prevents the identifier from being interpreted as a post-event. */
603 Music *mus = unsmob_music ($1);
604 bool is_event = mus &&
605 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
610 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
615 | number_expression {
628 $$ = scm_from_int ($1);
632 context_def_spec_block:
633 CONTEXT '{' context_def_spec_body '}'
639 context_def_spec_body:
641 $$ = Context_def::make_scm ();
642 unsmob_context_def ($$)->origin ()->set_spot (@$);
644 | CONTEXT_DEF_IDENTIFIER {
646 unsmob_context_def ($$)->origin ()->set_spot (@$);
648 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
649 Context_def*td = unsmob_context_def ($$);
651 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
652 SCM tag = scm_caar (p);
654 /* TODO: should make new tag "grob-definition" ? */
655 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
656 tag, scm_cons (scm_cdar (p), SCM_EOL)));
659 | context_def_spec_body context_mod {
660 unsmob_context_def ($$)->add_context_mod ($2);
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;
734 | book_body object_id_setting {
735 $$->user_key_ = ly_scm2string ($2);
740 BOOKPART '{' bookpart_body '}' {
742 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
749 $$->origin ()->set_spot (@$);
750 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
753 $$ = unsmob_book ($1);
755 $$->origin ()->set_spot (@$);
756 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
758 | bookpart_body paper_block {
762 | bookpart_body score_block {
764 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
765 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
768 | bookpart_body composite_music {
769 Music *music = unsmob_music ($2);
770 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
771 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
773 | bookpart_body full_markup {
774 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
775 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
777 | bookpart_body full_markup_list {
778 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
779 scm_call_2 (proc, $$->self_scm (), $2);
781 | bookpart_body lilypond_header {
784 | bookpart_body error {
786 $$->scores_ = SCM_EOL;
788 | bookpart_body object_id_setting {
789 $$->user_key_ = ly_scm2string ($2);
794 SCORE '{' score_body '}' {
802 SCM scorify = ly_lily_module_constant ("scorify-music");
803 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
805 // pass ownernship to C++ again.
806 $$ = unsmob_score (score);
808 $$->origin ()->set_spot (@$);
811 $$ = unsmob_score ($1);
813 $$->origin ()->set_spot (@$);
815 | score_body object_id_setting {
816 $$->user_key_ = ly_scm2string ($2);
818 | score_body lilypond_header {
821 | score_body output_def {
822 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
824 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
829 $$->add_output_def ($2);
834 $$->error_found_ = true;
846 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
848 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
850 $$ = get_paper (PARSER);
857 output_def_body '}' {
860 PARSER->lexer_->remove_scope ();
861 PARSER->lexer_->pop_state ();
867 $$ = get_paper (PARSER);
868 $$->input_origin_ = @$;
869 PARSER->lexer_->add_scope ($$->scope_);
872 Output_def *p = get_midi (PARSER);
874 PARSER->lexer_->add_scope (p->scope_);
877 Output_def *p = get_layout (PARSER);
879 PARSER->lexer_->add_scope (p->scope_);
884 output_def_head_with_mode_switch:
886 PARSER->lexer_->push_initial_state ();
892 output_def_head_with_mode_switch '{' {
894 $$->input_origin_.set_spot (@$);
896 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
899 Output_def *o = unsmob_output_def ($3);
900 o->input_origin_.set_spot (@$);
903 PARSER->lexer_->remove_scope ();
904 PARSER->lexer_->add_scope (o->scope_);
906 | output_def_body assignment {
909 | output_def_body context_def_spec_block {
910 assign_context_def ($$, $2);
912 | output_def_body error {
918 TEMPO steno_duration '=' bare_unsigned {
919 $$ = MAKE_SYNTAX ("tempo", @$, SCM_BOOL_F, $2, scm_int2num ($4));
921 | TEMPO string steno_duration '=' bare_unsigned {
922 $$ = MAKE_SYNTAX ("tempo", @$, make_simple_markup($2), $3, scm_int2num ($5));
924 | TEMPO full_markup steno_duration '=' bare_unsigned {
925 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, scm_int2num ($5));
928 $$ = MAKE_SYNTAX ("tempoText", @$, make_simple_markup($2) );
930 | TEMPO full_markup {
931 $$ = MAKE_SYNTAX ("tempoText", @$, $2 );
936 The representation of a list is the
940 to have efficient append. */
944 $$ = scm_cons (SCM_EOL, SCM_EOL);
948 SCM c = scm_cons ($2, SCM_EOL);
950 if (scm_is_pair (scm_cdr (s)))
951 scm_set_cdr_x (scm_cdr (s), c); /* append */
953 scm_set_car_x (s, c); /* set first cons */
954 scm_set_cdr_x (s, c); /* remember last cell */
956 | music_list embedded_scm {
960 Music *m = MY_MAKE_MUSIC("Music", @$);
962 m->set_property ("error-found", SCM_BOOL_T);
964 SCM c = scm_cons (m->self_scm (), SCM_EOL);
965 m->unprotect (); /* UGH */
967 if (scm_is_pair (scm_cdr (s)))
968 scm_set_cdr_x (scm_cdr (s), c); /* append */
970 scm_set_car_x (s, c); /* set first cons */
971 scm_set_cdr_x (s, c); /* remember last cell */
984 | ALTERNATIVE '{' music_list '}' {
991 REPEAT simple_string unsigned_number music alternative_music
993 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $5);
998 SEQUENTIAL '{' music_list '}' {
999 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($3));
1001 | '{' music_list '}' {
1002 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($2));
1007 SIMULTANEOUS '{' music_list '}'{
1008 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($3));
1010 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1011 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($2));
1018 | music_property_def
1022 optional_context_mod:
1023 /**/ { $$ = SCM_EOL; }
1024 | WITH { PARSER->lexer_->push_initial_state (); }
1025 '{' context_mod_list '}'
1027 PARSER->lexer_->pop_state ();
1033 /* */ { $$ = SCM_EOL; }
1034 | context_mod_list context_mod {
1035 $$ = scm_cons ($2, $1);
1040 prefix_composite_music { $$ = $1; }
1041 | grouped_music_list { $$ = $1; }
1045 simultaneous_music { $$ = $1; }
1046 | sequential_music { $$ = $1; }
1049 function_scm_argument:
1054 /* An argument list. If a function \foo expects scm scm music, then the lexer expands \foo into the token sequence:
1055 MUSIC_FUNCTION EXPECT_MUSIC EXPECT_SCM EXPECT_SCM
1056 and this rule returns the reversed list of arguments. */
1058 function_arglist_music_last:
1059 EXPECT_MUSIC function_arglist music {
1060 $$ = scm_cons ($3, $2);
1064 function_arglist_nonmusic_last:
1065 EXPECT_MARKUP function_arglist full_markup {
1066 $$ = scm_cons ($3, $2);
1068 | EXPECT_MARKUP function_arglist simple_string {
1069 $$ = scm_cons ($3, $2);
1071 | EXPECT_SCM function_arglist function_scm_argument {
1072 $$ = scm_cons ($3, $2);
1076 function_arglist_nonmusic: EXPECT_NO_MORE_ARGS {
1079 | EXPECT_MARKUP function_arglist_nonmusic full_markup {
1080 $$ = scm_cons ($3, $2);
1082 | EXPECT_MARKUP function_arglist_nonmusic simple_string {
1083 $$ = scm_cons ($3, $2);
1085 | EXPECT_SCM function_arglist_nonmusic function_scm_argument {
1086 $$ = scm_cons ($3, $2);
1090 function_arglist: EXPECT_NO_MORE_ARGS {
1091 /* This is for 0-ary functions, so they don't need to
1092 read a lookahead token */
1095 | function_arglist_music_last
1096 | function_arglist_nonmusic_last
1099 generic_prefix_music_scm:
1100 MUSIC_FUNCTION function_arglist {
1101 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1107 /**/ { $$ = SCM_EOL; }
1108 | '=' simple_string {
1114 prefix_composite_music:
1115 generic_prefix_music_scm {
1116 $$ = run_music_function (PARSER, $1);
1118 | CONTEXT simple_string optional_id optional_context_mod music {
1119 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_F);
1121 | NEWCONTEXT simple_string optional_id optional_context_mod music {
1122 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_T);
1125 | TIMES fraction music {
1126 $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3);
1128 | repeated_music { $$ = $1; }
1129 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords music {
1130 Pitch from = *unsmob_pitch ($2);
1131 Pitch to = *unsmob_pitch ($3);
1132 SCM pitch = pitch_interval (from, to).smobbed_copy ();
1133 $$ = MAKE_SYNTAX ("transpose-music", @$, pitch, $4);
1135 | mode_changing_head grouped_music_list {
1136 if ($1 == ly_symbol2scm ("chords"))
1138 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1144 PARSER->lexer_->pop_state ();
1146 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1147 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, $3, $2, SCM_BOOL_T);
1148 if ($1 == ly_symbol2scm ("ChordNames"))
1150 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1152 PARSER->lexer_->pop_state ();
1154 | relative_music { $$ = $1; }
1155 | re_rhythmed_music { $$ = $1; }
1160 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1161 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1163 $$ = ly_symbol2scm ("notes");
1167 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1168 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1170 $$ = ly_symbol2scm ("drums");
1173 PARSER->lexer_->push_figuredbass_state ();
1175 $$ = ly_symbol2scm ("figures");
1178 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1179 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1180 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1181 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1182 $$ = ly_symbol2scm ("chords");
1186 { PARSER->lexer_->push_lyric_state ();
1187 $$ = ly_symbol2scm ("lyrics");
1191 mode_changing_head_with_context:
1193 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1194 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1196 $$ = ly_symbol2scm ("DrumStaff");
1199 PARSER->lexer_->push_figuredbass_state ();
1201 $$ = ly_symbol2scm ("FiguredBass");
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 ("ChordNames");
1211 { PARSER->lexer_->push_lyric_state ();
1212 $$ = ly_symbol2scm ("Lyrics");
1218 RELATIVE absolute_pitch music {
1219 Pitch start = *unsmob_pitch ($2);
1220 $$ = make_music_relative (start, $3, @$);
1222 | RELATIVE composite_music {
1223 Pitch middle_c (0, 0, 0);
1224 $$ = make_music_relative (middle_c, $2, @$);
1229 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1231 grouped_music_list {
1232 /* Can also use music at the expensive of two S/Rs similar to
1233 \repeat \alternative */
1234 PARSER->lexer_->pop_state ();
1236 $$ = scm_cons ($3, SCM_EOL);
1238 | new_lyrics ADDLYRICS {
1239 PARSER->lexer_->push_lyric_state ();
1240 } grouped_music_list {
1241 PARSER->lexer_->pop_state ();
1242 $$ = scm_cons ($4, $1);
1247 grouped_music_list new_lyrics {
1248 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1250 | LYRICSTO simple_string {
1251 PARSER->lexer_->push_lyric_state ();
1253 PARSER->lexer_->pop_state ();
1254 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1259 CHANGE STRING '=' STRING {
1260 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1265 property_path_revved:
1267 $$ = scm_cons ($1, SCM_EOL);
1269 | property_path_revved embedded_scm {
1270 $$ = scm_cons ($2, $1);
1275 property_path_revved {
1276 $$ = scm_reverse_x ($1, SCM_EOL);
1282 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1283 scm_string_to_symbol ($1), $3);
1285 | UNSET simple_string {
1286 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1287 scm_string_to_symbol ($2));
1289 | OVERRIDE simple_string property_path '=' scalar {
1290 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1291 scm_string_to_symbol ($2), $5),
1294 | REVERT simple_string embedded_scm {
1295 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1296 scm_string_to_symbol ($2), $3);
1301 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1302 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1304 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1305 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1306 | DENIES { $$ = ly_symbol2scm ("denies"); }
1308 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1309 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1310 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1311 | NAME { $$ = ly_symbol2scm ("context-name"); }
1315 property_operation { $$ = $1; }
1316 | context_def_mod STRING {
1317 $$ = scm_list_2 ($1, $2);
1323 if (!is_regular_identifier ($1))
1325 @$.error (_("Grob name should be alphanumeric"));
1328 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1329 scm_string_to_symbol ($1));
1331 | simple_string '.' simple_string {
1332 $$ = scm_list_2 (scm_string_to_symbol ($1),
1333 scm_string_to_symbol ($3));
1337 simple_music_property_def:
1338 OVERRIDE context_prop_spec property_path '=' scalar {
1339 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1340 ly_symbol2scm ("OverrideProperty"),
1345 | REVERT context_prop_spec embedded_scm {
1346 $$ = scm_list_4 (scm_car ($2),
1347 ly_symbol2scm ("RevertProperty"),
1351 | SET context_prop_spec '=' scalar {
1352 $$ = scm_list_4 (scm_car ($2),
1353 ly_symbol2scm ("PropertySet"),
1357 | UNSET context_prop_spec {
1358 $$ = scm_list_3 (scm_car ($2),
1359 ly_symbol2scm ("PropertyUnset"),
1365 simple_music_property_def {
1366 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1368 | ONCE simple_music_property_def {
1369 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1377 | STRING_IDENTIFIER {
1380 | string '+' string {
1381 $$ = scm_string_append (scm_list_2 ($1, $3));
1385 simple_string: STRING {
1391 | STRING_IDENTIFIER {
1412 $$ = scm_from_int ($1);
1417 /* TODO: Create a special case that avoids the creation of
1418 EventChords around simple_elements that have no post_events?
1420 simple_chord_elements post_events {
1421 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1424 /* why is this giving wrong start location? -ns
1426 i.set_location (@1, @2);
1427 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1429 | CHORD_REPETITION optional_notemode_duration post_events {
1431 i.set_location (@1, @3);
1432 $$ = MAKE_SYNTAX ("repetition-chord", i,
1433 PARSER->lexer_->chord_repetition_.last_chord_,
1434 PARSER->lexer_->chord_repetition_.repetition_function_,
1437 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1439 i.set_location (@1, @3);
1440 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2, $3);
1443 /* note chord elements are memorized into
1444 PARSER->lexer_->chord_repetition_ so that the chord repetition
1445 mechanism copy them when a chord repetition symbol is found
1447 | note_chord_element {
1448 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
1454 chord_body optional_notemode_duration post_events
1456 Music *m = unsmob_music ($1);
1457 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1458 SCM es = m->get_property ("elements");
1459 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1461 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1462 unsmob_music (scm_car (s))->set_property ("duration", dur);
1463 es = ly_append2 (es, postevs);
1465 m-> set_property ("elements", es);
1467 $$ = m->self_scm ();
1472 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1474 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1478 chord_body_elements:
1479 /* empty */ { $$ = SCM_EOL; }
1480 | chord_body_elements chord_body_element {
1481 $$ = scm_cons ($2, $1);
1486 pitch exclamations questions octave_check post_events
1493 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1494 n->set_property ("pitch", $1);
1496 n->set_property ("cautionary", SCM_BOOL_T);
1497 if (ex % 2 || q % 2)
1498 n->set_property ("force-accidental", SCM_BOOL_T);
1500 if (scm_is_pair (post)) {
1501 SCM arts = scm_reverse_x (post, SCM_EOL);
1502 n->set_property ("articulations", arts);
1504 if (scm_is_number (check))
1506 int q = scm_to_int (check);
1507 n->set_property ("absolute-octave", scm_from_int (q-1));
1510 $$ = n->unprotect ();
1512 | DRUM_PITCH post_events {
1513 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1514 n->set_property ("duration", $2);
1515 n->set_property ("drum-type", $1);
1517 if (scm_is_pair ($2)) {
1518 SCM arts = scm_reverse_x ($2, SCM_EOL);
1519 n->set_property ("articulations", arts);
1521 $$ = n->unprotect ();
1523 | music_function_chord_body {
1524 $$ = run_music_function (PARSER, $1);
1528 music_function_identifier_musicless_prefix: MUSIC_FUNCTION {
1529 SCM sig = scm_object_property (yylval.scm, ly_symbol2scm ("music-function-signature"));
1530 if (scm_is_pair (sig) && to_boolean (scm_memq (ly_music_p_proc, scm_cdr (scm_reverse (sig)))))
1532 PARSER->parser_error (@$, "Music function applied to event may not have a Music argument, except as the last argument.");
1537 music_function_chord_body:
1538 /* We could allow chord functions to have multiple music arguments,
1539 but it's more consistent with music_function_event if we
1540 prohibit it here too */
1541 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic chord_body_element {
1542 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1544 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1545 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1549 music_function_event:
1550 /* Post-events can only have the last argument as music, without this
1551 restriction we get a shift/reduce conflict from e.g.
1552 c8-\partcombine c8 -. */
1553 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic post_event {
1554 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1556 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1557 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1565 | SKIP duration_length {
1566 $$ = MAKE_SYNTAX ("skip-music", @$, $2);
1569 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1570 m->set_property ("span-direction", scm_from_int (START));
1571 $$ = m->unprotect();
1574 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1575 m->set_property ("span-direction", scm_from_int (STOP));
1576 $$ = m->unprotect ();
1579 $$ = MAKE_SYNTAX ("voice-separator", @$, SCM_UNDEFINED);
1582 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1584 Music *m = unsmob_music (pipe);
1589 $$ = m->unprotect ();
1592 $$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
1595 | PARTIAL duration_length {
1596 Moment m = - unsmob_duration ($2)->get_length ();
1597 $$ = MAKE_SYNTAX ("property-operation", @$, SCM_BOOL_F, ly_symbol2scm ("Timing"), ly_symbol2scm ("PropertySet"), ly_symbol2scm ("measurePosition"), m.smobbed_copy ());
1598 $$ = MAKE_SYNTAX ("context-specification", @$, ly_symbol2scm ("Score"), SCM_BOOL_F, $$, SCM_EOL, SCM_BOOL_F);
1602 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1604 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1607 SCM proc = ly_lily_module_constant ("make-mark-set");
1609 $$ = scm_call_1 (proc, $2);
1615 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
1618 Music *m = MY_MAKE_MUSIC ("MarkEvent", @$);
1619 $$ = m->unprotect ();
1625 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1626 $$ = key->unprotect ();
1628 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1630 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1631 if (scm_ilength ($3) > 0)
1633 key->set_property ("pitch-alist", $3);
1634 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1635 key->transpose (* unsmob_pitch ($2));
1637 PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1640 $$ = key->unprotect ();
1649 | post_events post_event {
1650 unsmob_music ($2)->set_spot (@2);
1651 $$ = scm_cons ($2, $$);
1656 direction_less_event {
1659 | '-' music_function_event {
1660 $$ = run_music_function (PARSER, $2);
1663 if (!PARSER->lexer_->is_lyric_state ())
1664 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1665 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
1668 if (!PARSER->lexer_->is_lyric_state ())
1669 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1670 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
1672 | script_dir direction_reqd_event {
1675 Music *m = unsmob_music ($2);
1676 m->set_property ("direction", scm_from_int ($1));
1680 | script_dir direction_less_event {
1683 Music *m = unsmob_music ($2);
1684 m->set_property ("direction", scm_from_int ($1));
1688 | string_number_event
1691 string_number_event:
1693 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
1694 s->set_property ("string-number", scm_from_int ($1));
1695 $$ = s->unprotect ();
1699 direction_less_char:
1701 $$ = ly_symbol2scm ("bracketOpenSymbol");
1704 $$ = ly_symbol2scm ("bracketCloseSymbol");
1707 $$ = ly_symbol2scm ("tildeSymbol");
1710 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1713 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1716 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1719 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1722 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1725 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1728 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1732 direction_less_event:
1733 direction_less_char {
1734 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
1736 if (unsmob_music (predefd))
1738 m = unsmob_music (predefd)->clone ();
1743 m = MY_MAKE_MUSIC ("Music", @$);
1745 $$ = m->unprotect ();
1747 | EVENT_IDENTIFIER {
1751 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
1752 a->set_property ("tremolo-type", scm_from_int ($1));
1753 $$ = a->unprotect ();
1757 direction_reqd_event:
1761 | script_abbreviation {
1762 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1763 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
1764 if (scm_is_string (s))
1765 a->set_property ("articulation-type", s);
1766 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
1767 $$ = a->unprotect ();
1772 /**/ { $$ = SCM_EOL; }
1773 | '=' { $$ = scm_from_int (0); }
1774 | '=' sub_quotes { $$ = scm_from_int (-$2); }
1775 | '=' sup_quotes { $$ = scm_from_int ($2); }
1800 | NOTENAME_PITCH sup_quotes {
1801 Pitch p = *unsmob_pitch ($1);
1802 p = p.transposed (Pitch ($2,0,0));
1803 $$ = p.smobbed_copy ();
1805 | NOTENAME_PITCH sub_quotes {
1806 Pitch p =* unsmob_pitch ($1);
1807 p = p.transposed (Pitch (-$2,0,0));
1808 $$ = p.smobbed_copy ();
1820 | TONICNAME_PITCH sup_quotes {
1821 Pitch p = *unsmob_pitch ($1);
1822 p = p.transposed (Pitch ($2,0,0));
1823 $$ = p.smobbed_copy ();
1825 | TONICNAME_PITCH sub_quotes {
1826 Pitch p = *unsmob_pitch ($1);
1828 p = p.transposed (Pitch (-$2,0,0));
1829 $$ = p.smobbed_copy ();
1839 pitch_also_in_chords:
1846 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1847 t->set_property ("text", $1);
1848 $$ = t->unprotect ();
1851 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1852 t->set_property ("text",
1853 make_simple_markup ($1));
1854 $$ = t->unprotect ();
1857 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
1858 t->set_property ("digit", scm_from_int ($1));
1859 $$ = t->unprotect ();
1863 script_abbreviation:
1865 $$ = scm_from_locale_string ("Hat");
1868 $$ = scm_from_locale_string ("Plus");
1871 $$ = scm_from_locale_string ("Dash");
1874 $$ = scm_from_locale_string ("Bar");
1877 $$ = scm_from_locale_string ("Larger");
1880 $$ = scm_from_locale_string ("Dot");
1883 $$ = scm_from_locale_string ("Underscore");
1890 | '-' { $$ = CENTER; }
1901 multiplied_duration {
1906 optional_notemode_duration:
1908 Duration dd = PARSER->default_duration_;
1909 $$ = dd.smobbed_copy ();
1911 | multiplied_duration {
1913 PARSER->default_duration_ = *unsmob_duration ($$);
1918 bare_unsigned dots {
1920 if (!is_duration ($1))
1921 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
1925 $$ = Duration (len, $2).smobbed_copy ();
1927 | DURATION_IDENTIFIER dots {
1928 Duration *d = unsmob_duration ($1);
1929 Duration k (d->duration_log (), d->dot_count () + $2);
1935 multiplied_duration:
1939 | multiplied_duration '*' bare_unsigned {
1940 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1942 | multiplied_duration '*' FRACTION {
1943 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1945 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1950 FRACTION { $$ = $1; }
1951 | UNSIGNED '/' UNSIGNED {
1952 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
1969 | ':' bare_unsigned {
1970 if (!is_duration ($2))
1971 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
1978 $$ = scm_from_int ($1);
1981 $$ = scm_from_int ($1);
1983 | STRING { $$ = $1; }
1984 | full_markup { $$ = $1; }
1987 figured_bass_alteration:
1988 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
1989 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
1990 | '!' { $$ = scm_from_int (0); }
1995 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
1996 $$ = bfr->unprotect ();
1999 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2000 $$ = bfr->self_scm ();
2002 if (scm_is_number ($1))
2003 bfr->set_property ("figure", $1);
2004 else if (Text_interface::is_markup ($1))
2005 bfr->set_property ("text", $1);
2011 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2013 | bass_figure figured_bass_alteration {
2014 Music *m = unsmob_music ($1);
2015 if (scm_to_double ($2)) {
2016 SCM salter = m->get_property ("alteration");
2017 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2018 m->set_property ("alteration",
2019 scm_sum (alter, $2));
2021 m->set_property ("alteration", scm_from_int (0));
2024 | bass_figure figured_bass_modification {
2025 Music *m = unsmob_music ($1);
2026 if ($2 == ly_symbol2scm ("plus"))
2028 m->set_property ("augmented", SCM_BOOL_T);
2030 else if ($2 == ly_symbol2scm ("slash"))
2032 m->set_property ("diminished", SCM_BOOL_T);
2034 else if ($2 == ly_symbol2scm ("exclamation"))
2036 m->set_property ("no-continuation", SCM_BOOL_T);
2038 else if ($2 == ly_symbol2scm ("backslash"))
2040 m->set_property ("augmented-slash", SCM_BOOL_T);
2046 figured_bass_modification:
2048 $$ = ly_symbol2scm ("plus");
2051 $$ = ly_symbol2scm ("exclamation");
2054 $$ = ly_symbol2scm ("slash");
2057 $$ = ly_symbol2scm ("backslash");
2067 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2075 | figure_list br_bass_figure {
2076 $$ = scm_cons ($2, $1);
2081 FIGURE_OPEN figure_list FIGURE_CLOSE {
2082 $$ = scm_reverse_x ($2, SCM_EOL);
2093 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2094 if (!PARSER->lexer_->is_note_state ())
2095 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2099 n = MY_MAKE_MUSIC ("RestEvent", @$);
2101 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2103 n->set_property ("pitch", $1);
2104 n->set_property ("duration", $5);
2106 if (scm_is_number ($4))
2108 int q = scm_to_int ($4);
2109 n->set_property ("absolute-octave", scm_from_int (q-1));
2113 n->set_property ("cautionary", SCM_BOOL_T);
2114 if ($2 % 2 || $3 % 2)
2115 n->set_property ("force-accidental", SCM_BOOL_T);
2117 $$ = n->unprotect ();
2119 | DRUM_PITCH optional_notemode_duration {
2120 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2121 n->set_property ("duration", $2);
2122 n->set_property ("drum-type", $1);
2124 $$ = n->unprotect ();
2126 | RESTNAME optional_notemode_duration {
2128 if (ly_scm2string ($1) == "s") {
2130 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2133 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2136 ev->set_property ("duration", $2);
2137 $$ = ev->unprotect ();
2139 | lyric_element optional_notemode_duration {
2140 if (!PARSER->lexer_->is_lyric_state ())
2141 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2143 Music *levent = MY_MAKE_MUSIC ("LyricEvent", @$);
2144 levent->set_property ("text", $1);
2145 levent->set_property ("duration",$2);
2146 $$= levent->unprotect ();
2150 simple_chord_elements:
2152 $$ = scm_list_1 ($1);
2155 if (!PARSER->lexer_->is_chord_state ())
2156 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2159 | figure_spec optional_notemode_duration {
2160 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2162 unsmob_music (scm_car (s))->set_property ("duration", $2);
2178 steno_tonic_pitch optional_notemode_duration {
2179 $$ = make_chord_elements ($1, $2, SCM_EOL);
2181 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2182 SCM its = scm_reverse_x ($4, SCM_EOL);
2183 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2191 | chord_items chord_item {
2192 $$ = scm_cons ($2, $$);
2198 $$ = ly_symbol2scm ("chord-colon");
2201 $$ = ly_symbol2scm ("chord-caret");
2203 | CHORD_SLASH steno_tonic_pitch {
2204 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2206 | CHORD_BASS steno_tonic_pitch {
2207 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2216 $$ = scm_reverse_x ($1, SCM_EOL);
2224 step_number { $$ = scm_cons ($1, SCM_EOL); }
2225 | step_numbers '.' step_number {
2226 $$ = scm_cons ($3, $$);
2232 $$ = make_chord_step ($1, 0);
2234 | bare_unsigned '+' {
2235 $$ = make_chord_step ($1, SHARP_ALTERATION);
2237 | bare_unsigned CHORD_MINUS {
2238 $$ = make_chord_step ($1, FLAT_ALTERATION);
2245 TODO: should deprecate in favor of Scheme?
2249 number_expression '+' number_term {
2250 $$ = scm_sum ($1, $3);
2252 | number_expression '-' number_term {
2253 $$ = scm_difference ($1, $3);
2262 | number_factor '*' number_factor {
2263 $$ = scm_product ($1, $3);
2265 | number_factor '/' number_factor {
2266 $$ = scm_divide ($1, $3);
2271 '-' number_factor { /* %prec UNARY_MINUS */
2272 $$ = scm_difference ($2, SCM_UNDEFINED);
2280 $$ = scm_from_int ($1);
2285 | NUMBER_IDENTIFIER {
2288 | REAL NUMBER_IDENTIFIER {
2289 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2291 | UNSIGNED NUMBER_IDENTIFIER {
2292 $$ = scm_from_double ($1 *scm_to_double ($2));
2307 bare_unsigned { $$ = scm_from_int ($1); }
2308 | NUMBER_IDENTIFIER {
2316 | exclamations '!' { $$ ++; }
2321 | questions '?' { $$ ++; }
2325 This should be done more dynamically if possible.
2329 LYRIC_MARKUP_IDENTIFIER {
2333 { PARSER->lexer_->push_markup_state (); }
2336 PARSER->lexer_->pop_state ();
2342 { PARSER->lexer_->push_markup_state (); }
2345 PARSER->lexer_->pop_state ();
2354 { PARSER->lexer_->push_markup_state (); }
2357 PARSER->lexer_->pop_state ();
2363 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2365 | markup_head_1_list simple_markup {
2366 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2374 markup_composed_list {
2377 | markup_braced_list {
2380 | markup_command_list {
2381 $$ = scm_list_1 ($1);
2385 markup_composed_list:
2386 markup_head_1_list markup_braced_list {
2387 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2393 '{' markup_braced_list_body '}' {
2394 $$ = scm_reverse_x ($2, SCM_EOL);
2398 markup_braced_list_body:
2399 /* empty */ { $$ = SCM_EOL; }
2400 | markup_braced_list_body markup {
2401 $$ = scm_cons ($2, $1);
2403 | markup_braced_list_body markup_list {
2404 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2408 markup_command_list:
2409 MARKUP_LIST_HEAD_EMPTY {
2410 $$ = scm_list_1 ($1);
2412 | MARKUP_LIST_HEAD_LIST0 markup_list {
2413 $$ = scm_list_2 ($1, $2);
2415 | MARKUP_LIST_HEAD_SCM0 embedded_scm {
2416 $$ = scm_list_2 ($1, $2);
2418 | MARKUP_LIST_HEAD_SCM0_LIST1 embedded_scm markup_list {
2419 $$ = scm_list_3 ($1, $2, $3);
2421 | MARKUP_LIST_HEAD_SCM0_SCM1_LIST2 embedded_scm embedded_scm markup_list {
2422 $$ = scm_list_4 ($1, $2, $3, $4);
2427 MARKUP_HEAD_MARKUP0 {
2428 $$ = scm_list_1 ($1);
2430 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2431 $$ = scm_list_2 ($1, $2);
2433 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2434 $$ = scm_list_3 ($1, $2, $3);
2439 markup_head_1_item {
2440 $$ = scm_list_1 ($1);
2442 | markup_head_1_list markup_head_1_item {
2443 $$ = scm_cons ($2, $1);
2449 $$ = make_simple_markup ($1);
2451 | MARKUP_IDENTIFIER {
2454 | LYRIC_MARKUP_IDENTIFIER {
2457 | STRING_IDENTIFIER {
2461 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2462 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2463 } '{' score_body '}' {
2465 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2467 PARSER->lexer_->pop_state ();
2469 | MARKUP_HEAD_SCM0 embedded_scm {
2470 $$ = scm_list_2 ($1, $2);
2472 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2473 $$ = scm_list_4 ($1, $2, $3, $4);
2475 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2476 $$ = scm_list_3 ($1, $2, $3);
2478 | MARKUP_HEAD_SCM0_MARKUP1_MARKUP2 embedded_scm markup markup {
2479 $$ = scm_list_4 ($1, $2, $3, $4);
2481 | MARKUP_HEAD_SCM0_SCM1_MARKUP2_MARKUP3 embedded_scm embedded_scm markup markup {
2482 $$ = scm_list_5 ($1, $2, $3, $4, $5);
2484 | MARKUP_HEAD_EMPTY {
2485 $$ = scm_list_1 ($1);
2487 | MARKUP_HEAD_LIST0 markup_list {
2488 $$ = scm_list_2 ($1,$2);
2490 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2491 $$ = scm_list_3 ($1, $2, $3);
2496 markup_head_1_list simple_markup {
2497 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2498 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2508 Lily_parser::set_yydebug (bool x)
2514 Lily_parser::do_yyparse ()
2516 yyparse ((void*)this);
2525 It is a little strange to have this function in this file, but
2526 otherwise, we have to import music classes into the lexer.
2530 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2532 if (scm_is_string (sid)) {
2534 return STRING_IDENTIFIER;
2535 } else if (unsmob_book (sid)) {
2536 Book *book = unsmob_book (sid)->clone ();
2537 *destination = book->self_scm ();
2540 return BOOK_IDENTIFIER;
2541 } else if (scm_is_number (sid)) {
2543 return NUMBER_IDENTIFIER;
2544 } else if (unsmob_context_def (sid)) {
2545 Context_def *def= unsmob_context_def (sid)->clone ();
2547 *destination = def->self_scm ();
2550 return CONTEXT_DEF_IDENTIFIER;
2551 } else if (unsmob_score (sid)) {
2552 Score *score = new Score (*unsmob_score (sid));
2553 *destination = score->self_scm ();
2555 score->unprotect ();
2556 return SCORE_IDENTIFIER;
2557 } else if (Music *mus = unsmob_music (sid)) {
2558 mus = mus->clone ();
2559 *destination = mus->self_scm ();
2560 unsmob_music (*destination)->
2561 set_property ("origin", make_input (last_input_));
2563 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2567 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2568 } else if (unsmob_duration (sid)) {
2569 *destination = unsmob_duration (sid)->smobbed_copy ();
2570 return DURATION_IDENTIFIER;
2571 } else if (unsmob_output_def (sid)) {
2572 Output_def *p = unsmob_output_def (sid);
2575 *destination = p->self_scm ();
2577 return OUTPUT_DEF_IDENTIFIER;
2578 } else if (Text_interface::is_markup (sid)) {
2580 if (is_lyric_state ())
2581 return LYRIC_MARKUP_IDENTIFIER;
2582 return MARKUP_IDENTIFIER;
2589 get_next_unique_context_id ()
2591 return scm_from_locale_string ("$uniqueContextId");
2596 get_next_unique_lyrics_context_id ()
2598 static int new_context_count;
2600 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2601 return scm_from_locale_string (s);
2606 run_music_function (Lily_parser *parser, SCM expr)
2608 SCM func = scm_car (expr);
2609 Input *loc = unsmob_input (scm_cadr (expr));
2610 SCM args = scm_cddr (expr);
2611 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2613 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2615 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2617 parser->error_level_ = 1;
2618 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (*loc)));
2621 SCM syntax_args = scm_list_4 (parser->self_scm (), make_input (*loc), func, args);
2622 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
2626 is_regular_identifier (SCM id)
2628 string str = ly_scm2string (id);
2629 char const *s = str.c_str ();
2638 v = v && isalnum (*s);
2645 make_music_with_input (SCM name, Input where)
2647 Music *m = make_music_by_name (name);
2648 m->set_spot (where);
2653 get_first_context_id (SCM type, Music *m)
2655 SCM id = m->get_property ("context-id");
2656 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2657 && scm_is_string (m->get_property ("context-id"))
2658 && scm_c_string_length (id) > 0)
2666 make_simple_markup (SCM a)
2674 return t && t == 1 << intlog2 (t);
2678 set_music_properties (Music *p, SCM a)
2680 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2681 p->set_property (scm_caar (k), scm_cdar (k));
2686 make_chord_step (int step, Rational alter)
2689 alter += FLAT_ALTERATION;
2693 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2694 return m.smobbed_copy ();
2699 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
2701 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
2702 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
2706 /* Todo: actually also use apply iso. call too ... */
2708 ly_input_procedure_p (SCM x)
2710 return ly_is_procedure (x)
2711 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2715 make_music_relative (Pitch start, SCM music, Input loc)
2717 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic", loc);
2718 relative->set_property ("element", music);
2720 Music *m = unsmob_music (music);
2721 Pitch last = m->to_relative_octave (start);
2722 if (lily_1_8_relative)
2723 m->set_property ("last-pitch", last.smobbed_copy ());
2724 return relative->unprotect ();
2728 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2730 Lily_parser *pars = (Lily_parser*) v;
2731 Lily_lexer *lex = pars->lexer_;
2733 lex->lexval = (void*) s;
2735 lex->prepare_for_next_token ();
2736 return lex->yylex ();