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_MARKUP1_MARKUP2
283 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
284 %token <scm> MARKUP_IDENTIFIER
285 %token <scm> MUSIC_FUNCTION
286 %token <scm> MUSIC_IDENTIFIER
287 %token <scm> NOTENAME_PITCH
288 %token <scm> NUMBER_IDENTIFIER
289 %token <scm> OUTPUT_DEF_IDENTIFIER
291 %token <scm> RESTNAME
292 %token <scm> SCM_IDENTIFIER
293 %token <scm> SCM_TOKEN
294 %token <scm> SCORE_IDENTIFIER
296 %token <scm> STRING_IDENTIFIER
297 %token <scm> TONICNAME_PITCH
300 %type <book> book_block
301 %type <book> book_body
303 %type <i> bare_unsigned
304 %type <scm> figured_bass_alteration
306 %type <i> exclamations
307 %type <i> optional_rest
312 %type <i> tremolo_type
315 %type <scm> composite_music
316 %type <scm> grouped_music_list
318 %type <scm> prefix_composite_music
319 %type <scm> repeated_music
320 %type <scm> sequential_music
321 %type <scm> simple_music
322 %type <scm> simultaneous_music
323 %type <scm> chord_body
324 %type <scm> chord_body_element
325 %type <scm> command_element
326 %type <scm> command_event
327 %type <scm> context_change
328 %type <scm> direction_less_event
329 %type <scm> direction_reqd_event
330 %type <scm> event_chord
331 %type <scm> gen_text_def
332 %type <scm> music_property_def
333 %type <scm> note_chord_element
334 %type <scm> post_event
335 %type <scm> re_rhythmed_music
336 %type <scm> relative_music
337 %type <scm> simple_element
338 %type <scm> simple_music_property_def
339 %type <scm> string_number_event
340 %type <scm> tempo_event
342 %type <outputdef> output_def_body
343 %type <outputdef> output_def_head
344 %type <outputdef> output_def_head_with_mode_switch
345 %type <outputdef> output_def
346 %type <outputdef> paper_block
348 %type <scm> alternative_music
349 %type <scm> generic_prefix_music_scm
350 %type <scm> music_list
351 %type <scm> absolute_pitch
352 %type <scm> assignment_id
353 %type <scm> bare_number
354 %type <scm> unsigned_number
355 %type <scm> bass_figure
356 %type <scm> figured_bass_modification
357 %type <scm> br_bass_figure
358 %type <scm> bass_number
359 %type <scm> chord_body_elements
360 %type <scm> chord_item
361 %type <scm> chord_items
362 %type <scm> chord_separator
363 %type <scm> context_def_mod
364 %type <scm> context_def_spec_block
365 %type <scm> context_def_spec_body
366 %type <scm> context_mod
367 %type <scm> context_mod_list
368 %type <scm> context_prop_spec
369 %type <scm> direction_less_char
370 %type <scm> duration_length
371 %type <scm> embedded_scm
372 %type <scm> figure_list
373 %type <scm> figure_spec
375 %type <scm> full_markup
376 %type <scm> function_scm_argument
377 %type <scm> function_arglist
378 %type <scm> function_arglist_music_last
379 %type <scm> function_arglist_nonmusic_last
380 %type <scm> function_arglist_nonmusic
381 %type <scm> identifier_init
382 %type <scm> lilypond_header
383 %type <scm> lilypond_header_body
384 %type <scm> lyric_element
385 %type <scm> lyric_markup
387 %type <scm> markup_braced_list
388 %type <scm> markup_braced_list_body
389 %type <scm> markup_composed_list
390 %type <scm> markup_head_1_item
391 %type <scm> markup_head_1_list
392 %type <scm> markup_list
393 %type <scm> markup_top
394 %type <scm> mode_changing_head
395 %type <scm> mode_changing_head_with_context
396 %type <scm> multiplied_duration
397 %type <scm> music_function_identifier_musicless_prefix
398 %type <scm> music_function_event
399 %type <scm> music_function_chord_body
400 %type <scm> new_chord
401 %type <scm> new_lyrics
402 %type <scm> number_expression
403 %type <scm> number_factor
404 %type <scm> number_term
405 %type <scm> object_id_setting
406 %type <scm> octave_check
407 %type <scm> optional_context_mod
408 %type <scm> optional_id
409 %type <scm> optional_notemode_duration
411 %type <scm> pitch_also_in_chords
412 %type <scm> post_events
413 %type <scm> property_operation
414 %type <scm> property_path property_path_revved
416 %type <scm> script_abbreviation
417 %type <scm> simple_chord_elements
418 %type <scm> simple_markup
419 %type <scm> simple_string
420 %type <scm> steno_duration
421 %type <scm> steno_pitch
422 %type <scm> steno_tonic_pitch
423 %type <scm> step_number
424 %type <scm> step_numbers
427 %type <score> score_block
428 %type <score> score_body
433 /* We don't assign precedence to / and *, because we might need varied
434 prec levels in different prods */
440 lilypond: /* empty */
441 | lilypond toplevel_expression {
443 | lilypond assignment {
446 PARSER->error_level_ = 1;
449 PARSER->error_level_ = 1;
455 OBJECTID STRING { $$ = $2; }
460 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
464 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
465 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
471 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
472 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
476 Music *music = unsmob_music ($1);
477 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
478 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
481 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
482 scm_call_2 (proc, PARSER->self_scm (), $1);
486 Output_def * od = $1;
488 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
489 id = ly_symbol2scm ("$defaultpaper");
490 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
491 id = ly_symbol2scm ("$defaultmidi");
492 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
493 id = ly_symbol2scm ("$defaultlayout");
495 PARSER->lexer_->set_identifier (id, od->self_scm ());
506 lilypond_header_body:
508 $$ = get_header (PARSER);
509 PARSER->lexer_->add_scope ($$);
511 | lilypond_header_body assignment {
517 HEADER '{' lilypond_header_body '}' {
518 $$ = PARSER->lexer_->remove_scope ();
527 | LYRICS_STRING { $$ = $1; }
531 assignment_id '=' identifier_init {
532 PARSER->lexer_->set_identifier ($1, $3);
535 TODO: devise standard for protection in parser.
537 The parser stack lives on the C-stack, which means that
538 all objects can be unprotected as soon as they're here.
548 $$ = $1->self_scm ();
552 $$ = $1->self_scm ();
556 $$ = $1->self_scm ();
559 | context_def_spec_block {
563 /* Hack: Create event-chord around standalone events.
564 Prevents the identifier from being interpreted as a post-event. */
565 Music *mus = unsmob_music ($1);
566 bool is_event = mus &&
567 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
572 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
577 | number_expression {
590 $$ = scm_from_int ($1);
594 context_def_spec_block:
595 CONTEXT '{' context_def_spec_body '}'
601 context_def_spec_body:
603 $$ = Context_def::make_scm ();
604 unsmob_context_def ($$)->origin ()->set_spot (@$);
606 | CONTEXT_DEF_IDENTIFIER {
608 unsmob_context_def ($$)->origin ()->set_spot (@$);
610 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
611 Context_def*td = unsmob_context_def ($$);
613 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
614 SCM tag = scm_caar (p);
616 /* TODO: should make new tag "grob-definition" ? */
617 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
618 tag, scm_cons (scm_cdar (p), SCM_EOL)));
621 | context_def_spec_body context_mod {
622 unsmob_context_def ($$)->add_context_mod ($2);
629 BOOK '{' book_body '}' {
635 * Use 'handlers' like for toplevel-* stuff?
636 * grok \layout and \midi? */
640 $$->origin ()->set_spot (@$);
641 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
642 $$->paper_->unprotect ();
643 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
646 $$ = unsmob_book ($1);
648 $$->origin ()->set_spot (@$);
650 | book_body paper_block {
654 | book_body score_block {
656 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
657 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
660 | book_body composite_music {
661 Music *music = unsmob_music ($2);
662 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
663 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
665 | book_body full_markup {
666 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
667 scm_call_2 (proc, $$->self_scm (), $2);
669 | book_body lilypond_header {
674 $$->scores_ = SCM_EOL;
676 | book_body object_id_setting {
677 $$->user_key_ = ly_scm2string ($2);
682 SCORE '{' score_body '}' {
690 SCM scorify = ly_lily_module_constant ("scorify-music");
691 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
693 // pass ownernship to C++ again.
694 $$ = unsmob_score (score);
696 $$->origin ()->set_spot (@$);
699 $$ = unsmob_score ($1);
701 $$->origin ()->set_spot (@$);
703 | score_body object_id_setting {
704 $$->user_key_ = ly_scm2string ($2);
706 | score_body lilypond_header {
709 | score_body output_def {
710 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
712 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
717 $$->add_output_def ($2);
722 $$->error_found_ = true;
734 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
736 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
738 $$ = get_paper (PARSER);
745 output_def_body '}' {
748 PARSER->lexer_->remove_scope ();
749 PARSER->lexer_->pop_state ();
755 $$ = get_paper (PARSER);
756 $$->input_origin_ = @$;
757 PARSER->lexer_->add_scope ($$->scope_);
760 Output_def *p = get_midi (PARSER);
762 PARSER->lexer_->add_scope (p->scope_);
765 Output_def *p = get_layout (PARSER);
767 PARSER->lexer_->add_scope (p->scope_);
772 output_def_head_with_mode_switch:
774 PARSER->lexer_->push_initial_state ();
780 output_def_head_with_mode_switch '{' {
782 $$->input_origin_.set_spot (@$);
784 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
787 Output_def *o = unsmob_output_def ($3);
788 o->input_origin_.set_spot (@$);
791 PARSER->lexer_->remove_scope ();
792 PARSER->lexer_->add_scope (o->scope_);
794 | output_def_body assignment {
797 | output_def_body context_def_spec_block {
798 assign_context_def ($$, $2);
800 | output_def_body error {
806 TEMPO steno_duration '=' bare_unsigned {
807 $$ = MAKE_SYNTAX ("tempo", @$, $2, scm_int2num ($4));
812 The representation of a list is the
816 to have efficient append. */
820 $$ = scm_cons (SCM_EOL, SCM_EOL);
824 SCM c = scm_cons ($2, SCM_EOL);
826 if (scm_is_pair (scm_cdr (s)))
827 scm_set_cdr_x (scm_cdr (s), c); /* append */
829 scm_set_car_x (s, c); /* set first cons */
830 scm_set_cdr_x (s, c); /* remember last cell */
832 | music_list embedded_scm {
836 Music *m = MY_MAKE_MUSIC("Music", @$);
838 m->set_property ("error-found", SCM_BOOL_T);
840 SCM c = scm_cons (m->self_scm (), SCM_EOL);
841 m->unprotect (); /* UGH */
843 if (scm_is_pair (scm_cdr (s)))
844 scm_set_cdr_x (scm_cdr (s), c); /* append */
846 scm_set_car_x (s, c); /* set first cons */
847 scm_set_cdr_x (s, c); /* remember last cell */
860 | ALTERNATIVE '{' music_list '}' {
867 REPEAT simple_string unsigned_number music alternative_music
869 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $5);
874 SEQUENTIAL '{' music_list '}' {
875 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($3));
877 | '{' music_list '}' {
878 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($2));
883 SIMULTANEOUS '{' music_list '}'{
884 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($3));
886 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
887 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($2));
898 optional_context_mod:
899 /**/ { $$ = SCM_EOL; }
900 | WITH { PARSER->lexer_->push_initial_state (); }
901 '{' context_mod_list '}'
903 PARSER->lexer_->pop_state ();
909 /* */ { $$ = SCM_EOL; }
910 | context_mod_list context_mod {
911 $$ = scm_cons ($2, $1);
916 prefix_composite_music { $$ = $1; }
917 | grouped_music_list { $$ = $1; }
921 simultaneous_music { $$ = $1; }
922 | sequential_music { $$ = $1; }
925 function_scm_argument:
930 /* An argument list. If a function \foo expects scm scm music, then the lexer expands \foo into the token sequence:
931 MUSIC_FUNCTION EXPECT_MUSIC EXPECT_SCM EXPECT_SCM
932 and this rule returns the reversed list of arguments. */
934 function_arglist_music_last:
935 EXPECT_MUSIC function_arglist music {
936 $$ = scm_cons ($3, $2);
940 function_arglist_nonmusic_last:
941 EXPECT_MARKUP function_arglist full_markup {
942 $$ = scm_cons ($3, $2);
944 | EXPECT_SCM function_arglist function_scm_argument {
945 $$ = scm_cons ($3, $2);
949 function_arglist_nonmusic: EXPECT_NO_MORE_ARGS {
952 | EXPECT_MARKUP function_arglist_nonmusic full_markup {
953 $$ = scm_cons ($3, $2);
955 | EXPECT_SCM function_arglist_nonmusic function_scm_argument {
956 $$ = scm_cons ($3, $2);
960 function_arglist: EXPECT_NO_MORE_ARGS {
961 /* This is for 0-ary functions, so they don't need to
962 read a lookahead token */
965 | function_arglist_music_last
966 | function_arglist_nonmusic_last
969 generic_prefix_music_scm:
970 MUSIC_FUNCTION function_arglist {
971 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
977 /**/ { $$ = SCM_EOL; }
978 | '=' simple_string {
984 prefix_composite_music:
985 generic_prefix_music_scm {
986 $$ = run_music_function (PARSER, $1);
988 | CONTEXT simple_string optional_id optional_context_mod music {
989 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_F);
991 | NEWCONTEXT simple_string optional_id optional_context_mod music {
992 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_T);
995 | TIMES fraction music {
996 $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3);
998 | repeated_music { $$ = $1; }
999 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords music {
1000 Pitch from = *unsmob_pitch ($2);
1001 Pitch to = *unsmob_pitch ($3);
1002 SCM pitch = pitch_interval (from, to).smobbed_copy ();
1003 $$ = MAKE_SYNTAX ("transpose-music", @$, pitch, $4);
1005 | mode_changing_head grouped_music_list {
1006 if ($1 == ly_symbol2scm ("chords"))
1008 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1014 PARSER->lexer_->pop_state ();
1016 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1017 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, $3, $2, SCM_BOOL_T);
1018 if ($1 == ly_symbol2scm ("ChordNames"))
1020 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1022 PARSER->lexer_->pop_state ();
1024 | relative_music { $$ = $1; }
1025 | re_rhythmed_music { $$ = $1; }
1030 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1031 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1033 $$ = ly_symbol2scm ("notes");
1037 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1038 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1040 $$ = ly_symbol2scm ("drums");
1043 PARSER->lexer_->push_figuredbass_state ();
1045 $$ = ly_symbol2scm ("figures");
1048 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1049 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1050 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1051 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1052 $$ = ly_symbol2scm ("chords");
1056 { PARSER->lexer_->push_lyric_state ();
1057 $$ = ly_symbol2scm ("lyrics");
1061 mode_changing_head_with_context:
1063 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1064 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1066 $$ = ly_symbol2scm ("DrumStaff");
1069 PARSER->lexer_->push_figuredbass_state ();
1071 $$ = ly_symbol2scm ("FiguredBass");
1074 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1075 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1076 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1077 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1078 $$ = ly_symbol2scm ("ChordNames");
1081 { PARSER->lexer_->push_lyric_state ();
1082 $$ = ly_symbol2scm ("Lyrics");
1088 RELATIVE absolute_pitch music {
1089 Pitch start = *unsmob_pitch ($2);
1090 $$ = make_music_relative (start, $3, @$);
1092 | RELATIVE composite_music {
1093 Pitch middle_c (0, 0, 0);
1094 $$ = make_music_relative (middle_c, $2, @$);
1099 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1101 grouped_music_list {
1102 /* Can also use music at the expensive of two S/Rs similar to
1103 \repeat \alternative */
1104 PARSER->lexer_->pop_state ();
1106 $$ = scm_cons ($3, SCM_EOL);
1108 | new_lyrics ADDLYRICS {
1109 PARSER->lexer_->push_lyric_state ();
1110 } grouped_music_list {
1111 PARSER->lexer_->pop_state ();
1112 $$ = scm_cons ($4, $1);
1117 grouped_music_list new_lyrics {
1118 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1120 | LYRICSTO simple_string {
1121 PARSER->lexer_->push_lyric_state ();
1123 PARSER->lexer_->pop_state ();
1124 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1129 CHANGE STRING '=' STRING {
1130 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1135 property_path_revved:
1137 $$ = scm_cons ($1, SCM_EOL);
1139 | property_path_revved embedded_scm {
1140 $$ = scm_cons ($2, $1);
1145 property_path_revved {
1146 $$ = scm_reverse_x ($1, SCM_EOL);
1152 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1153 scm_string_to_symbol ($1), $3);
1155 | UNSET simple_string {
1156 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1157 scm_string_to_symbol ($2));
1159 | OVERRIDE simple_string property_path '=' embedded_scm {
1160 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1161 scm_string_to_symbol ($2), $5),
1164 | REVERT simple_string embedded_scm {
1165 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1166 scm_string_to_symbol ($2), $3);
1171 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1172 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1174 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1175 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1176 | DENIES { $$ = ly_symbol2scm ("denies"); }
1178 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1179 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1180 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1181 | NAME { $$ = ly_symbol2scm ("context-name"); }
1185 property_operation { $$ = $1; }
1186 | context_def_mod STRING {
1187 $$ = scm_list_2 ($1, $2);
1193 if (!is_regular_identifier ($1))
1195 @$.error (_("Grob name should be alphanumeric"));
1198 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1199 scm_string_to_symbol ($1));
1201 | simple_string '.' simple_string {
1202 $$ = scm_list_2 (scm_string_to_symbol ($1),
1203 scm_string_to_symbol ($3));
1207 simple_music_property_def:
1208 OVERRIDE context_prop_spec property_path '=' scalar {
1209 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1210 ly_symbol2scm ("OverrideProperty"),
1215 | REVERT context_prop_spec embedded_scm {
1216 $$ = scm_list_4 (scm_car ($2),
1217 ly_symbol2scm ("RevertProperty"),
1221 | SET context_prop_spec '=' scalar {
1222 $$ = scm_list_4 (scm_car ($2),
1223 ly_symbol2scm ("PropertySet"),
1227 | UNSET context_prop_spec {
1228 $$ = scm_list_3 (scm_car ($2),
1229 ly_symbol2scm ("PropertyUnset"),
1235 simple_music_property_def {
1236 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1238 | ONCE simple_music_property_def {
1239 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1247 | STRING_IDENTIFIER {
1250 | string '+' string {
1251 $$ = scm_string_append (scm_list_2 ($1, $3));
1255 simple_string: STRING {
1261 | STRING_IDENTIFIER {
1282 $$ = scm_from_int ($1);
1287 /* TODO: Create a special case that avoids the creation of
1288 EventChords around simple_elements that have no post_events?
1290 simple_chord_elements post_events {
1291 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1294 /* why is this giving wrong start location? -ns
1296 i.set_location (@1, @2);
1297 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1299 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1301 i.set_location (@1, @3);
1302 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2, $3);
1305 | note_chord_element
1310 chord_body optional_notemode_duration post_events
1312 Music *m = unsmob_music ($1);
1313 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1314 SCM es = m->get_property ("elements");
1315 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1317 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1318 unsmob_music (scm_car (s))->set_property ("duration", dur);
1319 es = ly_append2 (es, postevs);
1321 m-> set_property ("elements", es);
1323 $$ = m->self_scm ();
1328 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1330 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1334 chord_body_elements:
1335 /* empty */ { $$ = SCM_EOL; }
1336 | chord_body_elements chord_body_element {
1337 $$ = scm_cons ($2, $1);
1342 pitch exclamations questions octave_check post_events
1349 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1350 n->set_property ("pitch", $1);
1352 n->set_property ("cautionary", SCM_BOOL_T);
1353 if (ex % 2 || q % 2)
1354 n->set_property ("force-accidental", SCM_BOOL_T);
1356 if (scm_is_pair (post)) {
1357 SCM arts = scm_reverse_x (post, SCM_EOL);
1358 n->set_property ("articulations", arts);
1360 if (scm_is_number (check))
1362 int q = scm_to_int (check);
1363 n->set_property ("absolute-octave", scm_from_int (q-1));
1366 $$ = n->unprotect ();
1368 | DRUM_PITCH post_events {
1369 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1370 n->set_property ("duration", $2);
1371 n->set_property ("drum-type", $1);
1373 if (scm_is_pair ($2)) {
1374 SCM arts = scm_reverse_x ($2, SCM_EOL);
1375 n->set_property ("articulations", arts);
1377 $$ = n->unprotect ();
1379 | music_function_chord_body {
1380 $$ = run_music_function (PARSER, $1);
1384 music_function_identifier_musicless_prefix: MUSIC_FUNCTION {
1385 SCM sig = scm_object_property (yylval.scm, ly_symbol2scm ("music-function-signature"));
1386 if (scm_is_pair (sig) && to_boolean (scm_memq (ly_music_p_proc, scm_cdr (scm_reverse (sig)))))
1388 PARSER->parser_error (@$, "Music function applied to event may not have a Music argument, except as the last argument.");
1393 music_function_chord_body:
1394 /* We could allow chord functions to have multiple music arguments,
1395 but it's more consistent with music_function_event if we
1396 prohibit it here too */
1397 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic chord_body_element {
1398 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1400 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1401 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1405 music_function_event:
1406 /* Post-events can only have the last argument as music, without this
1407 restriction we get a shift/reduce conflict from e.g.
1408 c8-\partcombine c8 -. */
1409 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic post_event {
1410 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1412 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1413 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1421 | SKIP duration_length {
1422 $$ = MAKE_SYNTAX ("skip-music", @$, $2);
1425 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1426 m->set_property ("span-direction", scm_from_int (START));
1427 $$ = m->unprotect();
1430 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1431 m->set_property ("span-direction", scm_from_int (STOP));
1432 $$ = m->unprotect ();
1435 $$ = MAKE_SYNTAX ("voice-separator", @$, SCM_UNDEFINED);
1438 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1440 Music *m = unsmob_music (pipe);
1445 $$ = m->unprotect ();
1448 $$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
1451 | PARTIAL duration_length {
1452 Moment m = - unsmob_duration ($2)->get_length ();
1453 $$ = MAKE_SYNTAX ("property-operation", @$, SCM_BOOL_F, ly_symbol2scm ("Timing"), ly_symbol2scm ("PropertySet"), ly_symbol2scm ("measurePosition"), m.smobbed_copy ());
1454 $$ = MAKE_SYNTAX ("context-specification", @$, ly_symbol2scm ("Score"), SCM_BOOL_F, $$, SCM_EOL, SCM_BOOL_F);
1458 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1460 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1463 SCM proc = ly_lily_module_constant ("make-mark-set");
1465 $$ = scm_call_1 (proc, $2);
1471 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
1474 Music *m = MY_MAKE_MUSIC ("MarkEvent", @$);
1475 $$ = m->unprotect ();
1481 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1482 $$ = key->unprotect ();
1484 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1486 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1487 if (scm_ilength ($3) > 0)
1489 key->set_property ("pitch-alist", $3);
1490 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1491 key->transpose (* unsmob_pitch ($2));
1493 PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1496 $$ = key->unprotect ();
1505 | post_events post_event {
1506 unsmob_music ($2)->set_spot (@2);
1507 $$ = scm_cons ($2, $$);
1512 direction_less_event {
1515 | '-' music_function_event {
1516 $$ = run_music_function (PARSER, $2);
1519 if (!PARSER->lexer_->is_lyric_state ())
1520 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1521 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
1524 if (!PARSER->lexer_->is_lyric_state ())
1525 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1526 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
1528 | script_dir direction_reqd_event {
1531 Music *m = unsmob_music ($2);
1532 m->set_property ("direction", scm_from_int ($1));
1536 | script_dir direction_less_event {
1539 Music *m = unsmob_music ($2);
1540 m->set_property ("direction", scm_from_int ($1));
1544 | string_number_event
1547 string_number_event:
1549 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
1550 s->set_property ("string-number", scm_from_int ($1));
1551 $$ = s->unprotect ();
1555 direction_less_char:
1557 $$ = ly_symbol2scm ("bracketOpenSymbol");
1560 $$ = ly_symbol2scm ("bracketCloseSymbol");
1563 $$ = ly_symbol2scm ("tildeSymbol");
1566 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1569 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1572 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1575 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1578 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1581 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1584 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1588 direction_less_event:
1589 direction_less_char {
1590 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
1592 if (unsmob_music (predefd))
1594 m = unsmob_music (predefd)->clone ();
1599 m = MY_MAKE_MUSIC ("Music", @$);
1601 $$ = m->unprotect ();
1603 | EVENT_IDENTIFIER {
1607 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
1608 a->set_property ("tremolo-type", scm_from_int ($1));
1609 $$ = a->unprotect ();
1613 direction_reqd_event:
1617 | script_abbreviation {
1618 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1619 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
1620 if (scm_is_string (s))
1621 a->set_property ("articulation-type", s);
1622 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
1623 $$ = a->unprotect ();
1628 /**/ { $$ = SCM_EOL; }
1629 | '=' { $$ = scm_from_int (0); }
1630 | '=' sub_quotes { $$ = scm_from_int (-$2); }
1631 | '=' sup_quotes { $$ = scm_from_int ($2); }
1656 | NOTENAME_PITCH sup_quotes {
1657 Pitch p = *unsmob_pitch ($1);
1658 p = p.transposed (Pitch ($2,0,0));
1659 $$ = p.smobbed_copy ();
1661 | NOTENAME_PITCH sub_quotes {
1662 Pitch p =* unsmob_pitch ($1);
1663 p = p.transposed (Pitch (-$2,0,0));
1664 $$ = p.smobbed_copy ();
1676 | TONICNAME_PITCH sup_quotes {
1677 Pitch p = *unsmob_pitch ($1);
1678 p = p.transposed (Pitch ($2,0,0));
1679 $$ = p.smobbed_copy ();
1681 | TONICNAME_PITCH sub_quotes {
1682 Pitch p = *unsmob_pitch ($1);
1684 p = p.transposed (Pitch (-$2,0,0));
1685 $$ = p.smobbed_copy ();
1695 pitch_also_in_chords:
1702 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1703 t->set_property ("text", $1);
1704 $$ = t->unprotect ();
1707 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1708 t->set_property ("text",
1709 make_simple_markup ($1));
1710 $$ = t->unprotect ();
1713 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
1714 t->set_property ("digit", scm_from_int ($1));
1715 $$ = t->unprotect ();
1719 script_abbreviation:
1721 $$ = scm_from_locale_string ("Hat");
1724 $$ = scm_from_locale_string ("Plus");
1727 $$ = scm_from_locale_string ("Dash");
1730 $$ = scm_from_locale_string ("Bar");
1733 $$ = scm_from_locale_string ("Larger");
1736 $$ = scm_from_locale_string ("Dot");
1739 $$ = scm_from_locale_string ("Underscore");
1746 | '-' { $$ = CENTER; }
1757 multiplied_duration {
1762 optional_notemode_duration:
1764 Duration dd = PARSER->default_duration_;
1765 $$ = dd.smobbed_copy ();
1767 | multiplied_duration {
1769 PARSER->default_duration_ = *unsmob_duration ($$);
1774 bare_unsigned dots {
1776 if (!is_duration ($1))
1777 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
1781 $$ = Duration (len, $2).smobbed_copy ();
1783 | DURATION_IDENTIFIER dots {
1784 Duration *d = unsmob_duration ($1);
1785 Duration k (d->duration_log (), d->dot_count () + $2);
1791 multiplied_duration:
1795 | multiplied_duration '*' bare_unsigned {
1796 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1798 | multiplied_duration '*' FRACTION {
1799 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1801 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1806 FRACTION { $$ = $1; }
1807 | UNSIGNED '/' UNSIGNED {
1808 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
1825 | ':' bare_unsigned {
1826 if (!is_duration ($2))
1827 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
1834 $$ = scm_from_int ($1);
1837 $$ = scm_from_int ($1);
1839 | STRING { $$ = $1; }
1840 | full_markup { $$ = $1; }
1843 figured_bass_alteration:
1844 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
1845 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
1846 | '!' { $$ = scm_from_int (0); }
1851 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
1852 $$ = bfr->unprotect ();
1855 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
1856 $$ = bfr->self_scm ();
1858 if (scm_is_number ($1))
1859 bfr->set_property ("figure", $1);
1860 else if (Text_interface::is_markup ($1))
1861 bfr->set_property ("text", $1);
1867 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
1869 | bass_figure figured_bass_alteration {
1870 Music *m = unsmob_music ($1);
1871 if (scm_to_double ($2)) {
1872 SCM salter = m->get_property ("alteration");
1873 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
1874 m->set_property ("alteration",
1875 scm_sum (alter, $2));
1877 m->set_property ("alteration", scm_from_int (0));
1880 | bass_figure figured_bass_modification {
1881 Music *m = unsmob_music ($1);
1882 if ($2 == ly_symbol2scm ("plus"))
1884 m->set_property ("augmented", SCM_BOOL_T);
1886 else if ($2 == ly_symbol2scm ("slash"))
1888 m->set_property ("diminished", SCM_BOOL_T);
1890 else if ($2 == ly_symbol2scm ("exclamation"))
1892 m->set_property ("no-continuation", SCM_BOOL_T);
1898 figured_bass_modification:
1900 $$ = ly_symbol2scm ("plus");
1903 $$ = ly_symbol2scm ("exclamation");
1906 $$ = ly_symbol2scm ("slash");
1916 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
1924 | figure_list br_bass_figure {
1925 $$ = scm_cons ($2, $1);
1930 FIGURE_OPEN figure_list FIGURE_CLOSE {
1931 $$ = scm_reverse_x ($2, SCM_EOL);
1942 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
1943 if (!PARSER->lexer_->is_note_state ())
1944 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
1948 n = MY_MAKE_MUSIC ("RestEvent", @$);
1950 n = MY_MAKE_MUSIC ("NoteEvent", @$);
1952 n->set_property ("pitch", $1);
1953 n->set_property ("duration", $5);
1955 if (scm_is_number ($4))
1957 int q = scm_to_int ($4);
1958 n->set_property ("absolute-octave", scm_from_int (q-1));
1962 n->set_property ("cautionary", SCM_BOOL_T);
1963 if ($2 % 2 || $3 % 2)
1964 n->set_property ("force-accidental", SCM_BOOL_T);
1966 $$ = n->unprotect ();
1968 | DRUM_PITCH optional_notemode_duration {
1969 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1970 n->set_property ("duration", $2);
1971 n->set_property ("drum-type", $1);
1973 $$ = n->unprotect ();
1975 | RESTNAME optional_notemode_duration {
1977 if (ly_scm2string ($1) == "s") {
1979 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
1982 ev = MY_MAKE_MUSIC ("RestEvent", @$);
1985 ev->set_property ("duration", $2);
1986 $$ = ev->unprotect ();
1988 | lyric_element optional_notemode_duration {
1989 if (!PARSER->lexer_->is_lyric_state ())
1990 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1992 Music *levent = MY_MAKE_MUSIC ("LyricEvent", @$);
1993 levent->set_property ("text", $1);
1994 levent->set_property ("duration",$2);
1995 $$= levent->unprotect ();
1999 simple_chord_elements:
2001 $$ = scm_list_1 ($1);
2004 if (!PARSER->lexer_->is_chord_state ())
2005 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2008 | figure_spec optional_notemode_duration {
2009 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2011 unsmob_music (scm_car (s))->set_property ("duration", $2);
2027 steno_tonic_pitch optional_notemode_duration {
2028 $$ = make_chord_elements ($1, $2, SCM_EOL);
2030 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2031 SCM its = scm_reverse_x ($4, SCM_EOL);
2032 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2040 | chord_items chord_item {
2041 $$ = scm_cons ($2, $$);
2047 $$ = ly_symbol2scm ("chord-colon");
2050 $$ = ly_symbol2scm ("chord-caret");
2052 | CHORD_SLASH steno_tonic_pitch {
2053 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2055 | CHORD_BASS steno_tonic_pitch {
2056 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2065 $$ = scm_reverse_x ($1, SCM_EOL);
2073 step_number { $$ = scm_cons ($1, SCM_EOL); }
2074 | step_numbers '.' step_number {
2075 $$ = scm_cons ($3, $$);
2081 $$ = make_chord_step ($1, 0);
2083 | bare_unsigned '+' {
2084 $$ = make_chord_step ($1, SHARP_ALTERATION);
2086 | bare_unsigned CHORD_MINUS {
2087 $$ = make_chord_step ($1, FLAT_ALTERATION);
2094 TODO: should deprecate in favor of Scheme?
2098 number_expression '+' number_term {
2099 $$ = scm_sum ($1, $3);
2101 | number_expression '-' number_term {
2102 $$ = scm_difference ($1, $3);
2111 | number_factor '*' number_factor {
2112 $$ = scm_product ($1, $3);
2114 | number_factor '/' number_factor {
2115 $$ = scm_divide ($1, $3);
2120 '-' number_factor { /* %prec UNARY_MINUS */
2121 $$ = scm_difference ($2, SCM_UNDEFINED);
2129 $$ = scm_from_int ($1);
2134 | NUMBER_IDENTIFIER {
2137 | REAL NUMBER_IDENTIFIER {
2138 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2140 | UNSIGNED NUMBER_IDENTIFIER {
2141 $$ = scm_from_double ($1 *scm_to_double ($2));
2156 bare_unsigned { $$ = scm_from_int ($1); }
2157 | NUMBER_IDENTIFIER {
2165 | exclamations '!' { $$ ++; }
2170 | questions '?' { $$ ++; }
2174 This should be done more dynamically if possible.
2178 LYRIC_MARKUP_IDENTIFIER {
2182 { PARSER->lexer_->push_markup_state (); }
2185 PARSER->lexer_->pop_state ();
2194 { PARSER->lexer_->push_markup_state (); }
2197 PARSER->lexer_->pop_state ();
2203 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2205 | markup_head_1_list simple_markup {
2206 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2214 markup_composed_list {
2217 | markup_braced_list {
2222 markup_composed_list:
2223 markup_head_1_list markup_braced_list {
2224 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2230 '{' markup_braced_list_body '}' {
2231 $$ = scm_reverse_x ($2, SCM_EOL);
2235 markup_braced_list_body:
2236 /* empty */ { $$ = SCM_EOL; }
2237 | markup_braced_list_body markup {
2238 $$ = scm_cons ($2, $1);
2240 | markup_braced_list_body markup_list {
2241 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2246 MARKUP_HEAD_MARKUP0 {
2247 $$ = scm_list_1 ($1);
2249 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2250 $$ = scm_list_2 ($1, $2);
2252 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2253 $$ = scm_list_3 ($1, $2, $3);
2258 markup_head_1_item {
2259 $$ = scm_list_1 ($1);
2261 | markup_head_1_list markup_head_1_item {
2262 $$ = scm_cons ($2, $1);
2268 $$ = make_simple_markup ($1);
2270 | MARKUP_IDENTIFIER {
2273 | LYRIC_MARKUP_IDENTIFIER {
2276 | STRING_IDENTIFIER {
2280 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2281 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2282 } '{' score_body '}' {
2284 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2286 PARSER->lexer_->pop_state ();
2288 | MARKUP_HEAD_SCM0 embedded_scm {
2289 $$ = scm_list_2 ($1, $2);
2291 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2292 $$ = scm_list_4 ($1, $2, $3, $4);
2294 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2295 $$ = scm_list_3 ($1, $2, $3);
2297 | MARKUP_HEAD_SCM0_MARKUP1_MARKUP2 embedded_scm markup markup {
2298 $$ = scm_list_4 ($1, $2, $3, $4);
2300 | MARKUP_HEAD_EMPTY {
2301 $$ = scm_list_1 ($1);
2303 | MARKUP_HEAD_LIST0 markup_list {
2304 $$ = scm_list_2 ($1,$2);
2306 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2307 $$ = scm_list_3 ($1, $2, $3);
2312 markup_head_1_list simple_markup {
2313 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2314 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2324 Lily_parser::set_yydebug (bool x)
2330 Lily_parser::do_yyparse ()
2332 yyparse ((void*)this);
2341 It is a little strange to have this function in this file, but
2342 otherwise, we have to import music classes into the lexer.
2346 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2348 if (scm_is_string (sid)) {
2350 return STRING_IDENTIFIER;
2351 } else if (unsmob_book (sid)) {
2352 Book *book = unsmob_book (sid)->clone ();
2353 *destination = book->self_scm ();
2356 return BOOK_IDENTIFIER;
2357 } else if (scm_is_number (sid)) {
2359 return NUMBER_IDENTIFIER;
2360 } else if (unsmob_context_def (sid)) {
2361 Context_def *def= unsmob_context_def (sid)->clone ();
2363 *destination = def->self_scm ();
2366 return CONTEXT_DEF_IDENTIFIER;
2367 } else if (unsmob_score (sid)) {
2368 Score *score = new Score (*unsmob_score (sid));
2369 *destination = score->self_scm ();
2371 score->unprotect ();
2372 return SCORE_IDENTIFIER;
2373 } else if (Music *mus = unsmob_music (sid)) {
2374 mus = mus->clone ();
2375 *destination = mus->self_scm ();
2376 unsmob_music (*destination)->
2377 set_property ("origin", make_input (last_input_));
2379 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2383 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2384 } else if (unsmob_duration (sid)) {
2385 *destination = unsmob_duration (sid)->smobbed_copy ();
2386 return DURATION_IDENTIFIER;
2387 } else if (unsmob_output_def (sid)) {
2388 Output_def *p = unsmob_output_def (sid);
2391 *destination = p->self_scm ();
2393 return OUTPUT_DEF_IDENTIFIER;
2394 } else if (Text_interface::is_markup (sid)) {
2396 if (is_lyric_state ())
2397 return LYRIC_MARKUP_IDENTIFIER;
2398 return MARKUP_IDENTIFIER;
2405 get_next_unique_context_id ()
2407 return scm_from_locale_string ("$uniqueContextId");
2412 get_next_unique_lyrics_context_id ()
2414 static int new_context_count;
2416 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2417 return scm_from_locale_string (s);
2422 run_music_function (Lily_parser *parser, SCM expr)
2424 SCM func = scm_car (expr);
2425 Input *loc = unsmob_input (scm_cadr (expr));
2426 SCM args = scm_cddr (expr);
2427 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2429 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2431 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2433 parser->error_level_ = 1;
2434 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (*loc)));
2437 SCM syntax_args = scm_list_4 (parser->self_scm (), make_input (*loc), func, args);
2438 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
2442 is_regular_identifier (SCM id)
2444 string str = ly_scm2string (id);
2445 char const *s = str.c_str ();
2454 v = v && isalnum (*s);
2461 make_music_with_input (SCM name, Input where)
2463 Music *m = make_music_by_name (name);
2464 m->set_spot (where);
2469 get_first_context_id (SCM type, Music *m)
2471 SCM id = m->get_property ("context-id");
2472 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2473 && scm_is_string (m->get_property ("context-id"))
2474 && scm_c_string_length (id) > 0)
2482 make_simple_markup (SCM a)
2490 return t && t == 1 << intlog2 (t);
2494 set_music_properties (Music *p, SCM a)
2496 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2497 p->set_property (scm_caar (k), scm_cdar (k));
2502 make_chord_step (int step, Rational alter)
2505 alter += FLAT_ALTERATION;
2509 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2510 return m.smobbed_copy ();
2515 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
2517 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
2518 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
2522 /* Todo: actually also use apply iso. call too ... */
2524 ly_input_procedure_p (SCM x)
2526 return ly_is_procedure (x)
2527 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2531 make_music_relative (Pitch start, SCM music, Input loc)
2533 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic", loc);
2534 relative->set_property ("element", music);
2536 Music *m = unsmob_music (music);
2537 Pitch last = m->to_relative_octave (start);
2538 if (lily_1_8_relative)
2539 m->set_property ("last-pitch", last.smobbed_copy ());
2540 return relative->unprotect ();
2544 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2546 Lily_parser *pars = (Lily_parser*) v;
2547 Lily_lexer *lex = pars->lexer_;
2549 lex->lexval = (void*) s;
2551 lex->prepare_for_next_token ();
2552 return lex->yylex ();