2 parser.yy -- Bison/C++ parser for LilyPond
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
12 #define YYERROR_VERBOSE 1
13 #define YYPARSE_PARAM my_lily_parser
14 #define YYLEX_PARAM my_lily_parser
15 #define PARSER ((Lily_parser *) my_lily_parser)
17 #define yyerror PARSER->parser_error
19 /* We use custom location type: Input objects */
21 #define YYLLOC_DEFAULT(Current,Rhs,N) \
22 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
27 /* We use SCMs to do strings, because it saves us the trouble of
28 deleting them. Let's hope that a stack overflow doesnt trigger a move
29 of the parse stack onto the heap. */
37 /* One shift/reduce problem
40 \repeat .. \alternative
42 \repeat { \repeat .. \alternative }
46 \repeat { \repeat } \alternative
55 %{ // -*-Fundamental-*-
60 * The rules for who is protecting what are very shady. Uniformise
63 * There are too many lexical modes?
74 #include "context-def.hh"
75 #include "dimensions.hh"
76 #include "file-path.hh"
77 #include "input-smob.hh"
79 #include "international.hh"
80 #include "lily-guile.hh"
81 #include "lily-lexer.hh"
82 #include "lily-parser.hh"
83 #include "lilypond-input-version.hh"
88 #include "output-def.hh"
89 #include "paper-book.hh"
90 #include "program-option.hh"
91 #include "scm-hash.hh"
93 #include "text-interface.hh"
101 Output_def *outputdef;
111 #define MY_MAKE_MUSIC(x) make_music_by_name (ly_symbol2scm (x))
114 - Don't use lily module, create a new module instead.
115 - delay application of the function
117 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
118 scm_apply_0 (proc, args)
119 /* Syntactic Sugar. */
120 #define MAKE_SYNTAX(name, location, ...) \
121 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location), __VA_ARGS__, SCM_UNDEFINED));
123 SCM get_next_unique_context_id ();
124 SCM get_next_unique_lyrics_context_id ();
131 #define _(x) gettext (x)
136 SCM make_music_relative (Pitch start, SCM music);
137 SCM run_music_function (Lily_parser *, SCM expr);
138 SCM get_first_context_id (SCM type, Music *m);
139 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
140 SCM make_chord_step (int step, int alter);
141 SCM make_simple_markup (SCM a);
142 bool is_duration (int t);
143 bool is_regular_identifier (SCM id);
144 bool ly_input_procedure_p (SCM x);
145 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
146 void set_music_properties (Music *p, SCM a);
150 /* The third option is an alias that will be used to display the
151 syntax error. Bison CVS now correctly handles backslash escapes.
153 FIXME: Bison needs to translate some of these, eg, STRING.
157 /* Keyword tokens with plain escaped name. */
158 %token ACCEPTS "\\accepts"
159 %token ADDLYRICS "\\addlyrics"
160 %token ADDQUOTE "\\addquote"
161 %token ALIAS "\\alias"
162 %token ALTERNATIVE "\\alternative"
164 %token CHANGE "\\change"
165 %token CHORDMODE "\\chordmode"
166 %token CHORDS "\\chords"
167 %token CONSISTS "\\consists"
168 %token CONTEXT "\\context"
169 %token DEFAULT "\\default"
170 %token DEFAULTCHILD "\\defaultchild"
171 %token DENIES "\\denies"
172 %token DESCRIPTION "\\description"
173 %token DRUMMODE "\\drummode"
174 %token DRUMS "\\drums"
175 %token FIGUREMODE "\\figuremode"
176 %token FIGURES "\\figures"
177 %token GROBDESCRIPTIONS "\\grobdescriptions"
178 %token HEADER "\\header"
179 %token INVALID "\\invalid"
181 %token LAYOUT "\\layout"
182 %token LYRICMODE "\\lyricmode"
183 %token LYRICS "\\lyrics"
184 %token LYRICSTO "\\lyricsto"
186 %token MARKUP "\\markup"
189 %token NOTEMODE "\\notemode"
190 %token OBJECTID "\\objectid"
191 %token OCTAVE "\\octave"
193 %token OVERRIDE "\\override"
194 %token PAPER "\\paper"
195 %token PARTIAL "\\partial"
196 %token RELATIVE "\\relative"
197 %token REMOVE "\\remove"
198 %token REPEAT "\\repeat"
200 %token REVERT "\\revert"
201 %token SCORE "\\score"
202 %token SEQUENTIAL "\\sequential"
204 %token SIMULTANEOUS "\\simultaneous"
206 %token TEMPO "\\tempo"
207 %token TIMES "\\times"
208 %token TRANSPOSE "\\transpose"
209 %token TRANSPOSITION "\\transposition"
211 %token UNSET "\\unset"
214 /* Keyword token exceptions. */
215 %token TIME_T "\\time"
216 %token NEWCONTEXT "\\new"
219 /* Other string tokens. */
221 %token CHORD_BASS "/+"
222 %token CHORD_CARET "^"
223 %token CHORD_COLON ":"
224 %token CHORD_MINUS "-"
225 %token CHORD_SLASH "/"
226 %token DOUBLE_ANGLE_CLOSE ">>"
227 %token DOUBLE_ANGLE_OPEN "<<"
228 %token E_BACKSLASH "\\"
229 %token E_ANGLE_CLOSE "\\>"
230 %token E_CHAR "\\C[haracter]"
232 %token E_EXCLAMATION "\\!"
233 %token E_BRACKET_OPEN "\\["
235 %token E_BRACKET_CLOSE "\\]"
236 %token E_ANGLE_OPEN "\\<"
242 If we give names, Bison complains.
244 %token FIGURE_CLOSE /* "\\>" */
245 %token FIGURE_OPEN /* "\\<" */
246 %token FIGURE_SPACE "_"
249 %token CHORDMODIFIERS
251 %token MULTI_MEASURE_REST
256 %token <i> E_UNSIGNED
259 %token <scm> BOOK_IDENTIFIER
260 %token <scm> CHORDMODIFIER_PITCH
261 %token <scm> CHORD_MODIFIER
262 %token <scm> CONTEXT_DEF_IDENTIFIER
263 %token <scm> DRUM_PITCH
264 %token <scm> DURATION_IDENTIFIER
265 %token <scm> EVENT_IDENTIFIER
266 %token <scm> FRACTION
267 %token <scm> LYRICS_STRING
268 %token <scm> LYRIC_MARKUP_IDENTIFIER
269 %token <scm> MARKUP_HEAD_EMPTY
270 %token <scm> MARKUP_HEAD_LIST0
271 %token <scm> MARKUP_HEAD_MARKUP0
272 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
273 %token <scm> MARKUP_HEAD_SCM0
274 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
275 %token <scm> MARKUP_HEAD_SCM0_SCM1
276 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
277 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
278 %token <scm> MARKUP_IDENTIFIER
279 %token <scm> MUSIC_FUNCTION
280 %token <scm> MUSIC_FUNCTION_MARKUP
281 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP
282 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC
283 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC
284 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC
285 %token <scm> MUSIC_FUNCTION_MUSIC
286 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC
287 %token <scm> MUSIC_FUNCTION_SCM
288 %token <scm> MUSIC_FUNCTION_SCM_MUSIC
289 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC
290 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC_MUSIC
291 %token <scm> MUSIC_FUNCTION_SCM_SCM
292 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC
293 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM
294 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC
295 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC
296 %token <scm> MUSIC_IDENTIFIER
297 %token <scm> NOTENAME_PITCH
298 %token <scm> NUMBER_IDENTIFIER
299 %token <scm> OUTPUT_DEF_IDENTIFIER
301 %token <scm> RESTNAME
302 %token <scm> SCM_IDENTIFIER
304 %token <scm> SCORE_IDENTIFIER
306 %token <scm> STRING_IDENTIFIER
307 %token <scm> TONICNAME_PITCH
310 %type <book> book_block
311 %type <book> book_body
313 %type <i> bare_unsigned
314 %type <i> figured_bass_alteration
316 %type <i> exclamations
317 %type <i> optional_rest
322 %type <i> tremolo_type
325 %type <scm> composite_music
326 %type <scm> grouped_music_list
328 %type <scm> prefix_composite_music
329 %type <scm> repeated_music
330 %type <scm> sequential_music
331 %type <scm> simple_music
332 %type <scm> simultaneous_music
333 %type <scm> chord_body
334 %type <scm> chord_body_element
335 %type <scm> command_element
336 %type <scm> command_event
337 %type <scm> context_change
338 %type <scm> direction_less_event
339 %type <scm> direction_reqd_event
340 %type <scm> event_chord
341 %type <scm> gen_text_def
342 %type <scm> music_property_def
343 %type <scm> note_chord_element
344 %type <scm> post_event
345 %type <scm> re_rhythmed_music
346 %type <scm> relative_music
347 %type <scm> simple_element
348 %type <scm> simple_music_property_def
349 %type <scm> string_number_event
350 %type <scm> tempo_event
351 %type <scm> toplevel_music
353 %type <outputdef> output_def_body
354 %type <outputdef> output_def_head
355 %type <outputdef> output_def_head_with_mode_switch
356 %type <outputdef> output_def
357 %type <outputdef> paper_block
359 %type <scm> alternative_music
360 %type <scm> generic_prefix_music_scm
361 %type <scm> music_list
362 %type <scm> absolute_pitch
363 %type <scm> assignment_id
364 %type <scm> bare_number
365 %type <scm> music_function_event
366 %type <scm> music_function_chord_body
367 %type <scm> music_function_musicless_prefix
368 %type <scm> bass_figure
369 %type <scm> figured_bass_modification
370 %type <scm> br_bass_figure
371 %type <scm> bass_number
372 %type <scm> chord_body_elements
373 %type <scm> chord_item
374 %type <scm> chord_items
375 %type <scm> chord_separator
376 %type <scm> context_def_mod
377 %type <scm> context_def_spec_block
378 %type <scm> context_def_spec_body
379 %type <scm> context_mod
380 %type <scm> context_mod_list
381 %type <scm> context_prop_spec
382 %type <scm> direction_less_char
383 %type <scm> duration_length
384 %type <scm> embedded_scm
385 %type <scm> figure_list
386 %type <scm> figure_spec
388 %type <scm> full_markup
389 %type <scm> identifier_init
390 %type <scm> lilypond_header
391 %type <scm> lilypond_header_body
392 %type <scm> lyric_element
393 %type <scm> lyric_markup
395 %type <scm> markup_braced_list
396 %type <scm> markup_braced_list_body
397 %type <scm> markup_composed_list
398 %type <scm> markup_head_1_item
399 %type <scm> markup_head_1_list
400 %type <scm> markup_list
401 %type <scm> markup_top
402 %type <scm> mode_changing_head
403 %type <scm> mode_changing_head_with_context
404 %type <scm> multiplied_duration
405 %type <scm> new_chord
406 %type <scm> new_lyrics
407 %type <scm> number_expression
408 %type <scm> number_factor
409 %type <scm> number_term
410 %type <scm> object_id_setting
411 %type <scm> octave_check
412 %type <scm> optional_context_mod
413 %type <scm> optional_id
414 %type <scm> optional_notemode_duration
416 %type <scm> pitch_also_in_chords
417 %type <scm> post_events
418 %type <scm> property_operation
420 %type <scm> script_abbreviation
421 %type <scm> simple_chord_elements
422 %type <scm> simple_markup
423 %type <scm> simple_string
424 %type <scm> steno_duration
425 %type <scm> steno_pitch
426 %type <scm> steno_tonic_pitch
427 %type <scm> step_number
428 %type <scm> step_numbers
430 %type <scm> function_scm_argument
432 %type <score> score_block
433 %type <score> score_body
438 /* We don't assign precedence to / and *, because we might need varied
439 prec levels in different prods */
445 lilypond: /* empty */
446 | lilypond toplevel_expression {
448 | lilypond assignment {
451 PARSER->error_level_ = 1;
454 PARSER->error_level_ = 1;
460 OBJECTID STRING { $$ = $2; }
465 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
469 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
470 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
476 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
477 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
481 Music *music = unsmob_music ($1);
482 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
483 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
486 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
487 scm_call_2 (proc, PARSER->self_scm (), $1);
491 Output_def * od = $1;
493 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
494 id = ly_symbol2scm ("$defaultpaper");
495 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
496 id = ly_symbol2scm ("$defaultmidi");
497 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
498 id = ly_symbol2scm ("$defaultlayout");
500 PARSER->lexer_->set_identifier (id, od->self_scm ());
516 lilypond_header_body:
518 $$ = get_header(PARSER);
519 PARSER->lexer_->add_scope ($$);
521 | lilypond_header_body assignment {
527 HEADER '{' lilypond_header_body '}' {
528 $$ = PARSER->lexer_->remove_scope ();
537 | LYRICS_STRING { $$ = $1; }
541 assignment_id '=' identifier_init {
542 if (! is_regular_identifier ($1))
545 /* no longer valid with dashes in \paper{} block. */
546 @1.warning (_ ("identifier should have alphabetic characters only"));
551 PARSER->lexer_->set_identifier ($1, $3);
554 TODO: devise standard for protection in parser.
556 The parser stack lives on the C-stack, which means that
557 all objects can be unprotected as soon as they're here.
567 $$ = $1->self_scm ();
571 $$ = $1->self_scm ();
575 $$ = $1->self_scm ();
578 | context_def_spec_block {
587 | number_expression {
600 $$ = scm_from_int ($1);
604 context_def_spec_block:
605 CONTEXT '{' context_def_spec_body '}'
611 context_def_spec_body:
613 $$ = Context_def::make_scm ();
614 unsmob_context_def ($$)->set_spot (@$);
616 | CONTEXT_DEF_IDENTIFIER {
618 unsmob_context_def ($$)->set_spot (@$);
620 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
621 Context_def*td = unsmob_context_def ($$);
623 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
624 SCM tag = scm_caar (p);
626 /* TODO: should make new tag "grob-definition" ? */
627 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
628 tag, scm_cons (scm_cdar (p), SCM_EOL)));
631 | context_def_spec_body context_mod {
632 unsmob_context_def ($$)->add_context_mod ($2);
639 BOOK '{' book_body '}' {
645 * Use 'handlers' like for toplevel-* stuff?
646 * grok \layout and \midi? */
651 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
652 $$->paper_->unprotect ();
653 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
656 $$ = unsmob_book ($1);
659 | book_body paper_block {
663 | book_body score_block {
664 SCM s = $2->self_scm ();
668 | book_body full_markup {
671 | book_body lilypond_header {
676 $$->scores_ = SCM_EOL;
678 | book_body object_id_setting {
679 $$->user_key_ = ly_scm2string ($2);
684 SCORE '{' score_body '}' {
692 SCM scorify = ly_lily_module_constant ("scorify-music");
693 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
695 // pass ownernship to C++ again.
696 $$ = unsmob_score (score);
701 $$ = unsmob_score ($1);
704 | score_body object_id_setting {
705 $$->user_key_ = ly_scm2string ($2);
707 | score_body lilypond_header {
710 | score_body output_def {
711 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
713 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
718 $$->add_output_def ($2);
723 $$->error_found_ = true;
735 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
737 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 {
786 Output_def *o = unsmob_output_def ($3);
787 o->input_origin_.set_spot (@$);
789 PARSER->lexer_->remove_scope ();
790 PARSER->lexer_->add_scope (o->scope_);
792 | output_def_body assignment {
795 | output_def_body context_def_spec_block {
796 assign_context_def ($$, $2);
798 | output_def_body tempo_event {
800 junk this ? there already is tempo stuff in
803 int m = scm_to_int (unsmob_music($2)->get_property ("metronome-count"));
804 Duration *d = unsmob_duration (unsmob_music($2)->get_property ("tempo-unit"));
805 set_tempo ($$, d->get_length (), m);
807 | output_def_body error {
813 TEMPO steno_duration '=' bare_unsigned {
814 Music *m = MY_MAKE_MUSIC ("MetronomeChangeEvent");
815 m->set_property ("tempo-unit", $2);
816 m->set_property ("metronome-count", scm_from_int ( $4));
817 $$ = m->unprotect ();
822 The representation of a list is the
826 to have efficient append. */
830 $$ = scm_cons (SCM_EOL, SCM_EOL);
834 SCM c = scm_cons ($2, SCM_EOL);
836 if (scm_is_pair (scm_cdr (s)))
837 scm_set_cdr_x (scm_cdr (s), c); /* append */
839 scm_set_car_x (s, c); /* set first cons */
840 scm_set_cdr_x (s, c); /* remember last cell */
842 | music_list embedded_scm {
846 Music *m = MY_MAKE_MUSIC("Music");
848 m->set_property ("error-found", SCM_BOOL_T);
850 SCM c = scm_cons (m->self_scm (), SCM_EOL);
851 m->unprotect (); /* UGH */
853 if (scm_is_pair (scm_cdr (s)))
854 scm_set_cdr_x (scm_cdr (s), c); /* append */
856 scm_set_car_x (s, c); /* set first cons */
857 scm_set_cdr_x (s, c); /* remember last cell */
870 | ALTERNATIVE '{' music_list '}' {
877 REPEAT simple_string bare_unsigned music alternative_music
879 $$ = MAKE_SYNTAX ("repeat", @$, $2, scm_int2num ($3), $4, $5);
884 SEQUENTIAL '{' music_list '}' {
885 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($3));
887 | '{' music_list '}' {
888 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($2));
893 SIMULTANEOUS '{' music_list '}'{
894 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($3));
896 | simul_open music_list simul_close {
897 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($2));
908 optional_context_mod:
909 /**/ { $$ = SCM_EOL; }
910 | WITH { PARSER->lexer_->push_initial_state (); }
911 '{' context_mod_list '}'
913 PARSER->lexer_->pop_state ();
919 /* */ { $$ = SCM_EOL; }
920 | context_mod_list context_mod {
921 $$ = scm_cons ($2, $1);
926 prefix_composite_music { $$ = $1; }
927 | grouped_music_list { $$ = $1; }
931 simultaneous_music { $$ = $1; }
932 | sequential_music { $$ = $1; }
935 function_scm_argument:
941 TODO: use code generation for this
943 generic_prefix_music_scm:
945 $$ = scm_list_2 ($1, make_input (@$));
947 | MUSIC_FUNCTION_SCM function_scm_argument {
948 $$ = scm_list_3 ($1, make_input (@$), $2);
950 | MUSIC_FUNCTION_MARKUP full_markup {
951 $$ = scm_list_3 ($1, make_input (@$), $2);
953 | music_function_musicless_prefix music {
954 $$ = ly_append2 ($1, scm_list_1 ($2));
956 | MUSIC_FUNCTION_SCM_SCM function_scm_argument function_scm_argument {
957 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
959 | MUSIC_FUNCTION_SCM_SCM_SCM function_scm_argument function_scm_argument function_scm_argument {
960 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
962 | MUSIC_FUNCTION_MARKUP_MUSIC full_markup music {
963 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
965 | MUSIC_FUNCTION_MARKUP_MARKUP full_markup full_markup {
966 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
968 | MUSIC_FUNCTION_MUSIC_MUSIC music music {
969 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
971 | MUSIC_FUNCTION_SCM_MUSIC_MUSIC function_scm_argument music music {
972 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
974 | MUSIC_FUNCTION_SCM_SCM_MUSIC_MUSIC function_scm_argument function_scm_argument music music {
975 $$ = scm_list_n ($1, make_input (@$), $2, $3, $4, $5, SCM_UNDEFINED);
977 | MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC full_markup music music {
978 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
983 /**/ { $$ = SCM_EOL; }
984 | '=' simple_string {
990 prefix_composite_music:
991 generic_prefix_music_scm {
992 $$ = run_music_function (PARSER, $1);
994 | CONTEXT simple_string optional_id optional_context_mod music {
995 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_F);
997 | NEWCONTEXT simple_string optional_id optional_context_mod music {
998 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_T);
1001 | TIMES fraction music {
1002 $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3);
1004 | repeated_music { $$ = $1; }
1005 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords music {
1006 Pitch from = *unsmob_pitch ($2);
1007 Pitch to = *unsmob_pitch ($3);
1008 SCM pitch = pitch_interval (from, to).smobbed_copy ();
1009 $$ = MAKE_SYNTAX ("transpose-music", @$, pitch, $4);
1011 | mode_changing_head grouped_music_list {
1012 if ($1 == ly_symbol2scm ("chords"))
1014 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1020 PARSER->lexer_->pop_state ();
1022 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1023 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, $3, $2, SCM_BOOL_T);
1024 if ($1 == ly_symbol2scm ("ChordNames"))
1026 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1028 PARSER->lexer_->pop_state ();
1030 | relative_music { $$ = $1; }
1031 | re_rhythmed_music { $$ = $1; }
1036 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1037 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1039 $$ = ly_symbol2scm ("notes");
1043 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1044 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1046 $$ = ly_symbol2scm ("drums");
1049 PARSER->lexer_->push_figuredbass_state ();
1051 $$ = ly_symbol2scm ("figures");
1054 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1055 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1056 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1057 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1058 $$ = ly_symbol2scm ("chords");
1062 { PARSER->lexer_->push_lyric_state ();
1063 $$ = ly_symbol2scm ("lyrics");
1067 mode_changing_head_with_context:
1069 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1070 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1072 $$ = ly_symbol2scm ("DrumStaff");
1075 PARSER->lexer_->push_figuredbass_state ();
1077 $$ = ly_symbol2scm ("FiguredBass");
1080 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1081 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1082 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1083 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1084 $$ = ly_symbol2scm ("ChordNames");
1087 { PARSER->lexer_->push_lyric_state ();
1088 $$ = ly_symbol2scm ("Lyrics");
1094 RELATIVE absolute_pitch music {
1095 Pitch start = *unsmob_pitch ($2);
1096 $$ = make_music_relative (start, $3);
1098 | RELATIVE composite_music {
1099 Pitch middle_c (0, 0, 0);
1100 $$ = make_music_relative (middle_c, $2);
1105 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1107 grouped_music_list {
1108 /* Can also use music at the expensive of two S/Rs similar to
1109 \repeat \alternative */
1110 PARSER->lexer_->pop_state ();
1112 $$ = scm_cons ($3, SCM_EOL);
1114 | new_lyrics ADDLYRICS {
1115 PARSER->lexer_->push_lyric_state ();
1116 } grouped_music_list {
1117 PARSER->lexer_->pop_state ();
1118 $$ = scm_cons ($4, $1);
1123 grouped_music_list new_lyrics {
1124 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1126 | LYRICSTO simple_string {
1127 PARSER->lexer_->push_lyric_state ();
1129 PARSER->lexer_->pop_state ();
1130 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1135 CHANGE STRING '=' STRING {
1136 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1142 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1143 scm_string_to_symbol ($1), $3);
1145 | UNSET simple_string {
1146 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1147 scm_string_to_symbol ($2));
1149 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1150 $$ = scm_list_4 (ly_symbol2scm ("push"),
1151 scm_string_to_symbol ($2), $5, $3);
1153 | OVERRIDE simple_string embedded_scm embedded_scm '=' embedded_scm {
1154 $$ = scm_list_5 (ly_symbol2scm ("push"),
1155 scm_string_to_symbol ($2), $6, $4, $3);
1157 | REVERT simple_string embedded_scm {
1158 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1159 scm_string_to_symbol ($2), $3);
1164 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1165 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1167 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1168 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1169 | DENIES { $$ = ly_symbol2scm ("denies"); }
1171 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1172 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1173 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1174 | NAME { $$ = ly_symbol2scm ("context-name"); }
1178 property_operation { $$ = $1; }
1179 | context_def_mod STRING {
1180 $$ = scm_list_2 ($1, $2);
1186 if (!is_regular_identifier ($1))
1188 @$.error (_("Grob name should be alphanumeric"));
1191 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1192 scm_string_to_symbol ($1));
1194 | simple_string '.' simple_string {
1195 $$ = scm_list_2 (scm_string_to_symbol ($1),
1196 scm_string_to_symbol ($3));
1200 simple_music_property_def:
1201 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1202 $$ = scm_list_5 (scm_car ($2),
1203 ly_symbol2scm ("OverrideProperty"),
1207 | OVERRIDE context_prop_spec embedded_scm embedded_scm '=' scalar {
1208 $$ = scm_list_n (scm_car ($2),
1209 ly_symbol2scm ("OverrideProperty"),
1211 $6, $4, $3, SCM_UNDEFINED);
1213 | REVERT context_prop_spec embedded_scm {
1214 $$ = scm_list_4 (scm_car ($2),
1215 ly_symbol2scm ("RevertProperty"),
1219 | SET context_prop_spec '=' scalar {
1220 $$ = scm_list_4 (scm_car ($2),
1221 ly_symbol2scm ("PropertySet"),
1225 | UNSET context_prop_spec {
1226 $$ = scm_list_3 (scm_car ($2),
1227 ly_symbol2scm ("PropertyUnset"),
1233 simple_music_property_def {
1234 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1236 | ONCE simple_music_property_def {
1237 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1245 | STRING_IDENTIFIER {
1248 | string '+' string {
1249 $$ = scm_string_append (scm_list_2 ($1, $3));
1253 simple_string: STRING {
1259 | STRING_IDENTIFIER {
1280 $$ = scm_from_int ($1);
1285 /* TODO: Create a special case that avoids the creation of
1286 EventChords around simple_elements that have no post_events?
1288 simple_chord_elements post_events {
1289 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1292 /* why is this giving wrong start location? -ns
1294 i.set_location (@1, @2);
1295 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1297 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1299 i.set_location (@1, @3);
1300 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2, $3);
1303 | note_chord_element
1308 chord_body optional_notemode_duration post_events
1310 Music *m = unsmob_music ($1);
1311 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1312 SCM es = m->get_property ("elements");
1313 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1315 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1316 unsmob_music (scm_car (s))->set_property ("duration", dur);
1317 es = ly_append2 (es, postevs);
1319 m-> set_property ("elements", es);
1321 $$ = m->self_scm ();
1331 simul_open: DOUBLE_ANGLE_OPEN
1334 simul_close: DOUBLE_ANGLE_CLOSE
1338 chord_open chord_body_elements chord_close
1340 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1344 chord_body_elements:
1345 /* empty */ { $$ = SCM_EOL; }
1346 | chord_body_elements chord_body_element {
1347 $$ = scm_cons ($2, $1);
1352 pitch exclamations questions octave_check post_events
1359 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1360 n->set_property ("pitch", $1);
1363 n->set_property ("cautionary", SCM_BOOL_T);
1364 if (ex % 2 || q % 2)
1365 n->set_property ("force-accidental", SCM_BOOL_T);
1367 if (scm_is_pair (post)) {
1368 SCM arts = scm_reverse_x (post, SCM_EOL);
1369 n->set_property ("articulations", arts);
1371 if (scm_is_number (check))
1373 int q = scm_to_int (check);
1374 n->set_property ("absolute-octave", scm_from_int (q-1));
1377 $$ = n->unprotect ();
1379 | DRUM_PITCH post_events {
1380 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1381 n->set_property ("duration", $2);
1382 n->set_property ("drum-type", $1);
1385 if (scm_is_pair ($2)) {
1386 SCM arts = scm_reverse_x ($2, SCM_EOL);
1387 n->set_property ("articulations", arts);
1389 $$ = n->unprotect ();
1391 | music_function_chord_body {
1392 $$ = run_music_function (PARSER, $1);
1396 music_function_chord_body:
1398 $$ = scm_list_2 ($1, make_input (@$));
1400 | music_function_musicless_prefix chord_body_element {
1401 $$ = ly_append2 ($1, scm_list_1 ($2));
1405 music_function_event:
1406 music_function_musicless_prefix post_event {
1407 $$ = ly_append2 ($1, scm_list_1 ($2));
1412 TODO: use code generation for this
1414 music_function_musicless_prefix:
1415 MUSIC_FUNCTION_MUSIC {
1416 $$ = scm_list_2 ($1, make_input (@$));
1418 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument {
1419 $$ = scm_list_3 ($1, make_input (@$), $2);
1421 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument {
1422 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1424 | MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument {
1425 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
1427 | MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument function_scm_argument {
1428 $$ = scm_list_n ($1, make_input (@$), $2, $3, $4, $5, SCM_UNDEFINED);
1437 | SKIP duration_length {
1438 $$ = MAKE_SYNTAX ("skip-music", @$, $2);
1441 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1442 m->set_property ("span-direction", scm_from_int (START));
1444 $$ = m->unprotect();
1447 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1448 m->set_property ("span-direction", scm_from_int (STOP));
1450 $$ = m->unprotect ();
1453 $$ = MAKE_SYNTAX ("voice-separator", @$, SCM_UNDEFINED);
1456 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1458 Music *m = unsmob_music (pipe);
1463 $$ = m->unprotect ();
1466 $$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
1469 | TRANSPOSITION pitch {
1471 Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c);
1472 $$ = MAKE_SYNTAX ("property-operation", @$, SCM_BOOL_F, ly_symbol2scm ("Staff"), ly_symbol2scm ("PropertySet"), ly_symbol2scm ("instrumentTransposition"), sounds_as_c.smobbed_copy ());
1474 | PARTIAL duration_length {
1475 Moment m = - unsmob_duration ($2)->get_length ();
1476 $$ = MAKE_SYNTAX ("property-operation", @$, SCM_BOOL_F, ly_symbol2scm ("Timing"), ly_symbol2scm ("PropertySet"), ly_symbol2scm ("measurePosition"), m.smobbed_copy ());
1477 $$ = MAKE_SYNTAX ("context-specification", @$, ly_symbol2scm ("Score"), SCM_BOOL_F, $$, SCM_EOL, SCM_BOOL_F);
1481 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1483 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1486 SCM proc = ly_lily_module_constant ("make-mark-set");
1488 $$ = scm_call_1 (proc, $2);
1494 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent")->unprotect ();
1497 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1498 $$ = m->unprotect ();
1504 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1505 $$ = key->unprotect ();
1507 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1509 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1510 if (scm_ilength ($3) > 0)
1512 key->set_property ("pitch-alist", $3);
1513 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1514 key->transpose (* unsmob_pitch ($2));
1516 PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1519 $$ = key->unprotect ();
1528 | post_events post_event {
1529 unsmob_music ($2)->set_spot (@2);
1530 $$ = scm_cons ($2, $$);
1535 direction_less_event {
1538 | '-' music_function_event {
1539 $$ = run_music_function (PARSER, $2);
1542 if (!PARSER->lexer_->is_lyric_state ())
1543 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1544 $$ = MY_MAKE_MUSIC ("HyphenEvent")->unprotect ();
1547 if (!PARSER->lexer_->is_lyric_state ())
1548 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1549 $$ = MY_MAKE_MUSIC ("ExtenderEvent")->unprotect ();
1551 | script_dir direction_reqd_event {
1554 Music *m = unsmob_music ($2);
1555 m->set_property ("direction", scm_from_int ($1));
1559 | script_dir direction_less_event {
1562 Music *m = unsmob_music ($2);
1563 m->set_property ("direction", scm_from_int ($1));
1567 | string_number_event
1570 string_number_event:
1572 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1573 s->set_property ("string-number", scm_from_int ($1));
1575 $$ = s->unprotect ();
1579 direction_less_char:
1581 $$ = ly_symbol2scm ("bracketOpenSymbol");
1584 $$ = ly_symbol2scm ("bracketCloseSymbol");
1587 $$ = ly_symbol2scm ("tildeSymbol");
1590 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1593 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1596 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1599 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1602 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1605 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1608 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1612 direction_less_event:
1613 direction_less_char {
1614 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
1616 if (unsmob_music (predefd))
1618 m = unsmob_music (predefd)->clone ();
1622 m = MY_MAKE_MUSIC ("Music");
1625 $$ = m->unprotect ();
1627 | EVENT_IDENTIFIER {
1631 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1633 a->set_property ("tremolo-type", scm_from_int ($1));
1634 $$ = a->unprotect ();
1638 direction_reqd_event:
1642 | script_abbreviation {
1643 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1644 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1645 if (scm_is_string (s))
1646 a->set_property ("articulation-type", s);
1647 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
1648 $$ = a->unprotect ();
1653 /**/ { $$ = SCM_EOL; }
1654 | '=' { $$ = scm_from_int (0); }
1655 | '=' sub_quotes { $$ = scm_from_int ($2); }
1656 | '=' sup_quotes { $$ = scm_from_int ($2); }
1681 | NOTENAME_PITCH sup_quotes {
1682 Pitch p = *unsmob_pitch ($1);
1683 p = p.transposed (Pitch ($2,0,0));
1684 $$ = p.smobbed_copy ();
1686 | NOTENAME_PITCH sub_quotes {
1687 Pitch p =* unsmob_pitch ($1);
1688 p = p.transposed (Pitch (-$2,0,0));
1689 $$ = p.smobbed_copy ();
1701 | TONICNAME_PITCH sup_quotes {
1702 Pitch p = *unsmob_pitch ($1);
1703 p = p.transposed (Pitch ($2,0,0));
1704 $$ = p.smobbed_copy ();
1706 | TONICNAME_PITCH sub_quotes {
1707 Pitch p =* unsmob_pitch ($1);
1709 p = p.transposed (Pitch (-$2,0,0));
1710 $$ = p.smobbed_copy ();
1720 pitch_also_in_chords:
1727 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1728 t->set_property ("text", $1);
1730 $$ = t->unprotect ();
1733 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1734 t->set_property ("text",
1735 make_simple_markup ($1));
1737 $$ = t->unprotect ();
1740 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1741 t->set_property ("digit", scm_from_int ($1));
1743 $$ = t->unprotect ();
1747 script_abbreviation:
1749 $$ = scm_makfrom0str ("Hat");
1752 $$ = scm_makfrom0str ("Plus");
1755 $$ = scm_makfrom0str ("Dash");
1758 $$ = scm_makfrom0str ("Bar");
1761 $$ = scm_makfrom0str ("Larger");
1764 $$ = scm_makfrom0str ("Dot");
1767 $$ = scm_makfrom0str ("Underscore");
1774 | '-' { $$ = CENTER; }
1785 multiplied_duration {
1790 optional_notemode_duration:
1792 Duration dd = PARSER->default_duration_;
1793 $$ = dd.smobbed_copy ();
1795 | multiplied_duration {
1797 PARSER->default_duration_ = *unsmob_duration ($$);
1802 bare_unsigned dots {
1804 if (!is_duration ($1))
1805 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
1809 $$ = Duration (len, $2).smobbed_copy ();
1811 | DURATION_IDENTIFIER dots {
1812 Duration *d = unsmob_duration ($1);
1813 Duration k (d->duration_log (), d->dot_count () + $2);
1819 multiplied_duration:
1823 | multiplied_duration '*' bare_unsigned {
1824 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1826 | multiplied_duration '*' FRACTION {
1827 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1829 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1834 FRACTION { $$ = $1; }
1835 | UNSIGNED '/' UNSIGNED {
1836 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
1853 | ':' bare_unsigned {
1854 if (!is_duration ($2))
1855 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
1862 $$ = scm_from_int ($1);
1865 $$ = scm_from_int ($1);
1867 | STRING { $$ = $1; }
1868 | full_markup { $$ = $1; }
1871 figured_bass_alteration:
1879 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
1880 $$ = bfr->self_scm ();
1885 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
1886 $$ = bfr->self_scm ();
1888 if (scm_is_number ($1))
1889 bfr->set_property ("figure", $1);
1890 else if (Text_interface::is_markup ($1))
1891 bfr->set_property ("text", $1);
1898 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
1900 | bass_figure figured_bass_alteration {
1901 Music *m = unsmob_music ($1);
1903 SCM salter = m->get_property ("alteration");
1904 int alter = scm_is_number (salter) ? scm_to_int (salter) : 0;
1905 m->set_property ("alteration",
1906 scm_from_int (alter + $2));
1908 m->set_property ("alteration", scm_from_int (0));
1911 | bass_figure figured_bass_modification {
1912 Music *m = unsmob_music ($1);
1913 if ($2 == ly_symbol2scm ("plus"))
1915 m->set_property ("augmented", SCM_BOOL_T);
1917 else if ($2 == ly_symbol2scm ("slash"))
1919 m->set_property ("diminished", SCM_BOOL_T);
1921 else if ($2 == ly_symbol2scm ("exclamation"))
1923 m->set_property ("no-continuation", SCM_BOOL_T);
1929 figured_bass_modification:
1931 $$ = ly_symbol2scm ("plus");
1934 $$ = ly_symbol2scm ("exclamation");
1937 $$ = ly_symbol2scm ("slash");
1947 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
1955 | figure_list br_bass_figure {
1956 $$ = scm_cons ($2, $1);
1961 FIGURE_OPEN figure_list FIGURE_CLOSE {
1962 $$ = scm_reverse_x ($2, SCM_EOL);
1973 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
1974 if (!PARSER->lexer_->is_note_state ())
1975 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
1979 n = MY_MAKE_MUSIC ("RestEvent");
1981 n = MY_MAKE_MUSIC ("NoteEvent");
1983 n->set_property ("pitch", $1);
1984 n->set_property ("duration", $5);
1986 if (scm_is_number ($4))
1988 int q = scm_to_int ($4);
1989 n->set_property ("absolute-octave", scm_from_int (q-1));
1993 n->set_property ("cautionary", SCM_BOOL_T);
1994 if ($2 % 2 || $3 % 2)
1995 n->set_property ("force-accidental", SCM_BOOL_T);
1998 $$ = n->unprotect ();
2000 | DRUM_PITCH optional_notemode_duration {
2001 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2002 n->set_property ("duration", $2);
2003 n->set_property ("drum-type", $1);
2005 $$ = n->unprotect ();
2007 | RESTNAME optional_notemode_duration {
2009 if (ly_scm2string ($1) == "s") {
2011 ev = MY_MAKE_MUSIC ("SkipEvent");
2014 ev = MY_MAKE_MUSIC ("RestEvent");
2017 ev->set_property ("duration", $2);
2019 $$ = ev->unprotect ();
2021 | lyric_element optional_notemode_duration {
2022 if (!PARSER->lexer_->is_lyric_state ())
2023 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2025 Music *levent = MY_MAKE_MUSIC ("LyricEvent");
2026 levent->set_property ("text", $1);
2027 levent->set_property ("duration",$2);
2028 levent->set_spot (@$);
2029 $$= levent->unprotect ();
2033 simple_chord_elements:
2035 $$ = scm_list_1 ($1);
2038 if (!PARSER->lexer_->is_chord_state ())
2039 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2042 | figure_spec optional_notemode_duration {
2043 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2045 unsmob_music (scm_car (s))->set_property ("duration", $2);
2061 steno_tonic_pitch optional_notemode_duration {
2062 $$ = make_chord_elements ($1, $2, SCM_EOL);
2064 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2065 SCM its = scm_reverse_x ($4, SCM_EOL);
2066 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2074 | chord_items chord_item {
2075 $$ = scm_cons ($2, $$);
2081 $$ = ly_symbol2scm ("chord-colon");
2084 $$ = ly_symbol2scm ("chord-caret");
2086 | CHORD_SLASH steno_tonic_pitch {
2087 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2089 | CHORD_BASS steno_tonic_pitch {
2090 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2099 $$ = scm_reverse_x ($1, SCM_EOL);
2107 step_number { $$ = scm_cons ($1, SCM_EOL); }
2108 | step_numbers '.' step_number {
2109 $$ = scm_cons ($3, $$);
2115 $$ = make_chord_step ($1, 0);
2117 | bare_unsigned '+' {
2118 $$ = make_chord_step ($1, SHARP);
2120 | bare_unsigned CHORD_MINUS {
2121 $$ = make_chord_step ($1, FLAT);
2128 TODO: should deprecate in favor of Scheme?
2132 number_expression '+' number_term {
2133 $$ = scm_sum ($1, $3);
2135 | number_expression '-' number_term {
2136 $$ = scm_difference ($1, $3);
2145 | number_factor '*' number_factor {
2146 $$ = scm_product ($1, $3);
2148 | number_factor '/' number_factor {
2149 $$ = scm_divide ($1, $3);
2154 '-' number_factor { /* %prec UNARY_MINUS */
2155 $$ = scm_difference ($2, SCM_UNDEFINED);
2163 $$ = scm_from_int ($1);
2168 | NUMBER_IDENTIFIER {
2171 | REAL NUMBER_IDENTIFIER {
2172 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2174 | UNSIGNED NUMBER_IDENTIFIER {
2175 $$ = scm_from_double ($1 *scm_to_double ($2));
2191 | exclamations '!' { $$ ++; }
2196 | questions '?' { $$ ++; }
2200 This should be done more dynamically if possible.
2204 LYRIC_MARKUP_IDENTIFIER {
2208 { PARSER->lexer_->push_markup_state (); }
2211 PARSER->lexer_->pop_state ();
2220 { PARSER->lexer_->push_markup_state (); }
2223 PARSER->lexer_->pop_state ();
2229 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2231 | markup_head_1_list simple_markup {
2232 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2240 markup_composed_list {
2243 | markup_braced_list {
2248 markup_composed_list:
2249 markup_head_1_list markup_braced_list {
2250 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2256 '{' markup_braced_list_body '}' {
2257 $$ = scm_reverse_x ($2, SCM_EOL);
2261 markup_braced_list_body:
2262 /* empty */ { $$ = SCM_EOL; }
2263 | markup_braced_list_body markup {
2264 $$ = scm_cons ($2, $1);
2266 | markup_braced_list_body markup_list {
2267 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2272 MARKUP_HEAD_MARKUP0 {
2273 $$ = scm_list_1 ($1);
2275 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2276 $$ = scm_list_2 ($1, $2);
2278 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2279 $$ = scm_list_3 ($1, $2, $3);
2284 markup_head_1_item {
2285 $$ = scm_list_1 ($1);
2287 | markup_head_1_list markup_head_1_item {
2288 $$ = scm_cons ($2, $1);
2294 $$ = make_simple_markup ($1);
2296 | MARKUP_IDENTIFIER {
2299 | LYRIC_MARKUP_IDENTIFIER {
2302 | STRING_IDENTIFIER {
2306 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2307 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2308 } '{' score_body '}' {
2310 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2312 PARSER->lexer_->pop_state ();
2314 | MARKUP_HEAD_SCM0 embedded_scm {
2315 $$ = scm_list_2 ($1, $2);
2317 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2318 $$ = scm_list_4 ($1, $2, $3, $4);
2320 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2321 $$ = scm_list_3 ($1, $2, $3);
2323 | MARKUP_HEAD_EMPTY {
2324 $$ = scm_list_1 ($1);
2326 | MARKUP_HEAD_LIST0 markup_list {
2327 $$ = scm_list_2 ($1,$2);
2329 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2330 $$ = scm_list_3 ($1, $2, $3);
2335 markup_head_1_list simple_markup {
2336 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2337 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2347 Lily_parser::set_yydebug (bool )
2355 Lily_parser::do_yyparse ()
2357 yyparse ((void*)this);
2366 It is a little strange to have this function in this file, but
2367 otherwise, we have to import music classes into the lexer.
2371 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2373 if (scm_is_string (sid)) {
2375 return STRING_IDENTIFIER;
2376 } else if (unsmob_book (sid)) {
2377 *destination = unsmob_book (sid)->clone ()->self_scm ();
2378 return BOOK_IDENTIFIER;
2379 } else if (scm_is_number (sid)) {
2381 return NUMBER_IDENTIFIER;
2382 } else if (unsmob_context_def (sid)) {
2383 *destination = unsmob_context_def (sid)->clone_scm ();
2384 return CONTEXT_DEF_IDENTIFIER;
2385 } else if (unsmob_score (sid)) {
2386 Score *score = new Score (*unsmob_score (sid));
2387 *destination = score->self_scm ();
2388 return SCORE_IDENTIFIER;
2389 } else if (Music *mus = unsmob_music (sid)) {
2390 mus = mus->clone ();
2391 *destination = mus->self_scm ();
2392 unsmob_music (*destination)->
2393 set_property ("origin", make_input (last_input_));
2395 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2398 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2399 } else if (unsmob_duration (sid)) {
2400 *destination = unsmob_duration (sid)->smobbed_copy ();
2401 return DURATION_IDENTIFIER;
2402 } else if (unsmob_output_def (sid)) {
2403 Output_def *p = unsmob_output_def (sid);
2406 *destination = p->self_scm ();
2407 return OUTPUT_DEF_IDENTIFIER;
2408 } else if (Text_interface::is_markup (sid)) {
2410 if (is_lyric_state ())
2411 return LYRIC_MARKUP_IDENTIFIER;
2412 return MARKUP_IDENTIFIER;
2419 get_next_unique_context_id ()
2421 return scm_makfrom0str ("$uniqueContextId");
2426 get_next_unique_lyrics_context_id ()
2428 static int new_context_count;
2430 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2431 return scm_makfrom0str (s);
2436 run_music_function (Lily_parser *parser, SCM expr)
2438 SCM func = scm_car (expr);
2439 Input *loc = unsmob_input (scm_cadr (expr));
2440 SCM args = scm_cddr (expr);
2441 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2443 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2445 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2447 parser->error_level_ = 1;
2448 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (*loc)));
2451 SCM syntax_args = scm_list_4 (parser->self_scm (), make_input (*loc), func, args);
2452 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
2456 is_regular_identifier (SCM id)
2458 string str = ly_scm2string (id);
2459 char const *s = str.c_str ();
2468 v = v && isalnum (*s);
2476 get_first_context_id (SCM type, Music *m)
2478 SCM id = m->get_property ("context-id");
2479 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2480 && scm_is_string (m->get_property ("context-id"))
2481 && scm_c_string_length (id) > 0)
2489 make_simple_markup (SCM a)
2497 return t && t == 1 << intlog2 (t);
2501 set_music_properties (Music *p, SCM a)
2503 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2504 p->internal_set_property (scm_caar (k), scm_cdar (k));
2509 make_chord_step (int step, int alter)
2516 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2517 return m.smobbed_copy ();
2522 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
2524 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
2525 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
2529 /* Todo: actually also use apply iso. call too ... */
2531 ly_input_procedure_p (SCM x)
2533 return ly_is_procedure (x)
2534 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2538 make_music_relative (Pitch start, SCM music)
2540 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
2541 relative->set_property ("element", music);
2543 Music *m = unsmob_music (music);
2544 Pitch last = m->to_relative_octave (start);
2545 if (lily_1_8_relative)
2546 m->set_property ("last-pitch", last.smobbed_copy ());
2547 return relative->unprotect ();
2551 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2553 Lily_parser *pars = (Lily_parser*) v;
2554 Lily_lexer *lex = pars->lexer_;
2556 lex->lexval = (void*) s;
2558 lex->prepare_for_next_token ();
2559 return lex->yylex ();