2 parser.yy -- Bison/C++ parser for LilyPond
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
13 #define YYERROR_VERBOSE 1
14 #define YYPARSE_PARAM my_lily_parser
15 #define YYLEX_PARAM my_lily_parser
16 #define PARSER ((Lily_parser *) my_lily_parser)
18 #define yyerror PARSER->parser_error
20 /* We use custom location type: Input objects */
22 #define YYLLOC_DEFAULT(Current,Rhs,N) \
23 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
28 /* We use SCMs to do strings, because it saves us the trouble of
29 deleting them. Let's hope that a stack overflow doesnt trigger a move
30 of the parse stack onto the heap. */
38 /* One shift/reduce problem
41 \repeat .. \alternative
43 \repeat { \repeat .. \alternative }
47 \repeat { \repeat } \alternative
56 %{ // -*-Fundamental-*-
61 * The rules for who is protecting what are very shady. Uniformise
64 * There are too many lexical modes?
75 #include "context-def.hh"
76 #include "dimensions.hh"
77 #include "file-path.hh"
79 #include "international.hh"
80 #include "lily-guile.hh"
81 #include "lily-lexer.hh"
82 #include "lily-parser.hh"
87 #include "output-def.hh"
88 #include "paper-book.hh"
89 #include "program-option.hh"
90 #include "scm-hash.hh"
92 #include "text-interface.hh"
100 Output_def *outputdef;
110 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
113 - Don't use lily module, create a new module instead.
114 - delay application of the function
116 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
117 scm_apply_0 (proc, args)
118 /* Syntactic Sugar. */
119 #define MAKE_SYNTAX(name, location, ...) \
120 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location), __VA_ARGS__, SCM_UNDEFINED));
122 SCM get_next_unique_context_id ();
123 SCM get_next_unique_lyrics_context_id ();
130 #define _(x) gettext (x)
134 static Music *make_music_with_input (SCM name, Input where);
135 SCM make_music_relative (Pitch start, SCM music, Input loc);
136 SCM run_music_function (Lily_parser *, SCM expr);
137 SCM get_first_context_id (SCM type, Music *m);
138 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
139 SCM make_chord_step (int step, Rational alter);
140 SCM make_simple_markup (SCM a);
141 bool is_duration (int t);
142 bool is_regular_identifier (SCM id);
143 bool ly_input_procedure_p (SCM x);
144 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
145 void set_music_properties (Music *p, SCM a);
149 /* The third option is an alias that will be used to display the
150 syntax error. Bison CVS now correctly handles backslash escapes.
152 FIXME: Bison needs to translate some of these, eg, STRING.
156 /* Keyword tokens with plain escaped name. */
157 %token ACCEPTS "\\accepts"
158 %token ADDLYRICS "\\addlyrics"
159 %token ALIAS "\\alias"
160 %token ALTERNATIVE "\\alternative"
162 %token CHANGE "\\change"
163 %token CHORDMODE "\\chordmode"
164 %token CHORDS "\\chords"
165 %token CONSISTS "\\consists"
166 %token CONTEXT "\\context"
167 %token DEFAULT "\\default"
168 %token DEFAULTCHILD "\\defaultchild"
169 %token DENIES "\\denies"
170 %token DESCRIPTION "\\description"
171 %token DRUMMODE "\\drummode"
172 %token DRUMS "\\drums"
173 %token FIGUREMODE "\\figuremode"
174 %token FIGURES "\\figures"
175 %token GROBDESCRIPTIONS "\\grobdescriptions"
176 %token HEADER "\\header"
177 %token INVALID "\\invalid"
179 %token LAYOUT "\\layout"
180 %token LYRICMODE "\\lyricmode"
181 %token LYRICS "\\lyrics"
182 %token LYRICSTO "\\lyricsto"
184 %token MARKUP "\\markup"
187 %token NOTEMODE "\\notemode"
188 %token OBJECTID "\\objectid"
189 %token OCTAVE "\\octave"
191 %token OVERRIDE "\\override"
192 %token PAPER "\\paper"
193 %token PARTIAL "\\partial"
194 %token RELATIVE "\\relative"
195 %token REMOVE "\\remove"
196 %token REPEAT "\\repeat"
198 %token REVERT "\\revert"
199 %token SCORE "\\score"
200 %token SEQUENTIAL "\\sequential"
202 %token SIMULTANEOUS "\\simultaneous"
204 %token TEMPO "\\tempo"
205 %token TIMES "\\times"
206 %token TRANSPOSE "\\transpose"
208 %token UNSET "\\unset"
211 /* Keyword token exceptions. */
212 %token TIME_T "\\time"
213 %token NEWCONTEXT "\\new"
216 /* Other string tokens. */
218 %token CHORD_BASS "/+"
219 %token CHORD_CARET "^"
220 %token CHORD_COLON ":"
221 %token CHORD_MINUS "-"
222 %token CHORD_SLASH "/"
223 %token ANGLE_OPEN "<"
224 %token ANGLE_CLOSE ">"
225 %token DOUBLE_ANGLE_OPEN "<<"
226 %token DOUBLE_ANGLE_CLOSE ">>"
227 %token E_BACKSLASH "\\"
228 %token E_ANGLE_CLOSE "\\>"
229 %token E_CHAR "\\C[haracter]"
231 %token E_EXCLAMATION "\\!"
232 %token E_BRACKET_OPEN "\\["
234 %token E_BRACKET_CLOSE "\\]"
235 %token E_ANGLE_OPEN "\\<"
241 If we give names, Bison complains.
243 %token FIGURE_CLOSE /* "\\>" */
244 %token FIGURE_OPEN /* "\\<" */
245 %token FIGURE_SPACE "_"
248 %token CHORDMODIFIERS
250 %token MULTI_MEASURE_REST
254 %token <i> E_UNSIGNED
257 /* Artificial tokens, for more generic function syntax */
258 %token <i> EXPECT_MARKUP;
259 %token <i> EXPECT_MUSIC;
260 %token <i> EXPECT_SCM;
261 /* After the last argument. */
262 %token <i> EXPECT_NO_MORE_ARGS;
264 %token <scm> BOOK_IDENTIFIER
265 %token <scm> CHORDMODIFIER_PITCH
266 %token <scm> CHORD_MODIFIER
267 %token <scm> CONTEXT_DEF_IDENTIFIER
268 %token <scm> DRUM_PITCH
269 %token <scm> DURATION_IDENTIFIER
270 %token <scm> EVENT_IDENTIFIER
271 %token <scm> FRACTION
272 %token <scm> LYRICS_STRING
273 %token <scm> LYRIC_MARKUP_IDENTIFIER
274 %token <scm> MARKUP_HEAD_EMPTY
275 %token <scm> MARKUP_HEAD_LIST0
276 %token <scm> MARKUP_HEAD_MARKUP0
277 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
278 %token <scm> MARKUP_HEAD_SCM0
279 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
280 %token <scm> MARKUP_HEAD_SCM0_SCM1
281 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
282 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
283 %token <scm> MARKUP_IDENTIFIER
284 %token <scm> MUSIC_FUNCTION
285 %token <scm> MUSIC_IDENTIFIER
286 %token <scm> NOTENAME_PITCH
287 %token <scm> NUMBER_IDENTIFIER
288 %token <scm> OUTPUT_DEF_IDENTIFIER
290 %token <scm> RESTNAME
291 %token <scm> SCM_IDENTIFIER
292 %token <scm> SCM_TOKEN
293 %token <scm> SCORE_IDENTIFIER
295 %token <scm> STRING_IDENTIFIER
296 %token <scm> TONICNAME_PITCH
299 %type <book> book_block
300 %type <book> book_body
302 %type <i> bare_unsigned
303 %type <scm> figured_bass_alteration
305 %type <i> exclamations
306 %type <i> optional_rest
311 %type <i> tremolo_type
314 %type <scm> composite_music
315 %type <scm> grouped_music_list
317 %type <scm> prefix_composite_music
318 %type <scm> repeated_music
319 %type <scm> sequential_music
320 %type <scm> simple_music
321 %type <scm> simultaneous_music
322 %type <scm> chord_body
323 %type <scm> chord_body_element
324 %type <scm> command_element
325 %type <scm> command_event
326 %type <scm> context_change
327 %type <scm> direction_less_event
328 %type <scm> direction_reqd_event
329 %type <scm> event_chord
330 %type <scm> gen_text_def
331 %type <scm> music_property_def
332 %type <scm> note_chord_element
333 %type <scm> post_event
334 %type <scm> re_rhythmed_music
335 %type <scm> relative_music
336 %type <scm> simple_element
337 %type <scm> simple_music_property_def
338 %type <scm> string_number_event
339 %type <scm> tempo_event
341 %type <outputdef> output_def_body
342 %type <outputdef> output_def_head
343 %type <outputdef> output_def_head_with_mode_switch
344 %type <outputdef> output_def
345 %type <outputdef> paper_block
347 %type <scm> alternative_music
348 %type <scm> generic_prefix_music_scm
349 %type <scm> music_list
350 %type <scm> absolute_pitch
351 %type <scm> assignment_id
352 %type <scm> bare_number
353 %type <scm> unsigned_number
354 %type <scm> bass_figure
355 %type <scm> figured_bass_modification
356 %type <scm> br_bass_figure
357 %type <scm> bass_number
358 %type <scm> chord_body_elements
359 %type <scm> chord_item
360 %type <scm> chord_items
361 %type <scm> chord_separator
362 %type <scm> context_def_mod
363 %type <scm> context_def_spec_block
364 %type <scm> context_def_spec_body
365 %type <scm> context_mod
366 %type <scm> context_mod_list
367 %type <scm> context_prop_spec
368 %type <scm> direction_less_char
369 %type <scm> duration_length
370 %type <scm> embedded_scm
371 %type <scm> figure_list
372 %type <scm> figure_spec
374 %type <scm> full_markup
375 %type <scm> function_scm_argument
376 %type <scm> function_arglist
377 %type <scm> function_arglist_music_last
378 %type <scm> function_arglist_nonmusic_last
379 %type <scm> function_arglist_nonmusic
380 %type <scm> identifier_init
381 %type <scm> lilypond_header
382 %type <scm> lilypond_header_body
383 %type <scm> lyric_element
384 %type <scm> lyric_markup
386 %type <scm> markup_braced_list
387 %type <scm> markup_braced_list_body
388 %type <scm> markup_composed_list
389 %type <scm> markup_head_1_item
390 %type <scm> markup_head_1_list
391 %type <scm> markup_list
392 %type <scm> markup_top
393 %type <scm> mode_changing_head
394 %type <scm> mode_changing_head_with_context
395 %type <scm> multiplied_duration
396 %type <scm> music_function_identifier_musicless_prefix
397 %type <scm> music_function_event
398 %type <scm> music_function_chord_body
399 %type <scm> new_chord
400 %type <scm> new_lyrics
401 %type <scm> number_expression
402 %type <scm> number_factor
403 %type <scm> number_term
404 %type <scm> object_id_setting
405 %type <scm> octave_check
406 %type <scm> optional_context_mod
407 %type <scm> optional_id
408 %type <scm> optional_notemode_duration
410 %type <scm> pitch_also_in_chords
411 %type <scm> post_events
412 %type <scm> property_operation
413 %type <scm> property_path property_path_revved
415 %type <scm> script_abbreviation
416 %type <scm> simple_chord_elements
417 %type <scm> simple_markup
418 %type <scm> simple_string
419 %type <scm> steno_duration
420 %type <scm> steno_pitch
421 %type <scm> steno_tonic_pitch
422 %type <scm> step_number
423 %type <scm> step_numbers
426 %type <score> score_block
427 %type <score> score_body
432 /* We don't assign precedence to / and *, because we might need varied
433 prec levels in different prods */
439 lilypond: /* empty */
440 | lilypond toplevel_expression {
442 | lilypond assignment {
445 PARSER->error_level_ = 1;
448 PARSER->error_level_ = 1;
454 OBJECTID STRING { $$ = $2; }
459 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
463 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
464 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
470 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
471 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
475 Music *music = unsmob_music ($1);
476 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
477 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
480 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
481 scm_call_2 (proc, PARSER->self_scm (), $1);
485 Output_def * od = $1;
487 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
488 id = ly_symbol2scm ("$defaultpaper");
489 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
490 id = ly_symbol2scm ("$defaultmidi");
491 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
492 id = ly_symbol2scm ("$defaultlayout");
494 PARSER->lexer_->set_identifier (id, od->self_scm ());
505 lilypond_header_body:
507 $$ = get_header (PARSER);
508 PARSER->lexer_->add_scope ($$);
510 | lilypond_header_body assignment {
516 HEADER '{' lilypond_header_body '}' {
517 $$ = PARSER->lexer_->remove_scope ();
526 | LYRICS_STRING { $$ = $1; }
530 assignment_id '=' identifier_init {
531 PARSER->lexer_->set_identifier ($1, $3);
534 TODO: devise standard for protection in parser.
536 The parser stack lives on the C-stack, which means that
537 all objects can be unprotected as soon as they're here.
547 $$ = $1->self_scm ();
551 $$ = $1->self_scm ();
555 $$ = $1->self_scm ();
558 | context_def_spec_block {
562 /* Hack: Create event-chord around standalone events.
563 Prevents the identifier from being interpreted as a post-event. */
564 Music *mus = unsmob_music ($1);
565 bool is_event = mus &&
566 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
571 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
576 | number_expression {
589 $$ = scm_from_int ($1);
593 context_def_spec_block:
594 CONTEXT '{' context_def_spec_body '}'
600 context_def_spec_body:
602 $$ = Context_def::make_scm ();
603 unsmob_context_def ($$)->origin ()->set_spot (@$);
605 | CONTEXT_DEF_IDENTIFIER {
607 unsmob_context_def ($$)->origin ()->set_spot (@$);
609 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
610 Context_def*td = unsmob_context_def ($$);
612 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
613 SCM tag = scm_caar (p);
615 /* TODO: should make new tag "grob-definition" ? */
616 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
617 tag, scm_cons (scm_cdar (p), SCM_EOL)));
620 | context_def_spec_body context_mod {
621 unsmob_context_def ($$)->add_context_mod ($2);
628 BOOK '{' book_body '}' {
634 * Use 'handlers' like for toplevel-* stuff?
635 * grok \layout and \midi? */
639 $$->origin ()->set_spot (@$);
640 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
641 $$->paper_->unprotect ();
642 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
645 $$ = unsmob_book ($1);
647 $$->origin ()->set_spot (@$);
649 | book_body paper_block {
653 | book_body score_block {
654 SCM s = $2->self_scm ();
658 | book_body full_markup {
661 | book_body lilypond_header {
666 $$->scores_ = SCM_EOL;
668 | book_body object_id_setting {
669 $$->user_key_ = ly_scm2string ($2);
674 SCORE '{' score_body '}' {
682 SCM scorify = ly_lily_module_constant ("scorify-music");
683 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
685 // pass ownernship to C++ again.
686 $$ = unsmob_score (score);
688 $$->origin ()->set_spot (@$);
691 $$ = unsmob_score ($1);
693 $$->origin ()->set_spot (@$);
695 | score_body object_id_setting {
696 $$->user_key_ = ly_scm2string ($2);
698 | score_body lilypond_header {
701 | score_body output_def {
702 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
704 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
709 $$->add_output_def ($2);
714 $$->error_found_ = true;
726 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
728 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
730 $$ = get_paper (PARSER);
737 output_def_body '}' {
740 PARSER->lexer_->remove_scope ();
741 PARSER->lexer_->pop_state ();
747 $$ = get_paper (PARSER);
748 $$->input_origin_ = @$;
749 PARSER->lexer_->add_scope ($$->scope_);
752 Output_def *p = get_midi (PARSER);
754 PARSER->lexer_->add_scope (p->scope_);
757 Output_def *p = get_layout (PARSER);
759 PARSER->lexer_->add_scope (p->scope_);
764 output_def_head_with_mode_switch:
766 PARSER->lexer_->push_initial_state ();
772 output_def_head_with_mode_switch '{' {
774 $$->input_origin_.set_spot (@$);
776 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
779 Output_def *o = unsmob_output_def ($3);
780 o->input_origin_.set_spot (@$);
783 PARSER->lexer_->remove_scope ();
784 PARSER->lexer_->add_scope (o->scope_);
786 | output_def_body assignment {
789 | output_def_body context_def_spec_block {
790 assign_context_def ($$, $2);
792 | output_def_body error {
798 TEMPO steno_duration '=' bare_unsigned {
799 $$ = MAKE_SYNTAX ("tempo", @$, $2, scm_int2num ($4));
804 The representation of a list is the
808 to have efficient append. */
812 $$ = scm_cons (SCM_EOL, SCM_EOL);
816 SCM c = scm_cons ($2, SCM_EOL);
818 if (scm_is_pair (scm_cdr (s)))
819 scm_set_cdr_x (scm_cdr (s), c); /* append */
821 scm_set_car_x (s, c); /* set first cons */
822 scm_set_cdr_x (s, c); /* remember last cell */
824 | music_list embedded_scm {
828 Music *m = MY_MAKE_MUSIC("Music", @$);
830 m->set_property ("error-found", SCM_BOOL_T);
832 SCM c = scm_cons (m->self_scm (), SCM_EOL);
833 m->unprotect (); /* UGH */
835 if (scm_is_pair (scm_cdr (s)))
836 scm_set_cdr_x (scm_cdr (s), c); /* append */
838 scm_set_car_x (s, c); /* set first cons */
839 scm_set_cdr_x (s, c); /* remember last cell */
852 | ALTERNATIVE '{' music_list '}' {
859 REPEAT simple_string unsigned_number music alternative_music
861 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $5);
866 SEQUENTIAL '{' music_list '}' {
867 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($3));
869 | '{' music_list '}' {
870 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($2));
875 SIMULTANEOUS '{' music_list '}'{
876 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($3));
878 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
879 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($2));
890 optional_context_mod:
891 /**/ { $$ = SCM_EOL; }
892 | WITH { PARSER->lexer_->push_initial_state (); }
893 '{' context_mod_list '}'
895 PARSER->lexer_->pop_state ();
901 /* */ { $$ = SCM_EOL; }
902 | context_mod_list context_mod {
903 $$ = scm_cons ($2, $1);
908 prefix_composite_music { $$ = $1; }
909 | grouped_music_list { $$ = $1; }
913 simultaneous_music { $$ = $1; }
914 | sequential_music { $$ = $1; }
917 function_scm_argument:
922 /* An argument list. If a function \foo expects scm scm music, then the lexer expands \foo into the token sequence:
923 MUSIC_FUNCTION EXPECT_MUSIC EXPECT_SCM EXPECT_SCM
924 and this rule returns the reversed list of arguments. */
926 function_arglist_music_last:
927 EXPECT_MUSIC function_arglist music {
928 $$ = scm_cons ($3, $2);
932 function_arglist_nonmusic_last:
933 EXPECT_MARKUP function_arglist full_markup {
934 $$ = scm_cons ($3, $2);
936 | EXPECT_SCM function_arglist function_scm_argument {
937 $$ = scm_cons ($3, $2);
941 function_arglist_nonmusic: EXPECT_NO_MORE_ARGS {
944 | EXPECT_MARKUP function_arglist_nonmusic full_markup {
945 $$ = scm_cons ($3, $2);
947 | EXPECT_SCM function_arglist_nonmusic function_scm_argument {
948 $$ = scm_cons ($3, $2);
952 function_arglist: EXPECT_NO_MORE_ARGS {
953 /* This is for 0-ary functions, so they don't need to
954 read a lookahead token */
957 | function_arglist_music_last
958 | function_arglist_nonmusic_last
961 generic_prefix_music_scm:
962 MUSIC_FUNCTION function_arglist {
963 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
969 /**/ { $$ = SCM_EOL; }
970 | '=' simple_string {
976 prefix_composite_music:
977 generic_prefix_music_scm {
978 $$ = run_music_function (PARSER, $1);
980 | CONTEXT simple_string optional_id optional_context_mod music {
981 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_F);
983 | NEWCONTEXT simple_string optional_id optional_context_mod music {
984 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_T);
987 | TIMES fraction music {
988 $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3);
990 | repeated_music { $$ = $1; }
991 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords music {
992 Pitch from = *unsmob_pitch ($2);
993 Pitch to = *unsmob_pitch ($3);
994 SCM pitch = pitch_interval (from, to).smobbed_copy ();
995 $$ = MAKE_SYNTAX ("transpose-music", @$, pitch, $4);
997 | mode_changing_head grouped_music_list {
998 if ($1 == ly_symbol2scm ("chords"))
1000 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1006 PARSER->lexer_->pop_state ();
1008 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1009 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, $3, $2, SCM_BOOL_T);
1010 if ($1 == ly_symbol2scm ("ChordNames"))
1012 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1014 PARSER->lexer_->pop_state ();
1016 | relative_music { $$ = $1; }
1017 | re_rhythmed_music { $$ = $1; }
1022 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1023 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1025 $$ = ly_symbol2scm ("notes");
1029 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1030 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1032 $$ = ly_symbol2scm ("drums");
1035 PARSER->lexer_->push_figuredbass_state ();
1037 $$ = ly_symbol2scm ("figures");
1040 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1041 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1042 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1043 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1044 $$ = ly_symbol2scm ("chords");
1048 { PARSER->lexer_->push_lyric_state ();
1049 $$ = ly_symbol2scm ("lyrics");
1053 mode_changing_head_with_context:
1055 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1056 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1058 $$ = ly_symbol2scm ("DrumStaff");
1061 PARSER->lexer_->push_figuredbass_state ();
1063 $$ = ly_symbol2scm ("FiguredBass");
1066 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1067 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1068 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1069 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1070 $$ = ly_symbol2scm ("ChordNames");
1073 { PARSER->lexer_->push_lyric_state ();
1074 $$ = ly_symbol2scm ("Lyrics");
1080 RELATIVE absolute_pitch music {
1081 Pitch start = *unsmob_pitch ($2);
1082 $$ = make_music_relative (start, $3, @$);
1084 | RELATIVE composite_music {
1085 Pitch middle_c (0, 0, 0);
1086 $$ = make_music_relative (middle_c, $2, @$);
1091 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1093 grouped_music_list {
1094 /* Can also use music at the expensive of two S/Rs similar to
1095 \repeat \alternative */
1096 PARSER->lexer_->pop_state ();
1098 $$ = scm_cons ($3, SCM_EOL);
1100 | new_lyrics ADDLYRICS {
1101 PARSER->lexer_->push_lyric_state ();
1102 } grouped_music_list {
1103 PARSER->lexer_->pop_state ();
1104 $$ = scm_cons ($4, $1);
1109 grouped_music_list new_lyrics {
1110 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1112 | LYRICSTO simple_string {
1113 PARSER->lexer_->push_lyric_state ();
1115 PARSER->lexer_->pop_state ();
1116 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1121 CHANGE STRING '=' STRING {
1122 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1127 property_path_revved:
1129 $$ = scm_cons ($1, SCM_EOL);
1131 | property_path_revved embedded_scm {
1132 $$ = scm_cons ($2, $1);
1137 property_path_revved {
1138 $$ = scm_reverse_x ($1, SCM_EOL);
1144 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1145 scm_string_to_symbol ($1), $3);
1147 | UNSET simple_string {
1148 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1149 scm_string_to_symbol ($2));
1151 | OVERRIDE simple_string property_path '=' embedded_scm {
1152 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1153 scm_string_to_symbol ($2), $5),
1156 | REVERT simple_string embedded_scm {
1157 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1158 scm_string_to_symbol ($2), $3);
1163 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1164 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1166 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1167 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1168 | DENIES { $$ = ly_symbol2scm ("denies"); }
1170 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1171 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1172 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1173 | NAME { $$ = ly_symbol2scm ("context-name"); }
1177 property_operation { $$ = $1; }
1178 | context_def_mod STRING {
1179 $$ = scm_list_2 ($1, $2);
1185 if (!is_regular_identifier ($1))
1187 @$.error (_("Grob name should be alphanumeric"));
1190 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1191 scm_string_to_symbol ($1));
1193 | simple_string '.' simple_string {
1194 $$ = scm_list_2 (scm_string_to_symbol ($1),
1195 scm_string_to_symbol ($3));
1199 simple_music_property_def:
1200 OVERRIDE context_prop_spec property_path '=' scalar {
1201 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1202 ly_symbol2scm ("OverrideProperty"),
1207 | REVERT context_prop_spec embedded_scm {
1208 $$ = scm_list_4 (scm_car ($2),
1209 ly_symbol2scm ("RevertProperty"),
1213 | SET context_prop_spec '=' scalar {
1214 $$ = scm_list_4 (scm_car ($2),
1215 ly_symbol2scm ("PropertySet"),
1219 | UNSET context_prop_spec {
1220 $$ = scm_list_3 (scm_car ($2),
1221 ly_symbol2scm ("PropertyUnset"),
1227 simple_music_property_def {
1228 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1230 | ONCE simple_music_property_def {
1231 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1239 | STRING_IDENTIFIER {
1242 | string '+' string {
1243 $$ = scm_string_append (scm_list_2 ($1, $3));
1247 simple_string: STRING {
1253 | STRING_IDENTIFIER {
1274 $$ = scm_from_int ($1);
1279 /* TODO: Create a special case that avoids the creation of
1280 EventChords around simple_elements that have no post_events?
1282 simple_chord_elements post_events {
1283 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1286 /* why is this giving wrong start location? -ns
1288 i.set_location (@1, @2);
1289 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1291 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1293 i.set_location (@1, @3);
1294 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2, $3);
1297 | note_chord_element
1302 chord_body optional_notemode_duration post_events
1304 Music *m = unsmob_music ($1);
1305 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1306 SCM es = m->get_property ("elements");
1307 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1309 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1310 unsmob_music (scm_car (s))->set_property ("duration", dur);
1311 es = ly_append2 (es, postevs);
1313 m-> set_property ("elements", es);
1315 $$ = m->self_scm ();
1320 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1322 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1326 chord_body_elements:
1327 /* empty */ { $$ = SCM_EOL; }
1328 | chord_body_elements chord_body_element {
1329 $$ = scm_cons ($2, $1);
1334 pitch exclamations questions octave_check post_events
1341 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1342 n->set_property ("pitch", $1);
1344 n->set_property ("cautionary", SCM_BOOL_T);
1345 if (ex % 2 || q % 2)
1346 n->set_property ("force-accidental", SCM_BOOL_T);
1348 if (scm_is_pair (post)) {
1349 SCM arts = scm_reverse_x (post, SCM_EOL);
1350 n->set_property ("articulations", arts);
1352 if (scm_is_number (check))
1354 int q = scm_to_int (check);
1355 n->set_property ("absolute-octave", scm_from_int (q-1));
1358 $$ = n->unprotect ();
1360 | DRUM_PITCH post_events {
1361 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1362 n->set_property ("duration", $2);
1363 n->set_property ("drum-type", $1);
1365 if (scm_is_pair ($2)) {
1366 SCM arts = scm_reverse_x ($2, SCM_EOL);
1367 n->set_property ("articulations", arts);
1369 $$ = n->unprotect ();
1371 | music_function_chord_body {
1372 $$ = run_music_function (PARSER, $1);
1376 music_function_identifier_musicless_prefix: MUSIC_FUNCTION {
1377 SCM sig = scm_object_property (yylval.scm, ly_symbol2scm ("music-function-signature"));
1378 if (scm_is_pair (sig) && to_boolean (scm_memq (ly_music_p_proc, scm_cdr (scm_reverse (sig)))))
1380 PARSER->parser_error (@$, "Music function applied to event may not have a Music argument, except as the last argument.");
1385 music_function_chord_body:
1386 /* We could allow chord functions to have multiple music arguments,
1387 but it's more consistent with music_function_event if we
1388 prohibit it here too */
1389 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic chord_body_element {
1390 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1392 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1393 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1397 music_function_event:
1398 /* Post-events can only have the last argument as music, without this
1399 restriction we get a shift/reduce conflict from e.g.
1400 c8-\partcombine c8 -. */
1401 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic post_event {
1402 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1404 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1405 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1413 | SKIP duration_length {
1414 $$ = MAKE_SYNTAX ("skip-music", @$, $2);
1417 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1418 m->set_property ("span-direction", scm_from_int (START));
1419 $$ = m->unprotect();
1422 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1423 m->set_property ("span-direction", scm_from_int (STOP));
1424 $$ = m->unprotect ();
1427 $$ = MAKE_SYNTAX ("voice-separator", @$, SCM_UNDEFINED);
1430 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1432 Music *m = unsmob_music (pipe);
1437 $$ = m->unprotect ();
1440 $$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
1443 | PARTIAL duration_length {
1444 Moment m = - unsmob_duration ($2)->get_length ();
1445 $$ = MAKE_SYNTAX ("property-operation", @$, SCM_BOOL_F, ly_symbol2scm ("Timing"), ly_symbol2scm ("PropertySet"), ly_symbol2scm ("measurePosition"), m.smobbed_copy ());
1446 $$ = MAKE_SYNTAX ("context-specification", @$, ly_symbol2scm ("Score"), SCM_BOOL_F, $$, SCM_EOL, SCM_BOOL_F);
1450 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1452 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1455 SCM proc = ly_lily_module_constant ("make-mark-set");
1457 $$ = scm_call_1 (proc, $2);
1463 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
1466 Music *m = MY_MAKE_MUSIC ("MarkEvent", @$);
1467 $$ = m->unprotect ();
1473 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1474 $$ = key->unprotect ();
1476 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1478 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1479 if (scm_ilength ($3) > 0)
1481 key->set_property ("pitch-alist", $3);
1482 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1483 key->transpose (* unsmob_pitch ($2));
1485 PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1488 $$ = key->unprotect ();
1497 | post_events post_event {
1498 unsmob_music ($2)->set_spot (@2);
1499 $$ = scm_cons ($2, $$);
1504 direction_less_event {
1507 | '-' music_function_event {
1508 $$ = run_music_function (PARSER, $2);
1511 if (!PARSER->lexer_->is_lyric_state ())
1512 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1513 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
1516 if (!PARSER->lexer_->is_lyric_state ())
1517 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1518 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
1520 | script_dir direction_reqd_event {
1523 Music *m = unsmob_music ($2);
1524 m->set_property ("direction", scm_from_int ($1));
1528 | script_dir direction_less_event {
1531 Music *m = unsmob_music ($2);
1532 m->set_property ("direction", scm_from_int ($1));
1536 | string_number_event
1539 string_number_event:
1541 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
1542 s->set_property ("string-number", scm_from_int ($1));
1543 $$ = s->unprotect ();
1547 direction_less_char:
1549 $$ = ly_symbol2scm ("bracketOpenSymbol");
1552 $$ = ly_symbol2scm ("bracketCloseSymbol");
1555 $$ = ly_symbol2scm ("tildeSymbol");
1558 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1561 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1564 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1567 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1570 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1573 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1576 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1580 direction_less_event:
1581 direction_less_char {
1582 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
1584 if (unsmob_music (predefd))
1586 m = unsmob_music (predefd)->clone ();
1591 m = MY_MAKE_MUSIC ("Music", @$);
1593 $$ = m->unprotect ();
1595 | EVENT_IDENTIFIER {
1599 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
1600 a->set_property ("tremolo-type", scm_from_int ($1));
1601 $$ = a->unprotect ();
1605 direction_reqd_event:
1609 | script_abbreviation {
1610 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1611 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
1612 if (scm_is_string (s))
1613 a->set_property ("articulation-type", s);
1614 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
1615 $$ = a->unprotect ();
1620 /**/ { $$ = SCM_EOL; }
1621 | '=' { $$ = scm_from_int (0); }
1622 | '=' sub_quotes { $$ = scm_from_int (-$2); }
1623 | '=' sup_quotes { $$ = scm_from_int ($2); }
1648 | NOTENAME_PITCH sup_quotes {
1649 Pitch p = *unsmob_pitch ($1);
1650 p = p.transposed (Pitch ($2,0,0));
1651 $$ = p.smobbed_copy ();
1653 | NOTENAME_PITCH sub_quotes {
1654 Pitch p =* unsmob_pitch ($1);
1655 p = p.transposed (Pitch (-$2,0,0));
1656 $$ = p.smobbed_copy ();
1668 | TONICNAME_PITCH sup_quotes {
1669 Pitch p = *unsmob_pitch ($1);
1670 p = p.transposed (Pitch ($2,0,0));
1671 $$ = p.smobbed_copy ();
1673 | TONICNAME_PITCH sub_quotes {
1674 Pitch p = *unsmob_pitch ($1);
1676 p = p.transposed (Pitch (-$2,0,0));
1677 $$ = p.smobbed_copy ();
1687 pitch_also_in_chords:
1694 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1695 t->set_property ("text", $1);
1696 $$ = t->unprotect ();
1699 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1700 t->set_property ("text",
1701 make_simple_markup ($1));
1702 $$ = t->unprotect ();
1705 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
1706 t->set_property ("digit", scm_from_int ($1));
1707 $$ = t->unprotect ();
1711 script_abbreviation:
1713 $$ = scm_from_locale_string ("Hat");
1716 $$ = scm_from_locale_string ("Plus");
1719 $$ = scm_from_locale_string ("Dash");
1722 $$ = scm_from_locale_string ("Bar");
1725 $$ = scm_from_locale_string ("Larger");
1728 $$ = scm_from_locale_string ("Dot");
1731 $$ = scm_from_locale_string ("Underscore");
1738 | '-' { $$ = CENTER; }
1749 multiplied_duration {
1754 optional_notemode_duration:
1756 Duration dd = PARSER->default_duration_;
1757 $$ = dd.smobbed_copy ();
1759 | multiplied_duration {
1761 PARSER->default_duration_ = *unsmob_duration ($$);
1766 bare_unsigned dots {
1768 if (!is_duration ($1))
1769 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
1773 $$ = Duration (len, $2).smobbed_copy ();
1775 | DURATION_IDENTIFIER dots {
1776 Duration *d = unsmob_duration ($1);
1777 Duration k (d->duration_log (), d->dot_count () + $2);
1783 multiplied_duration:
1787 | multiplied_duration '*' bare_unsigned {
1788 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1790 | multiplied_duration '*' FRACTION {
1791 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1793 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1798 FRACTION { $$ = $1; }
1799 | UNSIGNED '/' UNSIGNED {
1800 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
1817 | ':' bare_unsigned {
1818 if (!is_duration ($2))
1819 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
1826 $$ = scm_from_int ($1);
1829 $$ = scm_from_int ($1);
1831 | STRING { $$ = $1; }
1832 | full_markup { $$ = $1; }
1835 figured_bass_alteration:
1836 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
1837 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
1838 | '!' { $$ = scm_from_int (0); }
1843 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
1844 $$ = bfr->unprotect ();
1847 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
1848 $$ = bfr->self_scm ();
1850 if (scm_is_number ($1))
1851 bfr->set_property ("figure", $1);
1852 else if (Text_interface::is_markup ($1))
1853 bfr->set_property ("text", $1);
1859 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
1861 | bass_figure figured_bass_alteration {
1862 Music *m = unsmob_music ($1);
1863 if (scm_to_double ($2)) {
1864 SCM salter = m->get_property ("alteration");
1865 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
1866 m->set_property ("alteration",
1867 scm_sum (alter, $2));
1869 m->set_property ("alteration", scm_from_int (0));
1872 | bass_figure figured_bass_modification {
1873 Music *m = unsmob_music ($1);
1874 if ($2 == ly_symbol2scm ("plus"))
1876 m->set_property ("augmented", SCM_BOOL_T);
1878 else if ($2 == ly_symbol2scm ("slash"))
1880 m->set_property ("diminished", SCM_BOOL_T);
1882 else if ($2 == ly_symbol2scm ("exclamation"))
1884 m->set_property ("no-continuation", SCM_BOOL_T);
1890 figured_bass_modification:
1892 $$ = ly_symbol2scm ("plus");
1895 $$ = ly_symbol2scm ("exclamation");
1898 $$ = ly_symbol2scm ("slash");
1908 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
1916 | figure_list br_bass_figure {
1917 $$ = scm_cons ($2, $1);
1922 FIGURE_OPEN figure_list FIGURE_CLOSE {
1923 $$ = scm_reverse_x ($2, SCM_EOL);
1934 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
1935 if (!PARSER->lexer_->is_note_state ())
1936 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
1940 n = MY_MAKE_MUSIC ("RestEvent", @$);
1942 n = MY_MAKE_MUSIC ("NoteEvent", @$);
1944 n->set_property ("pitch", $1);
1945 n->set_property ("duration", $5);
1947 if (scm_is_number ($4))
1949 int q = scm_to_int ($4);
1950 n->set_property ("absolute-octave", scm_from_int (q-1));
1954 n->set_property ("cautionary", SCM_BOOL_T);
1955 if ($2 % 2 || $3 % 2)
1956 n->set_property ("force-accidental", SCM_BOOL_T);
1958 $$ = n->unprotect ();
1960 | DRUM_PITCH optional_notemode_duration {
1961 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1962 n->set_property ("duration", $2);
1963 n->set_property ("drum-type", $1);
1965 $$ = n->unprotect ();
1967 | RESTNAME optional_notemode_duration {
1969 if (ly_scm2string ($1) == "s") {
1971 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
1974 ev = MY_MAKE_MUSIC ("RestEvent", @$);
1977 ev->set_property ("duration", $2);
1978 $$ = ev->unprotect ();
1980 | lyric_element optional_notemode_duration {
1981 if (!PARSER->lexer_->is_lyric_state ())
1982 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1984 Music *levent = MY_MAKE_MUSIC ("LyricEvent", @$);
1985 levent->set_property ("text", $1);
1986 levent->set_property ("duration",$2);
1987 $$= levent->unprotect ();
1991 simple_chord_elements:
1993 $$ = scm_list_1 ($1);
1996 if (!PARSER->lexer_->is_chord_state ())
1997 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2000 | figure_spec optional_notemode_duration {
2001 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2003 unsmob_music (scm_car (s))->set_property ("duration", $2);
2019 steno_tonic_pitch optional_notemode_duration {
2020 $$ = make_chord_elements ($1, $2, SCM_EOL);
2022 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2023 SCM its = scm_reverse_x ($4, SCM_EOL);
2024 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2032 | chord_items chord_item {
2033 $$ = scm_cons ($2, $$);
2039 $$ = ly_symbol2scm ("chord-colon");
2042 $$ = ly_symbol2scm ("chord-caret");
2044 | CHORD_SLASH steno_tonic_pitch {
2045 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2047 | CHORD_BASS steno_tonic_pitch {
2048 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2057 $$ = scm_reverse_x ($1, SCM_EOL);
2065 step_number { $$ = scm_cons ($1, SCM_EOL); }
2066 | step_numbers '.' step_number {
2067 $$ = scm_cons ($3, $$);
2073 $$ = make_chord_step ($1, 0);
2075 | bare_unsigned '+' {
2076 $$ = make_chord_step ($1, SHARP_ALTERATION);
2078 | bare_unsigned CHORD_MINUS {
2079 $$ = make_chord_step ($1, FLAT_ALTERATION);
2086 TODO: should deprecate in favor of Scheme?
2090 number_expression '+' number_term {
2091 $$ = scm_sum ($1, $3);
2093 | number_expression '-' number_term {
2094 $$ = scm_difference ($1, $3);
2103 | number_factor '*' number_factor {
2104 $$ = scm_product ($1, $3);
2106 | number_factor '/' number_factor {
2107 $$ = scm_divide ($1, $3);
2112 '-' number_factor { /* %prec UNARY_MINUS */
2113 $$ = scm_difference ($2, SCM_UNDEFINED);
2121 $$ = scm_from_int ($1);
2126 | NUMBER_IDENTIFIER {
2129 | REAL NUMBER_IDENTIFIER {
2130 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2132 | UNSIGNED NUMBER_IDENTIFIER {
2133 $$ = scm_from_double ($1 *scm_to_double ($2));
2148 bare_unsigned { $$ = scm_from_int ($1); }
2149 | NUMBER_IDENTIFIER {
2157 | exclamations '!' { $$ ++; }
2162 | questions '?' { $$ ++; }
2166 This should be done more dynamically if possible.
2170 LYRIC_MARKUP_IDENTIFIER {
2174 { PARSER->lexer_->push_markup_state (); }
2177 PARSER->lexer_->pop_state ();
2186 { PARSER->lexer_->push_markup_state (); }
2189 PARSER->lexer_->pop_state ();
2195 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2197 | markup_head_1_list simple_markup {
2198 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2206 markup_composed_list {
2209 | markup_braced_list {
2214 markup_composed_list:
2215 markup_head_1_list markup_braced_list {
2216 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2222 '{' markup_braced_list_body '}' {
2223 $$ = scm_reverse_x ($2, SCM_EOL);
2227 markup_braced_list_body:
2228 /* empty */ { $$ = SCM_EOL; }
2229 | markup_braced_list_body markup {
2230 $$ = scm_cons ($2, $1);
2232 | markup_braced_list_body markup_list {
2233 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2238 MARKUP_HEAD_MARKUP0 {
2239 $$ = scm_list_1 ($1);
2241 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2242 $$ = scm_list_2 ($1, $2);
2244 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2245 $$ = scm_list_3 ($1, $2, $3);
2250 markup_head_1_item {
2251 $$ = scm_list_1 ($1);
2253 | markup_head_1_list markup_head_1_item {
2254 $$ = scm_cons ($2, $1);
2260 $$ = make_simple_markup ($1);
2262 | MARKUP_IDENTIFIER {
2265 | LYRIC_MARKUP_IDENTIFIER {
2268 | STRING_IDENTIFIER {
2272 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2273 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2274 } '{' score_body '}' {
2276 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2278 PARSER->lexer_->pop_state ();
2280 | MARKUP_HEAD_SCM0 embedded_scm {
2281 $$ = scm_list_2 ($1, $2);
2283 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2284 $$ = scm_list_4 ($1, $2, $3, $4);
2286 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2287 $$ = scm_list_3 ($1, $2, $3);
2289 | MARKUP_HEAD_EMPTY {
2290 $$ = scm_list_1 ($1);
2292 | MARKUP_HEAD_LIST0 markup_list {
2293 $$ = scm_list_2 ($1,$2);
2295 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2296 $$ = scm_list_3 ($1, $2, $3);
2301 markup_head_1_list simple_markup {
2302 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2303 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2313 Lily_parser::set_yydebug (bool x)
2319 Lily_parser::do_yyparse ()
2321 yyparse ((void*)this);
2330 It is a little strange to have this function in this file, but
2331 otherwise, we have to import music classes into the lexer.
2335 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2337 if (scm_is_string (sid)) {
2339 return STRING_IDENTIFIER;
2340 } else if (unsmob_book (sid)) {
2341 Book *book = unsmob_book (sid)->clone ();
2342 *destination = book->self_scm ();
2345 return BOOK_IDENTIFIER;
2346 } else if (scm_is_number (sid)) {
2348 return NUMBER_IDENTIFIER;
2349 } else if (unsmob_context_def (sid)) {
2350 Context_def *def= unsmob_context_def (sid)->clone ();
2352 *destination = def->self_scm ();
2355 return CONTEXT_DEF_IDENTIFIER;
2356 } else if (unsmob_score (sid)) {
2357 Score *score = new Score (*unsmob_score (sid));
2358 *destination = score->self_scm ();
2360 score->unprotect ();
2361 return SCORE_IDENTIFIER;
2362 } else if (Music *mus = unsmob_music (sid)) {
2363 mus = mus->clone ();
2364 *destination = mus->self_scm ();
2365 unsmob_music (*destination)->
2366 set_property ("origin", make_input (last_input_));
2368 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2372 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2373 } else if (unsmob_duration (sid)) {
2374 *destination = unsmob_duration (sid)->smobbed_copy ();
2375 return DURATION_IDENTIFIER;
2376 } else if (unsmob_output_def (sid)) {
2377 Output_def *p = unsmob_output_def (sid);
2380 *destination = p->self_scm ();
2382 return OUTPUT_DEF_IDENTIFIER;
2383 } else if (Text_interface::is_markup (sid)) {
2385 if (is_lyric_state ())
2386 return LYRIC_MARKUP_IDENTIFIER;
2387 return MARKUP_IDENTIFIER;
2394 get_next_unique_context_id ()
2396 return scm_from_locale_string ("$uniqueContextId");
2401 get_next_unique_lyrics_context_id ()
2403 static int new_context_count;
2405 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2406 return scm_from_locale_string (s);
2411 run_music_function (Lily_parser *parser, SCM expr)
2413 SCM func = scm_car (expr);
2414 Input *loc = unsmob_input (scm_cadr (expr));
2415 SCM args = scm_cddr (expr);
2416 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2418 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2420 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2422 parser->error_level_ = 1;
2423 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (*loc)));
2426 SCM syntax_args = scm_list_4 (parser->self_scm (), make_input (*loc), func, args);
2427 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
2431 is_regular_identifier (SCM id)
2433 string str = ly_scm2string (id);
2434 char const *s = str.c_str ();
2443 v = v && isalnum (*s);
2450 make_music_with_input (SCM name, Input where)
2452 Music *m = make_music_by_name (name);
2453 m->set_spot (where);
2458 get_first_context_id (SCM type, Music *m)
2460 SCM id = m->get_property ("context-id");
2461 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2462 && scm_is_string (m->get_property ("context-id"))
2463 && scm_c_string_length (id) > 0)
2471 make_simple_markup (SCM a)
2479 return t && t == 1 << intlog2 (t);
2483 set_music_properties (Music *p, SCM a)
2485 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2486 p->set_property (scm_caar (k), scm_cdar (k));
2491 make_chord_step (int step, Rational alter)
2494 alter += FLAT_ALTERATION;
2498 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2499 return m.smobbed_copy ();
2504 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
2506 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
2507 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
2511 /* Todo: actually also use apply iso. call too ... */
2513 ly_input_procedure_p (SCM x)
2515 return ly_is_procedure (x)
2516 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2520 make_music_relative (Pitch start, SCM music, Input loc)
2522 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic", loc);
2523 relative->set_property ("element", music);
2525 Music *m = unsmob_music (music);
2526 Pitch last = m->to_relative_octave (start);
2527 if (lily_1_8_relative)
2528 m->set_property ("last-pitch", last.smobbed_copy ());
2529 return relative->unprotect ();
2533 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2535 Lily_parser *pars = (Lily_parser*) v;
2536 Lily_lexer *lex = pars->lexer_;
2538 lex->lexval = (void*) s;
2540 lex->prepare_for_next_token ();
2541 return lex->yylex ();