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"
210 %token UNSET "\\unset"
213 /* Keyword token exceptions. */
214 %token TIME_T "\\time"
215 %token NEWCONTEXT "\\new"
218 /* Other string tokens. */
220 %token CHORD_BASS "/+"
221 %token CHORD_CARET "^"
222 %token CHORD_COLON ":"
223 %token CHORD_MINUS "-"
224 %token CHORD_SLASH "/"
225 %token ANGLE_OPEN "<"
226 %token ANGLE_CLOSE ">"
227 %token DOUBLE_ANGLE_OPEN "<<"
228 %token DOUBLE_ANGLE_CLOSE ">>"
229 %token E_BACKSLASH "\\"
230 %token E_ANGLE_CLOSE "\\>"
231 %token E_CHAR "\\C[haracter]"
233 %token E_EXCLAMATION "\\!"
234 %token E_BRACKET_OPEN "\\["
236 %token E_BRACKET_CLOSE "\\]"
237 %token E_ANGLE_OPEN "\\<"
243 If we give names, Bison complains.
245 %token FIGURE_CLOSE /* "\\>" */
246 %token FIGURE_OPEN /* "\\<" */
247 %token FIGURE_SPACE "_"
250 %token CHORDMODIFIERS
252 %token MULTI_MEASURE_REST
257 %token <i> E_UNSIGNED
260 %token <scm> BOOK_IDENTIFIER
261 %token <scm> CHORDMODIFIER_PITCH
262 %token <scm> CHORD_MODIFIER
263 %token <scm> CONTEXT_DEF_IDENTIFIER
264 %token <scm> DRUM_PITCH
265 %token <scm> DURATION_IDENTIFIER
266 %token <scm> EVENT_IDENTIFIER
267 %token <scm> FRACTION
268 %token <scm> LYRICS_STRING
269 %token <scm> LYRIC_MARKUP_IDENTIFIER
270 %token <scm> MARKUP_HEAD_EMPTY
271 %token <scm> MARKUP_HEAD_LIST0
272 %token <scm> MARKUP_HEAD_MARKUP0
273 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
274 %token <scm> MARKUP_HEAD_SCM0
275 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
276 %token <scm> MARKUP_HEAD_SCM0_SCM1
277 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
278 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
279 %token <scm> MARKUP_IDENTIFIER
280 %token <scm> MUSIC_FUNCTION
281 %token <scm> MUSIC_FUNCTION_MARKUP
282 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP
283 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC
284 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC
285 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC
286 %token <scm> MUSIC_FUNCTION_MUSIC
287 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC
288 %token <scm> MUSIC_FUNCTION_SCM
289 %token <scm> MUSIC_FUNCTION_SCM_MUSIC
290 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC
291 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC_MUSIC
292 %token <scm> MUSIC_FUNCTION_SCM_SCM
293 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC
294 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM
295 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC
296 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC
297 %token <scm> MUSIC_IDENTIFIER
298 %token <scm> NOTENAME_PITCH
299 %token <scm> NUMBER_IDENTIFIER
300 %token <scm> OUTPUT_DEF_IDENTIFIER
302 %token <scm> RESTNAME
303 %token <scm> SCM_IDENTIFIER
305 %token <scm> SCORE_IDENTIFIER
307 %token <scm> STRING_IDENTIFIER
308 %token <scm> TONICNAME_PITCH
311 %type <book> book_block
312 %type <book> book_body
314 %type <i> bare_unsigned
315 %type <i> figured_bass_alteration
317 %type <i> exclamations
318 %type <i> optional_rest
323 %type <i> tremolo_type
326 %type <scm> composite_music
327 %type <scm> grouped_music_list
329 %type <scm> prefix_composite_music
330 %type <scm> repeated_music
331 %type <scm> sequential_music
332 %type <scm> simple_music
333 %type <scm> simultaneous_music
334 %type <scm> chord_body
335 %type <scm> chord_body_element
336 %type <scm> command_element
337 %type <scm> command_event
338 %type <scm> context_change
339 %type <scm> direction_less_event
340 %type <scm> direction_reqd_event
341 %type <scm> event_chord
342 %type <scm> gen_text_def
343 %type <scm> music_property_def
344 %type <scm> note_chord_element
345 %type <scm> post_event
346 %type <scm> re_rhythmed_music
347 %type <scm> relative_music
348 %type <scm> simple_element
349 %type <scm> simple_music_property_def
350 %type <scm> string_number_event
351 %type <scm> tempo_event
353 %type <outputdef> output_def_body
354 %type <outputdef> output_def_head
355 %type <outputdef> output_def_head_with_mode_switch
356 %type <outputdef> output_def
357 %type <outputdef> paper_block
359 %type <scm> alternative_music
360 %type <scm> generic_prefix_music_scm
361 %type <scm> music_list
362 %type <scm> absolute_pitch
363 %type <scm> assignment_id
364 %type <scm> bare_number
365 %type <scm> music_function_event
366 %type <scm> music_function_chord_body
367 %type <scm> music_function_musicless_prefix
368 %type <scm> music_function_musicless_function
369 %type <scm> bass_figure
370 %type <scm> figured_bass_modification
371 %type <scm> br_bass_figure
372 %type <scm> bass_number
373 %type <scm> chord_body_elements
374 %type <scm> chord_item
375 %type <scm> chord_items
376 %type <scm> chord_separator
377 %type <scm> context_def_mod
378 %type <scm> context_def_spec_block
379 %type <scm> context_def_spec_body
380 %type <scm> context_mod
381 %type <scm> context_mod_list
382 %type <scm> context_prop_spec
383 %type <scm> direction_less_char
384 %type <scm> duration_length
385 %type <scm> embedded_scm
386 %type <scm> figure_list
387 %type <scm> figure_spec
389 %type <scm> full_markup
390 %type <scm> identifier_init
391 %type <scm> lilypond_header
392 %type <scm> lilypond_header_body
393 %type <scm> lyric_element
394 %type <scm> lyric_markup
396 %type <scm> markup_braced_list
397 %type <scm> markup_braced_list_body
398 %type <scm> markup_composed_list
399 %type <scm> markup_head_1_item
400 %type <scm> markup_head_1_list
401 %type <scm> markup_list
402 %type <scm> markup_top
403 %type <scm> mode_changing_head
404 %type <scm> mode_changing_head_with_context
405 %type <scm> multiplied_duration
406 %type <scm> new_chord
407 %type <scm> new_lyrics
408 %type <scm> number_expression
409 %type <scm> number_factor
410 %type <scm> number_term
411 %type <scm> object_id_setting
412 %type <scm> octave_check
413 %type <scm> optional_context_mod
414 %type <scm> optional_id
415 %type <scm> optional_notemode_duration
417 %type <scm> pitch_also_in_chords
418 %type <scm> post_events
419 %type <scm> property_operation
421 %type <scm> script_abbreviation
422 %type <scm> simple_chord_elements
423 %type <scm> simple_markup
424 %type <scm> simple_string
425 %type <scm> steno_duration
426 %type <scm> steno_pitch
427 %type <scm> steno_tonic_pitch
428 %type <scm> step_number
429 %type <scm> step_numbers
431 %type <scm> function_scm_argument
433 %type <score> score_block
434 %type <score> score_body
439 /* We don't assign precedence to / and *, because we might need varied
440 prec levels in different prods */
446 lilypond: /* empty */
447 | lilypond toplevel_expression {
449 | lilypond assignment {
452 PARSER->error_level_ = 1;
455 PARSER->error_level_ = 1;
461 OBJECTID STRING { $$ = $2; }
466 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
470 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
471 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
477 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
478 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
482 Music *music = unsmob_music ($1);
483 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
484 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
487 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
488 scm_call_2 (proc, PARSER->self_scm (), $1);
492 Output_def * od = $1;
494 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
495 id = ly_symbol2scm ("$defaultpaper");
496 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
497 id = ly_symbol2scm ("$defaultmidi");
498 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
499 id = ly_symbol2scm ("$defaultlayout");
501 PARSER->lexer_->set_identifier (id, od->self_scm ());
512 lilypond_header_body:
514 $$ = get_header(PARSER);
515 PARSER->lexer_->add_scope ($$);
517 | lilypond_header_body assignment {
523 HEADER '{' lilypond_header_body '}' {
524 $$ = PARSER->lexer_->remove_scope ();
533 | LYRICS_STRING { $$ = $1; }
537 assignment_id '=' identifier_init {
538 if (! is_regular_identifier ($1))
541 /* no longer valid with dashes in \paper{} block. */
542 @1.warning (_ ("identifier should have alphabetic characters only"));
547 PARSER->lexer_->set_identifier ($1, $3);
550 TODO: devise standard for protection in parser.
552 The parser stack lives on the C-stack, which means that
553 all objects can be unprotected as soon as they're here.
563 $$ = $1->self_scm ();
567 $$ = $1->self_scm ();
571 $$ = $1->self_scm ();
574 | context_def_spec_block {
578 /* Hack: Create event-chord around standalone events.
579 Prevents the identifier from being interpreted as a post-event. */
580 Music *mus = unsmob_music ($1);
581 bool is_event = mus &&
582 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
587 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
592 | number_expression {
605 $$ = scm_from_int ($1);
609 context_def_spec_block:
610 CONTEXT '{' context_def_spec_body '}'
616 context_def_spec_body:
618 $$ = Context_def::make_scm ();
619 unsmob_context_def ($$)->set_spot (@$);
621 | CONTEXT_DEF_IDENTIFIER {
623 unsmob_context_def ($$)->set_spot (@$);
625 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
626 Context_def*td = unsmob_context_def ($$);
628 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
629 SCM tag = scm_caar (p);
631 /* TODO: should make new tag "grob-definition" ? */
632 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
633 tag, scm_cons (scm_cdar (p), SCM_EOL)));
636 | context_def_spec_body context_mod {
637 unsmob_context_def ($$)->add_context_mod ($2);
644 BOOK '{' book_body '}' {
650 * Use 'handlers' like for toplevel-* stuff?
651 * grok \layout and \midi? */
656 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
657 $$->paper_->unprotect ();
658 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
661 $$ = unsmob_book ($1);
664 | book_body paper_block {
668 | book_body score_block {
669 SCM s = $2->self_scm ();
673 | book_body full_markup {
676 | book_body lilypond_header {
681 $$->scores_ = SCM_EOL;
683 | book_body object_id_setting {
684 $$->user_key_ = ly_scm2string ($2);
689 SCORE '{' score_body '}' {
697 SCM scorify = ly_lily_module_constant ("scorify-music");
698 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
700 // pass ownernship to C++ again.
701 $$ = unsmob_score (score);
706 $$ = unsmob_score ($1);
709 | score_body object_id_setting {
710 $$->user_key_ = ly_scm2string ($2);
712 | score_body lilypond_header {
715 | score_body output_def {
716 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
718 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
723 $$->add_output_def ($2);
728 $$->error_found_ = true;
740 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
742 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
743 $$ = get_paper (PARSER);
750 output_def_body '}' {
753 PARSER->lexer_->remove_scope ();
754 PARSER->lexer_->pop_state ();
760 $$ = get_paper (PARSER);
761 $$->input_origin_ = @$;
762 PARSER->lexer_->add_scope ($$->scope_);
765 Output_def *p = get_midi (PARSER);
767 PARSER->lexer_->add_scope (p->scope_);
770 Output_def *p = get_layout (PARSER);
772 PARSER->lexer_->add_scope (p->scope_);
777 output_def_head_with_mode_switch:
779 PARSER->lexer_->push_initial_state ();
785 output_def_head_with_mode_switch '{' {
787 $$->input_origin_.set_spot (@$);
789 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
791 Output_def *o = unsmob_output_def ($3);
792 o->input_origin_.set_spot (@$);
794 PARSER->lexer_->remove_scope ();
795 PARSER->lexer_->add_scope (o->scope_);
797 | output_def_body assignment {
800 | output_def_body context_def_spec_block {
801 assign_context_def ($$, $2);
803 | output_def_body tempo_event {
805 junk this ? there already is tempo stuff in
808 int m = scm_to_int (unsmob_music($2)->get_property ("metronome-count"));
809 Duration *d = unsmob_duration (unsmob_music($2)->get_property ("tempo-unit"));
810 set_tempo ($$, d->get_length (), m);
812 | output_def_body error {
818 TEMPO steno_duration '=' bare_unsigned {
819 Music *m = MY_MAKE_MUSIC ("MetronomeChangeEvent");
820 m->set_property ("tempo-unit", $2);
821 m->set_property ("metronome-count", scm_from_int ( $4));
822 $$ = m->unprotect ();
827 The representation of a list is the
831 to have efficient append. */
835 $$ = scm_cons (SCM_EOL, SCM_EOL);
839 SCM c = scm_cons ($2, SCM_EOL);
841 if (scm_is_pair (scm_cdr (s)))
842 scm_set_cdr_x (scm_cdr (s), c); /* append */
844 scm_set_car_x (s, c); /* set first cons */
845 scm_set_cdr_x (s, c); /* remember last cell */
847 | music_list embedded_scm {
851 Music *m = MY_MAKE_MUSIC("Music");
853 m->set_property ("error-found", SCM_BOOL_T);
855 SCM c = scm_cons (m->self_scm (), SCM_EOL);
856 m->unprotect (); /* UGH */
858 if (scm_is_pair (scm_cdr (s)))
859 scm_set_cdr_x (scm_cdr (s), c); /* append */
861 scm_set_car_x (s, c); /* set first cons */
862 scm_set_cdr_x (s, c); /* remember last cell */
875 | ALTERNATIVE '{' music_list '}' {
882 REPEAT simple_string bare_unsigned music alternative_music
884 $$ = MAKE_SYNTAX ("repeat", @$, $2, scm_int2num ($3), $4, $5);
889 SEQUENTIAL '{' music_list '}' {
890 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($3));
892 | '{' music_list '}' {
893 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($2));
898 SIMULTANEOUS '{' music_list '}'{
899 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($3));
901 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
902 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($2));
913 optional_context_mod:
914 /**/ { $$ = SCM_EOL; }
915 | WITH { PARSER->lexer_->push_initial_state (); }
916 '{' context_mod_list '}'
918 PARSER->lexer_->pop_state ();
924 /* */ { $$ = SCM_EOL; }
925 | context_mod_list context_mod {
926 $$ = scm_cons ($2, $1);
931 prefix_composite_music { $$ = $1; }
932 | grouped_music_list { $$ = $1; }
936 simultaneous_music { $$ = $1; }
937 | sequential_music { $$ = $1; }
940 function_scm_argument:
946 TODO: use code generation for this
948 music_function_musicless_function:
950 $$ = scm_list_2 ($1, make_input (@$));
952 | MUSIC_FUNCTION_SCM function_scm_argument {
953 $$ = scm_list_3 ($1, make_input (@$), $2);
955 | MUSIC_FUNCTION_MARKUP full_markup {
956 $$ = scm_list_3 ($1, make_input (@$), $2);
958 | MUSIC_FUNCTION_SCM_SCM function_scm_argument function_scm_argument {
959 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
961 | MUSIC_FUNCTION_SCM_SCM_SCM function_scm_argument function_scm_argument function_scm_argument {
962 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
964 | MUSIC_FUNCTION_MARKUP_MARKUP full_markup full_markup {
965 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
970 TODO: use code generation for this
972 music_function_musicless_prefix:
973 MUSIC_FUNCTION_MUSIC {
974 $$ = scm_list_2 ($1, make_input (@$));
976 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument {
977 $$ = scm_list_3 ($1, make_input (@$), $2);
979 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument {
980 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
982 | MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument {
983 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
985 | MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument function_scm_argument {
986 $$ = scm_list_n ($1, make_input (@$), $2, $3, $4, $5, SCM_UNDEFINED);
988 | MUSIC_FUNCTION_MARKUP_MUSIC full_markup {
989 $$ = scm_list_3 ($1, make_input (@$), $2);
993 generic_prefix_music_scm:
994 music_function_musicless_function {
997 | music_function_musicless_prefix music {
998 $$ = ly_append2 ($1, scm_list_1 ($2));
1000 | MUSIC_FUNCTION_MUSIC_MUSIC music music {
1001 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1003 | MUSIC_FUNCTION_SCM_MUSIC_MUSIC function_scm_argument music music {
1004 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
1006 | MUSIC_FUNCTION_SCM_SCM_MUSIC_MUSIC function_scm_argument function_scm_argument music music {
1007 $$ = scm_list_n ($1, make_input (@$), $2, $3, $4, $5, SCM_UNDEFINED);
1009 | MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC full_markup music music {
1010 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
1016 /**/ { $$ = SCM_EOL; }
1017 | '=' simple_string {
1023 prefix_composite_music:
1024 generic_prefix_music_scm {
1025 $$ = run_music_function (PARSER, $1);
1027 | CONTEXT simple_string optional_id optional_context_mod music {
1028 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_F);
1030 | NEWCONTEXT simple_string optional_id optional_context_mod music {
1031 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_T);
1034 | TIMES fraction music {
1035 $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3);
1037 | repeated_music { $$ = $1; }
1038 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords music {
1039 Pitch from = *unsmob_pitch ($2);
1040 Pitch to = *unsmob_pitch ($3);
1041 SCM pitch = pitch_interval (from, to).smobbed_copy ();
1042 $$ = MAKE_SYNTAX ("transpose-music", @$, pitch, $4);
1044 | mode_changing_head grouped_music_list {
1045 if ($1 == ly_symbol2scm ("chords"))
1047 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1053 PARSER->lexer_->pop_state ();
1055 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1056 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, $3, $2, SCM_BOOL_T);
1057 if ($1 == ly_symbol2scm ("ChordNames"))
1059 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1061 PARSER->lexer_->pop_state ();
1063 | relative_music { $$ = $1; }
1064 | re_rhythmed_music { $$ = $1; }
1069 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1070 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1072 $$ = ly_symbol2scm ("notes");
1076 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1077 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1079 $$ = ly_symbol2scm ("drums");
1082 PARSER->lexer_->push_figuredbass_state ();
1084 $$ = ly_symbol2scm ("figures");
1087 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1088 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1089 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1090 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1091 $$ = ly_symbol2scm ("chords");
1095 { PARSER->lexer_->push_lyric_state ();
1096 $$ = ly_symbol2scm ("lyrics");
1100 mode_changing_head_with_context:
1102 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1103 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1105 $$ = ly_symbol2scm ("DrumStaff");
1108 PARSER->lexer_->push_figuredbass_state ();
1110 $$ = ly_symbol2scm ("FiguredBass");
1113 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1114 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1115 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1116 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1117 $$ = ly_symbol2scm ("ChordNames");
1120 { PARSER->lexer_->push_lyric_state ();
1121 $$ = ly_symbol2scm ("Lyrics");
1127 RELATIVE absolute_pitch music {
1128 Pitch start = *unsmob_pitch ($2);
1129 $$ = make_music_relative (start, $3);
1131 | RELATIVE composite_music {
1132 Pitch middle_c (0, 0, 0);
1133 $$ = make_music_relative (middle_c, $2);
1138 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1140 grouped_music_list {
1141 /* Can also use music at the expensive of two S/Rs similar to
1142 \repeat \alternative */
1143 PARSER->lexer_->pop_state ();
1145 $$ = scm_cons ($3, SCM_EOL);
1147 | new_lyrics ADDLYRICS {
1148 PARSER->lexer_->push_lyric_state ();
1149 } grouped_music_list {
1150 PARSER->lexer_->pop_state ();
1151 $$ = scm_cons ($4, $1);
1156 grouped_music_list new_lyrics {
1157 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1159 | LYRICSTO simple_string {
1160 PARSER->lexer_->push_lyric_state ();
1162 PARSER->lexer_->pop_state ();
1163 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1168 CHANGE STRING '=' STRING {
1169 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1175 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1176 scm_string_to_symbol ($1), $3);
1178 | UNSET simple_string {
1179 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1180 scm_string_to_symbol ($2));
1182 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1183 $$ = scm_list_4 (ly_symbol2scm ("push"),
1184 scm_string_to_symbol ($2), $5, $3);
1186 | OVERRIDE simple_string embedded_scm embedded_scm '=' embedded_scm {
1187 $$ = scm_list_5 (ly_symbol2scm ("push"),
1188 scm_string_to_symbol ($2), $6, $4, $3);
1190 | REVERT simple_string embedded_scm {
1191 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1192 scm_string_to_symbol ($2), $3);
1197 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1198 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1200 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1201 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1202 | DENIES { $$ = ly_symbol2scm ("denies"); }
1204 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1205 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1206 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1207 | NAME { $$ = ly_symbol2scm ("context-name"); }
1211 property_operation { $$ = $1; }
1212 | context_def_mod STRING {
1213 $$ = scm_list_2 ($1, $2);
1219 if (!is_regular_identifier ($1))
1221 @$.error (_("Grob name should be alphanumeric"));
1224 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1225 scm_string_to_symbol ($1));
1227 | simple_string '.' simple_string {
1228 $$ = scm_list_2 (scm_string_to_symbol ($1),
1229 scm_string_to_symbol ($3));
1233 simple_music_property_def:
1234 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1235 $$ = scm_list_5 (scm_car ($2),
1236 ly_symbol2scm ("OverrideProperty"),
1240 | OVERRIDE context_prop_spec embedded_scm embedded_scm '=' scalar {
1241 $$ = scm_list_n (scm_car ($2),
1242 ly_symbol2scm ("OverrideProperty"),
1244 $6, $4, $3, SCM_UNDEFINED);
1246 | REVERT context_prop_spec embedded_scm {
1247 $$ = scm_list_4 (scm_car ($2),
1248 ly_symbol2scm ("RevertProperty"),
1252 | SET context_prop_spec '=' scalar {
1253 $$ = scm_list_4 (scm_car ($2),
1254 ly_symbol2scm ("PropertySet"),
1258 | UNSET context_prop_spec {
1259 $$ = scm_list_3 (scm_car ($2),
1260 ly_symbol2scm ("PropertyUnset"),
1266 simple_music_property_def {
1267 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1269 | ONCE simple_music_property_def {
1270 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1278 | STRING_IDENTIFIER {
1281 | string '+' string {
1282 $$ = scm_string_append (scm_list_2 ($1, $3));
1286 simple_string: STRING {
1292 | STRING_IDENTIFIER {
1313 $$ = scm_from_int ($1);
1318 /* TODO: Create a special case that avoids the creation of
1319 EventChords around simple_elements that have no post_events?
1321 simple_chord_elements post_events {
1322 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1325 /* why is this giving wrong start location? -ns
1327 i.set_location (@1, @2);
1328 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1330 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1332 i.set_location (@1, @3);
1333 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2, $3);
1336 | note_chord_element
1341 chord_body optional_notemode_duration post_events
1343 Music *m = unsmob_music ($1);
1344 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1345 SCM es = m->get_property ("elements");
1346 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1348 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1349 unsmob_music (scm_car (s))->set_property ("duration", dur);
1350 es = ly_append2 (es, postevs);
1352 m-> set_property ("elements", es);
1354 $$ = m->self_scm ();
1359 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1361 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1365 chord_body_elements:
1366 /* empty */ { $$ = SCM_EOL; }
1367 | chord_body_elements chord_body_element {
1368 $$ = scm_cons ($2, $1);
1373 pitch exclamations questions octave_check post_events
1380 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1381 n->set_property ("pitch", $1);
1384 n->set_property ("cautionary", SCM_BOOL_T);
1385 if (ex % 2 || q % 2)
1386 n->set_property ("force-accidental", SCM_BOOL_T);
1388 if (scm_is_pair (post)) {
1389 SCM arts = scm_reverse_x (post, SCM_EOL);
1390 n->set_property ("articulations", arts);
1392 if (scm_is_number (check))
1394 int q = scm_to_int (check);
1395 n->set_property ("absolute-octave", scm_from_int (q-1));
1398 $$ = n->unprotect ();
1400 | DRUM_PITCH post_events {
1401 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1402 n->set_property ("duration", $2);
1403 n->set_property ("drum-type", $1);
1406 if (scm_is_pair ($2)) {
1407 SCM arts = scm_reverse_x ($2, SCM_EOL);
1408 n->set_property ("articulations", arts);
1410 $$ = n->unprotect ();
1412 | music_function_chord_body {
1413 $$ = run_music_function (PARSER, $1);
1417 music_function_chord_body:
1418 music_function_musicless_function {
1421 | music_function_musicless_prefix chord_body_element {
1422 $$ = ly_append2 ($1, scm_list_1 ($2));
1426 music_function_event:
1427 music_function_musicless_prefix post_event {
1428 $$ = ly_append2 ($1, scm_list_1 ($2));
1430 | music_function_musicless_function {
1440 | SKIP duration_length {
1441 $$ = MAKE_SYNTAX ("skip-music", @$, $2);
1444 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1445 m->set_property ("span-direction", scm_from_int (START));
1447 $$ = m->unprotect();
1450 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1451 m->set_property ("span-direction", scm_from_int (STOP));
1453 $$ = m->unprotect ();
1456 $$ = MAKE_SYNTAX ("voice-separator", @$, SCM_UNDEFINED);
1459 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1461 Music *m = unsmob_music (pipe);
1466 $$ = m->unprotect ();
1469 $$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
1472 | PARTIAL duration_length {
1473 Moment m = - unsmob_duration ($2)->get_length ();
1474 $$ = MAKE_SYNTAX ("property-operation", @$, SCM_BOOL_F, ly_symbol2scm ("Timing"), ly_symbol2scm ("PropertySet"), ly_symbol2scm ("measurePosition"), m.smobbed_copy ());
1475 $$ = MAKE_SYNTAX ("context-specification", @$, ly_symbol2scm ("Score"), SCM_BOOL_F, $$, SCM_EOL, SCM_BOOL_F);
1479 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1481 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1484 SCM proc = ly_lily_module_constant ("make-mark-set");
1486 $$ = scm_call_1 (proc, $2);
1492 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent")->unprotect ();
1495 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1496 $$ = m->unprotect ();
1502 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1503 $$ = key->unprotect ();
1505 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1507 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1508 if (scm_ilength ($3) > 0)
1510 key->set_property ("pitch-alist", $3);
1511 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1512 key->transpose (* unsmob_pitch ($2));
1514 PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1517 $$ = key->unprotect ();
1526 | post_events post_event {
1527 unsmob_music ($2)->set_spot (@2);
1528 $$ = scm_cons ($2, $$);
1533 direction_less_event {
1536 | '-' music_function_event {
1537 $$ = run_music_function (PARSER, $2);
1540 if (!PARSER->lexer_->is_lyric_state ())
1541 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1542 $$ = MY_MAKE_MUSIC ("HyphenEvent")->unprotect ();
1545 if (!PARSER->lexer_->is_lyric_state ())
1546 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1547 $$ = MY_MAKE_MUSIC ("ExtenderEvent")->unprotect ();
1549 | script_dir direction_reqd_event {
1552 Music *m = unsmob_music ($2);
1553 m->set_property ("direction", scm_from_int ($1));
1557 | script_dir direction_less_event {
1560 Music *m = unsmob_music ($2);
1561 m->set_property ("direction", scm_from_int ($1));
1565 | string_number_event
1568 string_number_event:
1570 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1571 s->set_property ("string-number", scm_from_int ($1));
1573 $$ = s->unprotect ();
1577 direction_less_char:
1579 $$ = ly_symbol2scm ("bracketOpenSymbol");
1582 $$ = ly_symbol2scm ("bracketCloseSymbol");
1585 $$ = ly_symbol2scm ("tildeSymbol");
1588 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1591 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1594 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1597 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1600 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1603 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1606 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1610 direction_less_event:
1611 direction_less_char {
1612 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
1614 if (unsmob_music (predefd))
1616 m = unsmob_music (predefd)->clone ();
1620 m = MY_MAKE_MUSIC ("Music");
1623 $$ = m->unprotect ();
1625 | EVENT_IDENTIFIER {
1629 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1631 a->set_property ("tremolo-type", scm_from_int ($1));
1632 $$ = a->unprotect ();
1636 direction_reqd_event:
1640 | script_abbreviation {
1641 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1642 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1643 if (scm_is_string (s))
1644 a->set_property ("articulation-type", s);
1645 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
1646 $$ = a->unprotect ();
1651 /**/ { $$ = SCM_EOL; }
1652 | '=' { $$ = scm_from_int (0); }
1653 | '=' sub_quotes { $$ = scm_from_int ($2); }
1654 | '=' sup_quotes { $$ = scm_from_int ($2); }
1679 | NOTENAME_PITCH sup_quotes {
1680 Pitch p = *unsmob_pitch ($1);
1681 p = p.transposed (Pitch ($2,0,0));
1682 $$ = p.smobbed_copy ();
1684 | NOTENAME_PITCH sub_quotes {
1685 Pitch p =* unsmob_pitch ($1);
1686 p = p.transposed (Pitch (-$2,0,0));
1687 $$ = p.smobbed_copy ();
1699 | TONICNAME_PITCH sup_quotes {
1700 Pitch p = *unsmob_pitch ($1);
1701 p = p.transposed (Pitch ($2,0,0));
1702 $$ = p.smobbed_copy ();
1704 | TONICNAME_PITCH sub_quotes {
1705 Pitch p =* unsmob_pitch ($1);
1707 p = p.transposed (Pitch (-$2,0,0));
1708 $$ = p.smobbed_copy ();
1718 pitch_also_in_chords:
1725 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1726 t->set_property ("text", $1);
1728 $$ = t->unprotect ();
1731 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1732 t->set_property ("text",
1733 make_simple_markup ($1));
1735 $$ = t->unprotect ();
1738 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1739 t->set_property ("digit", scm_from_int ($1));
1741 $$ = t->unprotect ();
1745 script_abbreviation:
1747 $$ = scm_makfrom0str ("Hat");
1750 $$ = scm_makfrom0str ("Plus");
1753 $$ = scm_makfrom0str ("Dash");
1756 $$ = scm_makfrom0str ("Bar");
1759 $$ = scm_makfrom0str ("Larger");
1762 $$ = scm_makfrom0str ("Dot");
1765 $$ = scm_makfrom0str ("Underscore");
1772 | '-' { $$ = CENTER; }
1783 multiplied_duration {
1788 optional_notemode_duration:
1790 Duration dd = PARSER->default_duration_;
1791 $$ = dd.smobbed_copy ();
1793 | multiplied_duration {
1795 PARSER->default_duration_ = *unsmob_duration ($$);
1800 bare_unsigned dots {
1802 if (!is_duration ($1))
1803 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
1807 $$ = Duration (len, $2).smobbed_copy ();
1809 | DURATION_IDENTIFIER dots {
1810 Duration *d = unsmob_duration ($1);
1811 Duration k (d->duration_log (), d->dot_count () + $2);
1817 multiplied_duration:
1821 | multiplied_duration '*' bare_unsigned {
1822 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1824 | multiplied_duration '*' FRACTION {
1825 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1827 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1832 FRACTION { $$ = $1; }
1833 | UNSIGNED '/' UNSIGNED {
1834 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
1851 | ':' bare_unsigned {
1852 if (!is_duration ($2))
1853 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
1860 $$ = scm_from_int ($1);
1863 $$ = scm_from_int ($1);
1865 | STRING { $$ = $1; }
1866 | full_markup { $$ = $1; }
1869 figured_bass_alteration:
1877 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
1878 $$ = bfr->self_scm ();
1883 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
1884 $$ = bfr->self_scm ();
1886 if (scm_is_number ($1))
1887 bfr->set_property ("figure", $1);
1888 else if (Text_interface::is_markup ($1))
1889 bfr->set_property ("text", $1);
1896 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
1898 | bass_figure figured_bass_alteration {
1899 Music *m = unsmob_music ($1);
1901 SCM salter = m->get_property ("alteration");
1902 int alter = scm_is_number (salter) ? scm_to_int (salter) : 0;
1903 m->set_property ("alteration",
1904 scm_from_int (alter + $2));
1906 m->set_property ("alteration", scm_from_int (0));
1909 | bass_figure figured_bass_modification {
1910 Music *m = unsmob_music ($1);
1911 if ($2 == ly_symbol2scm ("plus"))
1913 m->set_property ("augmented", SCM_BOOL_T);
1915 else if ($2 == ly_symbol2scm ("slash"))
1917 m->set_property ("diminished", SCM_BOOL_T);
1919 else if ($2 == ly_symbol2scm ("exclamation"))
1921 m->set_property ("no-continuation", SCM_BOOL_T);
1927 figured_bass_modification:
1929 $$ = ly_symbol2scm ("plus");
1932 $$ = ly_symbol2scm ("exclamation");
1935 $$ = ly_symbol2scm ("slash");
1945 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
1953 | figure_list br_bass_figure {
1954 $$ = scm_cons ($2, $1);
1959 FIGURE_OPEN figure_list FIGURE_CLOSE {
1960 $$ = scm_reverse_x ($2, SCM_EOL);
1971 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
1972 if (!PARSER->lexer_->is_note_state ())
1973 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
1977 n = MY_MAKE_MUSIC ("RestEvent");
1979 n = MY_MAKE_MUSIC ("NoteEvent");
1981 n->set_property ("pitch", $1);
1982 n->set_property ("duration", $5);
1984 if (scm_is_number ($4))
1986 int q = scm_to_int ($4);
1987 n->set_property ("absolute-octave", scm_from_int (q-1));
1991 n->set_property ("cautionary", SCM_BOOL_T);
1992 if ($2 % 2 || $3 % 2)
1993 n->set_property ("force-accidental", SCM_BOOL_T);
1996 $$ = n->unprotect ();
1998 | DRUM_PITCH optional_notemode_duration {
1999 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2000 n->set_property ("duration", $2);
2001 n->set_property ("drum-type", $1);
2003 $$ = n->unprotect ();
2005 | RESTNAME optional_notemode_duration {
2007 if (ly_scm2string ($1) == "s") {
2009 ev = MY_MAKE_MUSIC ("SkipEvent");
2012 ev = MY_MAKE_MUSIC ("RestEvent");
2015 ev->set_property ("duration", $2);
2017 $$ = ev->unprotect ();
2019 | lyric_element optional_notemode_duration {
2020 if (!PARSER->lexer_->is_lyric_state ())
2021 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2023 Music *levent = MY_MAKE_MUSIC ("LyricEvent");
2024 levent->set_property ("text", $1);
2025 levent->set_property ("duration",$2);
2026 levent->set_spot (@$);
2027 $$= levent->unprotect ();
2031 simple_chord_elements:
2033 $$ = scm_list_1 ($1);
2036 if (!PARSER->lexer_->is_chord_state ())
2037 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2040 | figure_spec optional_notemode_duration {
2041 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2043 unsmob_music (scm_car (s))->set_property ("duration", $2);
2059 steno_tonic_pitch optional_notemode_duration {
2060 $$ = make_chord_elements ($1, $2, SCM_EOL);
2062 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2063 SCM its = scm_reverse_x ($4, SCM_EOL);
2064 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2072 | chord_items chord_item {
2073 $$ = scm_cons ($2, $$);
2079 $$ = ly_symbol2scm ("chord-colon");
2082 $$ = ly_symbol2scm ("chord-caret");
2084 | CHORD_SLASH steno_tonic_pitch {
2085 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2087 | CHORD_BASS steno_tonic_pitch {
2088 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2097 $$ = scm_reverse_x ($1, SCM_EOL);
2105 step_number { $$ = scm_cons ($1, SCM_EOL); }
2106 | step_numbers '.' step_number {
2107 $$ = scm_cons ($3, $$);
2113 $$ = make_chord_step ($1, 0);
2115 | bare_unsigned '+' {
2116 $$ = make_chord_step ($1, SHARP);
2118 | bare_unsigned CHORD_MINUS {
2119 $$ = make_chord_step ($1, FLAT);
2126 TODO: should deprecate in favor of Scheme?
2130 number_expression '+' number_term {
2131 $$ = scm_sum ($1, $3);
2133 | number_expression '-' number_term {
2134 $$ = scm_difference ($1, $3);
2143 | number_factor '*' number_factor {
2144 $$ = scm_product ($1, $3);
2146 | number_factor '/' number_factor {
2147 $$ = scm_divide ($1, $3);
2152 '-' number_factor { /* %prec UNARY_MINUS */
2153 $$ = scm_difference ($2, SCM_UNDEFINED);
2161 $$ = scm_from_int ($1);
2166 | NUMBER_IDENTIFIER {
2169 | REAL NUMBER_IDENTIFIER {
2170 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2172 | UNSIGNED NUMBER_IDENTIFIER {
2173 $$ = scm_from_double ($1 *scm_to_double ($2));
2189 | exclamations '!' { $$ ++; }
2194 | questions '?' { $$ ++; }
2198 This should be done more dynamically if possible.
2202 LYRIC_MARKUP_IDENTIFIER {
2206 { PARSER->lexer_->push_markup_state (); }
2209 PARSER->lexer_->pop_state ();
2218 { PARSER->lexer_->push_markup_state (); }
2221 PARSER->lexer_->pop_state ();
2227 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2229 | markup_head_1_list simple_markup {
2230 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2238 markup_composed_list {
2241 | markup_braced_list {
2246 markup_composed_list:
2247 markup_head_1_list markup_braced_list {
2248 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2254 '{' markup_braced_list_body '}' {
2255 $$ = scm_reverse_x ($2, SCM_EOL);
2259 markup_braced_list_body:
2260 /* empty */ { $$ = SCM_EOL; }
2261 | markup_braced_list_body markup {
2262 $$ = scm_cons ($2, $1);
2264 | markup_braced_list_body markup_list {
2265 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2270 MARKUP_HEAD_MARKUP0 {
2271 $$ = scm_list_1 ($1);
2273 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2274 $$ = scm_list_2 ($1, $2);
2276 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2277 $$ = scm_list_3 ($1, $2, $3);
2282 markup_head_1_item {
2283 $$ = scm_list_1 ($1);
2285 | markup_head_1_list markup_head_1_item {
2286 $$ = scm_cons ($2, $1);
2292 $$ = make_simple_markup ($1);
2294 | MARKUP_IDENTIFIER {
2297 | LYRIC_MARKUP_IDENTIFIER {
2300 | STRING_IDENTIFIER {
2304 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2305 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2306 } '{' score_body '}' {
2308 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2310 PARSER->lexer_->pop_state ();
2312 | MARKUP_HEAD_SCM0 embedded_scm {
2313 $$ = scm_list_2 ($1, $2);
2315 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2316 $$ = scm_list_4 ($1, $2, $3, $4);
2318 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2319 $$ = scm_list_3 ($1, $2, $3);
2321 | MARKUP_HEAD_EMPTY {
2322 $$ = scm_list_1 ($1);
2324 | MARKUP_HEAD_LIST0 markup_list {
2325 $$ = scm_list_2 ($1,$2);
2327 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2328 $$ = scm_list_3 ($1, $2, $3);
2333 markup_head_1_list simple_markup {
2334 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2335 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2345 Lily_parser::set_yydebug (bool )
2353 Lily_parser::do_yyparse ()
2355 yyparse ((void*)this);
2364 It is a little strange to have this function in this file, but
2365 otherwise, we have to import music classes into the lexer.
2369 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2371 if (scm_is_string (sid)) {
2373 return STRING_IDENTIFIER;
2374 } else if (unsmob_book (sid)) {
2375 *destination = unsmob_book (sid)->clone ()->self_scm ();
2376 return BOOK_IDENTIFIER;
2377 } else if (scm_is_number (sid)) {
2379 return NUMBER_IDENTIFIER;
2380 } else if (unsmob_context_def (sid)) {
2381 *destination = unsmob_context_def (sid)->clone_scm ();
2382 return CONTEXT_DEF_IDENTIFIER;
2383 } else if (unsmob_score (sid)) {
2384 Score *score = new Score (*unsmob_score (sid));
2385 *destination = score->self_scm ();
2386 return SCORE_IDENTIFIER;
2387 } else if (Music *mus = unsmob_music (sid)) {
2388 mus = mus->clone ();
2389 *destination = mus->self_scm ();
2390 unsmob_music (*destination)->
2391 set_property ("origin", make_input (last_input_));
2393 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2396 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2397 } else if (unsmob_duration (sid)) {
2398 *destination = unsmob_duration (sid)->smobbed_copy ();
2399 return DURATION_IDENTIFIER;
2400 } else if (unsmob_output_def (sid)) {
2401 Output_def *p = unsmob_output_def (sid);
2404 *destination = p->self_scm ();
2405 return OUTPUT_DEF_IDENTIFIER;
2406 } else if (Text_interface::is_markup (sid)) {
2408 if (is_lyric_state ())
2409 return LYRIC_MARKUP_IDENTIFIER;
2410 return MARKUP_IDENTIFIER;
2417 get_next_unique_context_id ()
2419 return scm_makfrom0str ("$uniqueContextId");
2424 get_next_unique_lyrics_context_id ()
2426 static int new_context_count;
2428 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2429 return scm_makfrom0str (s);
2434 run_music_function (Lily_parser *parser, SCM expr)
2436 SCM func = scm_car (expr);
2437 Input *loc = unsmob_input (scm_cadr (expr));
2438 SCM args = scm_cddr (expr);
2439 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2441 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2443 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2445 parser->error_level_ = 1;
2446 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (*loc)));
2449 SCM syntax_args = scm_list_4 (parser->self_scm (), make_input (*loc), func, args);
2450 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
2454 is_regular_identifier (SCM id)
2456 string str = ly_scm2string (id);
2457 char const *s = str.c_str ();
2466 v = v && isalnum (*s);
2474 get_first_context_id (SCM type, Music *m)
2476 SCM id = m->get_property ("context-id");
2477 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2478 && scm_is_string (m->get_property ("context-id"))
2479 && scm_c_string_length (id) > 0)
2487 make_simple_markup (SCM a)
2495 return t && t == 1 << intlog2 (t);
2499 set_music_properties (Music *p, SCM a)
2501 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2502 p->internal_set_property (scm_caar (k), scm_cdar (k));
2507 make_chord_step (int step, int alter)
2514 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2515 return m.smobbed_copy ();
2520 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
2522 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
2523 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
2527 /* Todo: actually also use apply iso. call too ... */
2529 ly_input_procedure_p (SCM x)
2531 return ly_is_procedure (x)
2532 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2536 make_music_relative (Pitch start, SCM music)
2538 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
2539 relative->set_property ("element", music);
2541 Music *m = unsmob_music (music);
2542 Pitch last = m->to_relative_octave (start);
2543 if (lily_1_8_relative)
2544 m->set_property ("last-pitch", last.smobbed_copy ());
2545 return relative->unprotect ();
2549 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2551 Lily_parser *pars = (Lily_parser*) v;
2552 Lily_lexer *lex = pars->lexer_;
2554 lex->lexval = (void*) s;
2556 lex->prepare_for_next_token ();
2557 return lex->yylex ();