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>
13 #define YYERROR_VERBOSE 1
14 #define YYPARSE_PARAM my_lily_parser
15 #define YYLEX_PARAM my_lily_parser
16 #define PARSER ((Lily_parser *) my_lily_parser)
18 #define yyerror PARSER->parser_error
20 /* We use custom location type: Input objects */
22 #define YYLLOC_DEFAULT(Current,Rhs,N) \
23 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
28 /* We use SCMs to do strings, because it saves us the trouble of
29 deleting them. Let's hope that a stack overflow doesnt trigger a move
30 of the parse stack onto the heap. */
38 /* One shift/reduce problem
41 \repeat .. \alternative
43 \repeat { \repeat .. \alternative }
47 \repeat { \repeat } \alternative
56 %{ // -*-Fundamental-*-
61 * The rules for who is protecting what are very shady. Uniformise
64 * There are too many lexical modes?
75 #include "context-def.hh"
76 #include "dimensions.hh"
77 #include "file-path.hh"
79 #include "international.hh"
80 #include "lily-guile.hh"
81 #include "lily-lexer.hh"
82 #include "lily-parser.hh"
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
256 %token <i> E_UNSIGNED
259 /* Artificial tokens, for more generic function syntax */
260 %token <i> EXPECT_MARKUP;
261 %token <i> EXPECT_MUSIC;
262 %token <i> EXPECT_SCM;
264 %token <scm> BOOK_IDENTIFIER
265 %token <scm> CHORDMODIFIER_PITCH
266 %token <scm> CHORD_MODIFIER
267 %token <scm> CONTEXT_DEF_IDENTIFIER
268 %token <scm> DRUM_PITCH
269 %token <scm> DURATION_IDENTIFIER
270 %token <scm> EVENT_IDENTIFIER
271 %token <scm> FRACTION
272 %token <scm> LYRICS_STRING
273 %token <scm> LYRIC_MARKUP_IDENTIFIER
274 %token <scm> MARKUP_HEAD_EMPTY
275 %token <scm> MARKUP_HEAD_LIST0
276 %token <scm> MARKUP_HEAD_MARKUP0
277 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
278 %token <scm> MARKUP_HEAD_SCM0
279 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
280 %token <scm> MARKUP_HEAD_SCM0_SCM1
281 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
282 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
283 %token <scm> MARKUP_IDENTIFIER
284 %token <scm> MUSIC_FUNCTION
285 %token <scm> MUSIC_IDENTIFIER
286 %token <scm> NOTENAME_PITCH
287 %token <scm> NUMBER_IDENTIFIER
288 %token <scm> OUTPUT_DEF_IDENTIFIER
290 %token <scm> RESTNAME
291 %token <scm> SCM_IDENTIFIER
292 %token <scm> SCM_TOKEN
293 %token <scm> SCORE_IDENTIFIER
295 %token <scm> STRING_IDENTIFIER
296 %token <scm> TONICNAME_PITCH
299 %type <book> book_block
300 %type <book> book_body
302 %type <i> bare_unsigned
303 %type <i> figured_bass_alteration
305 %type <i> exclamations
306 %type <i> optional_rest
311 %type <i> tremolo_type
314 %type <scm> composite_music
315 %type <scm> grouped_music_list
317 %type <scm> prefix_composite_music
318 %type <scm> repeated_music
319 %type <scm> sequential_music
320 %type <scm> simple_music
321 %type <scm> simultaneous_music
322 %type <scm> chord_body
323 %type <scm> chord_body_element
324 %type <scm> command_element
325 %type <scm> command_event
326 %type <scm> context_change
327 %type <scm> direction_less_event
328 %type <scm> direction_reqd_event
329 %type <scm> event_chord
330 %type <scm> gen_text_def
331 %type <scm> music_property_def
332 %type <scm> note_chord_element
333 %type <scm> post_event
334 %type <scm> re_rhythmed_music
335 %type <scm> relative_music
336 %type <scm> simple_element
337 %type <scm> simple_music_property_def
338 %type <scm> string_number_event
339 %type <scm> tempo_event
341 %type <outputdef> output_def_body
342 %type <outputdef> output_def_head
343 %type <outputdef> output_def_head_with_mode_switch
344 %type <outputdef> output_def
345 %type <outputdef> paper_block
347 %type <scm> alternative_music
348 %type <scm> generic_prefix_music_scm
349 %type <scm> music_list
350 %type <scm> absolute_pitch
351 %type <scm> assignment_id
352 %type <scm> bare_number
353 %type <scm> bass_figure
354 %type <scm> figured_bass_modification
355 %type <scm> br_bass_figure
356 %type <scm> bass_number
357 %type <scm> chord_body_elements
358 %type <scm> chord_item
359 %type <scm> chord_items
360 %type <scm> chord_separator
361 %type <scm> context_def_mod
362 %type <scm> context_def_spec_block
363 %type <scm> context_def_spec_body
364 %type <scm> context_mod
365 %type <scm> context_mod_list
366 %type <scm> context_prop_spec
367 %type <scm> direction_less_char
368 %type <scm> duration_length
369 %type <scm> embedded_scm
370 %type <scm> figure_list
371 %type <scm> figure_spec
373 %type <scm> full_markup
374 %type <scm> function_scm_argument
375 %type <scm> function_arglist
376 %type <scm> function_arglist_music_last
377 %type <scm> function_arglist_nonmusic_last
378 %type <scm> function_arglist_nonmusic
379 %type <scm> identifier_init
380 %type <scm> lilypond_header
381 %type <scm> lilypond_header_body
382 %type <scm> lyric_element
383 %type <scm> lyric_markup
385 %type <scm> markup_braced_list
386 %type <scm> markup_braced_list_body
387 %type <scm> markup_composed_list
388 %type <scm> markup_head_1_item
389 %type <scm> markup_head_1_list
390 %type <scm> markup_list
391 %type <scm> markup_top
392 %type <scm> mode_changing_head
393 %type <scm> mode_changing_head_with_context
394 %type <scm> multiplied_duration
395 %type <scm> music_function_identifier_musicless_prefix
396 %type <scm> music_function_event
397 %type <scm> music_function_chord_body
398 %type <scm> new_chord
399 %type <scm> new_lyrics
400 %type <scm> number_expression
401 %type <scm> number_factor
402 %type <scm> number_term
403 %type <scm> object_id_setting
404 %type <scm> octave_check
405 %type <scm> optional_context_mod
406 %type <scm> optional_id
407 %type <scm> optional_notemode_duration
409 %type <scm> pitch_also_in_chords
410 %type <scm> post_events
411 %type <scm> property_operation
413 %type <scm> script_abbreviation
414 %type <scm> simple_chord_elements
415 %type <scm> simple_markup
416 %type <scm> simple_string
417 %type <scm> steno_duration
418 %type <scm> steno_pitch
419 %type <scm> steno_tonic_pitch
420 %type <scm> step_number
421 %type <scm> step_numbers
424 %type <score> score_block
425 %type <score> score_body
430 /* We don't assign precedence to / and *, because we might need varied
431 prec levels in different prods */
437 lilypond: /* empty */
438 | lilypond toplevel_expression {
440 | lilypond assignment {
443 PARSER->error_level_ = 1;
446 PARSER->error_level_ = 1;
452 OBJECTID STRING { $$ = $2; }
457 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
461 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
462 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
468 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
469 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
473 Music *music = unsmob_music ($1);
474 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
475 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
478 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
479 scm_call_2 (proc, PARSER->self_scm (), $1);
483 Output_def * od = $1;
485 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
486 id = ly_symbol2scm ("$defaultpaper");
487 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
488 id = ly_symbol2scm ("$defaultmidi");
489 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
490 id = ly_symbol2scm ("$defaultlayout");
492 PARSER->lexer_->set_identifier (id, od->self_scm ());
503 lilypond_header_body:
505 $$ = get_header(PARSER);
506 PARSER->lexer_->add_scope ($$);
508 | lilypond_header_body assignment {
514 HEADER '{' lilypond_header_body '}' {
515 $$ = PARSER->lexer_->remove_scope ();
524 | LYRICS_STRING { $$ = $1; }
528 assignment_id '=' identifier_init {
529 PARSER->lexer_->set_identifier ($1, $3);
532 TODO: devise standard for protection in parser.
534 The parser stack lives on the C-stack, which means that
535 all objects can be unprotected as soon as they're here.
545 $$ = $1->self_scm ();
549 $$ = $1->self_scm ();
553 $$ = $1->self_scm ();
556 | context_def_spec_block {
560 /* Hack: Create event-chord around standalone events.
561 Prevents the identifier from being interpreted as a post-event. */
562 Music *mus = unsmob_music ($1);
563 bool is_event = mus &&
564 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
569 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
574 | number_expression {
587 $$ = scm_from_int ($1);
591 context_def_spec_block:
592 CONTEXT '{' context_def_spec_body '}'
598 context_def_spec_body:
600 $$ = Context_def::make_scm ();
601 unsmob_context_def ($$)->origin ()->set_spot (@$);
603 | CONTEXT_DEF_IDENTIFIER {
605 unsmob_context_def ($$)->origin ()->set_spot (@$);
607 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
608 Context_def*td = unsmob_context_def ($$);
610 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
611 SCM tag = scm_caar (p);
613 /* TODO: should make new tag "grob-definition" ? */
614 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
615 tag, scm_cons (scm_cdar (p), SCM_EOL)));
618 | context_def_spec_body context_mod {
619 unsmob_context_def ($$)->add_context_mod ($2);
626 BOOK '{' book_body '}' {
632 * Use 'handlers' like for toplevel-* stuff?
633 * grok \layout and \midi? */
637 $$->origin ()->set_spot (@$);
638 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
639 $$->paper_->unprotect ();
640 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
643 $$ = unsmob_book ($1);
645 $$->origin ()->set_spot (@$);
647 | book_body paper_block {
651 | book_body score_block {
652 SCM s = $2->self_scm ();
656 | book_body full_markup {
659 | book_body lilypond_header {
664 $$->scores_ = SCM_EOL;
666 | book_body object_id_setting {
667 $$->user_key_ = ly_scm2string ($2);
672 SCORE '{' score_body '}' {
680 SCM scorify = ly_lily_module_constant ("scorify-music");
681 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
683 // pass ownernship to C++ again.
684 $$ = unsmob_score (score);
686 $$->origin ()->set_spot (@$);
689 $$ = unsmob_score ($1);
691 $$->origin ()->set_spot (@$);
693 | score_body object_id_setting {
694 $$->user_key_ = ly_scm2string ($2);
696 | score_body lilypond_header {
699 | score_body output_def {
700 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
702 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
707 $$->add_output_def ($2);
712 $$->error_found_ = true;
724 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
726 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
728 $$ = get_paper (PARSER);
735 output_def_body '}' {
738 PARSER->lexer_->remove_scope ();
739 PARSER->lexer_->pop_state ();
745 $$ = get_paper (PARSER);
746 $$->input_origin_ = @$;
747 PARSER->lexer_->add_scope ($$->scope_);
750 Output_def *p = get_midi (PARSER);
752 PARSER->lexer_->add_scope (p->scope_);
755 Output_def *p = get_layout (PARSER);
757 PARSER->lexer_->add_scope (p->scope_);
762 output_def_head_with_mode_switch:
764 PARSER->lexer_->push_initial_state ();
770 output_def_head_with_mode_switch '{' {
772 $$->input_origin_.set_spot (@$);
774 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
777 Output_def *o = unsmob_output_def ($3);
778 o->input_origin_.set_spot (@$);
781 PARSER->lexer_->remove_scope ();
782 PARSER->lexer_->add_scope (o->scope_);
784 | output_def_body assignment {
787 | output_def_body context_def_spec_block {
788 assign_context_def ($$, $2);
790 | output_def_body error {
796 TEMPO steno_duration '=' bare_unsigned {
797 $$ = MAKE_SYNTAX ("tempo", @$, $2, scm_int2num ($4));
802 The representation of a list is the
806 to have efficient append. */
810 $$ = scm_cons (SCM_EOL, SCM_EOL);
814 SCM c = scm_cons ($2, SCM_EOL);
816 if (scm_is_pair (scm_cdr (s)))
817 scm_set_cdr_x (scm_cdr (s), c); /* append */
819 scm_set_car_x (s, c); /* set first cons */
820 scm_set_cdr_x (s, c); /* remember last cell */
822 | music_list embedded_scm {
826 Music *m = MY_MAKE_MUSIC("Music");
828 m->set_property ("error-found", SCM_BOOL_T);
830 SCM c = scm_cons (m->self_scm (), SCM_EOL);
831 m->unprotect (); /* UGH */
833 if (scm_is_pair (scm_cdr (s)))
834 scm_set_cdr_x (scm_cdr (s), c); /* append */
836 scm_set_car_x (s, c); /* set first cons */
837 scm_set_cdr_x (s, c); /* remember last cell */
850 | ALTERNATIVE '{' music_list '}' {
857 REPEAT simple_string bare_unsigned music alternative_music
859 $$ = MAKE_SYNTAX ("repeat", @$, $2, scm_int2num ($3), $4, $5);
864 SEQUENTIAL '{' music_list '}' {
865 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($3));
867 | '{' music_list '}' {
868 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($2));
873 SIMULTANEOUS '{' music_list '}'{
874 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($3));
876 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
877 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($2));
888 optional_context_mod:
889 /**/ { $$ = SCM_EOL; }
890 | WITH { PARSER->lexer_->push_initial_state (); }
891 '{' context_mod_list '}'
893 PARSER->lexer_->pop_state ();
899 /* */ { $$ = SCM_EOL; }
900 | context_mod_list context_mod {
901 $$ = scm_cons ($2, $1);
906 prefix_composite_music { $$ = $1; }
907 | grouped_music_list { $$ = $1; }
911 simultaneous_music { $$ = $1; }
912 | sequential_music { $$ = $1; }
915 function_scm_argument:
920 /* An argument list. If a function \foo expects scm scm music, then the lexer expands \foo into the token sequence:
921 MUSIC_FUNCTION EXPECT_MUSIC EXPECT_SCM EXPECT_SCM
922 and this rule returns the reversed list of arguments. */
924 function_arglist_music_last:
925 EXPECT_MUSIC function_arglist music {
926 $$ = scm_cons ($3, $2);
930 function_arglist_nonmusic_last:
931 EXPECT_MARKUP function_arglist full_markup {
932 $$ = scm_cons ($3, $2);
934 | EXPECT_SCM function_arglist function_scm_argument {
935 $$ = scm_cons ($3, $2);
939 function_arglist_nonmusic: /*empty*/ {
942 | EXPECT_MARKUP function_arglist_nonmusic full_markup {
943 $$ = scm_cons ($3, $2);
945 | EXPECT_SCM function_arglist_nonmusic function_scm_argument {
946 $$ = scm_cons ($3, $2);
950 function_arglist: /*empty*/ {
953 | function_arglist_music_last
954 | function_arglist_nonmusic_last
957 generic_prefix_music_scm:
958 MUSIC_FUNCTION function_arglist {
959 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
965 /**/ { $$ = SCM_EOL; }
966 | '=' simple_string {
972 prefix_composite_music:
973 generic_prefix_music_scm {
974 $$ = run_music_function (PARSER, $1);
976 | CONTEXT simple_string optional_id optional_context_mod music {
977 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_F);
979 | NEWCONTEXT simple_string optional_id optional_context_mod music {
980 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_T);
983 | TIMES fraction music {
984 $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3);
986 | repeated_music { $$ = $1; }
987 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords music {
988 Pitch from = *unsmob_pitch ($2);
989 Pitch to = *unsmob_pitch ($3);
990 SCM pitch = pitch_interval (from, to).smobbed_copy ();
991 $$ = MAKE_SYNTAX ("transpose-music", @$, pitch, $4);
993 | mode_changing_head grouped_music_list {
994 if ($1 == ly_symbol2scm ("chords"))
996 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1002 PARSER->lexer_->pop_state ();
1004 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1005 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, $3, $2, SCM_BOOL_T);
1006 if ($1 == ly_symbol2scm ("ChordNames"))
1008 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1010 PARSER->lexer_->pop_state ();
1012 | relative_music { $$ = $1; }
1013 | re_rhythmed_music { $$ = $1; }
1018 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1019 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1021 $$ = ly_symbol2scm ("notes");
1025 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1026 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1028 $$ = ly_symbol2scm ("drums");
1031 PARSER->lexer_->push_figuredbass_state ();
1033 $$ = ly_symbol2scm ("figures");
1036 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1037 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1038 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1039 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1040 $$ = ly_symbol2scm ("chords");
1044 { PARSER->lexer_->push_lyric_state ();
1045 $$ = ly_symbol2scm ("lyrics");
1049 mode_changing_head_with_context:
1051 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1052 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1054 $$ = ly_symbol2scm ("DrumStaff");
1057 PARSER->lexer_->push_figuredbass_state ();
1059 $$ = ly_symbol2scm ("FiguredBass");
1062 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1063 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1064 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1065 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1066 $$ = ly_symbol2scm ("ChordNames");
1069 { PARSER->lexer_->push_lyric_state ();
1070 $$ = ly_symbol2scm ("Lyrics");
1076 RELATIVE absolute_pitch music {
1077 Pitch start = *unsmob_pitch ($2);
1078 $$ = make_music_relative (start, $3);
1080 | RELATIVE composite_music {
1081 Pitch middle_c (0, 0, 0);
1082 $$ = make_music_relative (middle_c, $2);
1087 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1089 grouped_music_list {
1090 /* Can also use music at the expensive of two S/Rs similar to
1091 \repeat \alternative */
1092 PARSER->lexer_->pop_state ();
1094 $$ = scm_cons ($3, SCM_EOL);
1096 | new_lyrics ADDLYRICS {
1097 PARSER->lexer_->push_lyric_state ();
1098 } grouped_music_list {
1099 PARSER->lexer_->pop_state ();
1100 $$ = scm_cons ($4, $1);
1105 grouped_music_list new_lyrics {
1106 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1108 | LYRICSTO simple_string {
1109 PARSER->lexer_->push_lyric_state ();
1111 PARSER->lexer_->pop_state ();
1112 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1117 CHANGE STRING '=' STRING {
1118 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1124 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1125 scm_string_to_symbol ($1), $3);
1127 | UNSET simple_string {
1128 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1129 scm_string_to_symbol ($2));
1131 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1132 $$ = scm_list_4 (ly_symbol2scm ("push"),
1133 scm_string_to_symbol ($2), $5, $3);
1135 | OVERRIDE simple_string embedded_scm embedded_scm '=' embedded_scm {
1136 $$ = scm_list_5 (ly_symbol2scm ("push"),
1137 scm_string_to_symbol ($2), $6, $4, $3);
1139 | REVERT simple_string embedded_scm {
1140 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1141 scm_string_to_symbol ($2), $3);
1146 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1147 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1149 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1150 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1151 | DENIES { $$ = ly_symbol2scm ("denies"); }
1153 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1154 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1155 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1156 | NAME { $$ = ly_symbol2scm ("context-name"); }
1160 property_operation { $$ = $1; }
1161 | context_def_mod STRING {
1162 $$ = scm_list_2 ($1, $2);
1168 if (!is_regular_identifier ($1))
1170 @$.error (_("Grob name should be alphanumeric"));
1173 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1174 scm_string_to_symbol ($1));
1176 | simple_string '.' simple_string {
1177 $$ = scm_list_2 (scm_string_to_symbol ($1),
1178 scm_string_to_symbol ($3));
1182 simple_music_property_def:
1183 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1184 $$ = scm_list_5 (scm_car ($2),
1185 ly_symbol2scm ("OverrideProperty"),
1189 | OVERRIDE context_prop_spec embedded_scm embedded_scm '=' scalar {
1190 $$ = scm_list_n (scm_car ($2),
1191 ly_symbol2scm ("OverrideProperty"),
1193 $6, $4, $3, SCM_UNDEFINED);
1195 | REVERT context_prop_spec embedded_scm {
1196 $$ = scm_list_4 (scm_car ($2),
1197 ly_symbol2scm ("RevertProperty"),
1201 | SET context_prop_spec '=' scalar {
1202 $$ = scm_list_4 (scm_car ($2),
1203 ly_symbol2scm ("PropertySet"),
1207 | UNSET context_prop_spec {
1208 $$ = scm_list_3 (scm_car ($2),
1209 ly_symbol2scm ("PropertyUnset"),
1215 simple_music_property_def {
1216 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1218 | ONCE simple_music_property_def {
1219 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1227 | STRING_IDENTIFIER {
1230 | string '+' string {
1231 $$ = scm_string_append (scm_list_2 ($1, $3));
1235 simple_string: STRING {
1241 | STRING_IDENTIFIER {
1262 $$ = scm_from_int ($1);
1267 /* TODO: Create a special case that avoids the creation of
1268 EventChords around simple_elements that have no post_events?
1270 simple_chord_elements post_events {
1271 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1274 /* why is this giving wrong start location? -ns
1276 i.set_location (@1, @2);
1277 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1279 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1281 i.set_location (@1, @3);
1282 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2, $3);
1285 | note_chord_element
1290 chord_body optional_notemode_duration post_events
1292 Music *m = unsmob_music ($1);
1293 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1294 SCM es = m->get_property ("elements");
1295 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1297 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1298 unsmob_music (scm_car (s))->set_property ("duration", dur);
1299 es = ly_append2 (es, postevs);
1301 m-> set_property ("elements", es);
1303 $$ = m->self_scm ();
1308 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1310 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1314 chord_body_elements:
1315 /* empty */ { $$ = SCM_EOL; }
1316 | chord_body_elements chord_body_element {
1317 $$ = scm_cons ($2, $1);
1322 pitch exclamations questions octave_check post_events
1329 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1330 n->set_property ("pitch", $1);
1333 n->set_property ("cautionary", SCM_BOOL_T);
1334 if (ex % 2 || q % 2)
1335 n->set_property ("force-accidental", SCM_BOOL_T);
1337 if (scm_is_pair (post)) {
1338 SCM arts = scm_reverse_x (post, SCM_EOL);
1339 n->set_property ("articulations", arts);
1341 if (scm_is_number (check))
1343 int q = scm_to_int (check);
1344 n->set_property ("absolute-octave", scm_from_int (q-1));
1347 $$ = n->unprotect ();
1349 | DRUM_PITCH post_events {
1350 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1351 n->set_property ("duration", $2);
1352 n->set_property ("drum-type", $1);
1355 if (scm_is_pair ($2)) {
1356 SCM arts = scm_reverse_x ($2, SCM_EOL);
1357 n->set_property ("articulations", arts);
1359 $$ = n->unprotect ();
1361 | music_function_chord_body {
1362 $$ = run_music_function (PARSER, $1);
1366 music_function_identifier_musicless_prefix: MUSIC_FUNCTION {
1367 SCM sig = scm_object_property (yylval.scm, ly_symbol2scm ("music-function-signature"));
1368 if (scm_is_pair (sig) && to_boolean (scm_memq (ly_music_p_proc, scm_cdr (scm_reverse (sig)))))
1370 PARSER->parser_error (@$, "Music function applied to event may not have a Music argument, except as the last argument.");
1375 music_function_chord_body:
1376 /* We could allow chord functions to have multiple music arguments,
1377 but it's more consistent with music_function_event if we
1378 prohibit it here too */
1379 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic chord_body_element {
1380 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1382 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1383 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1387 music_function_event:
1388 /* Post-events can only have the last argument as music, without this
1389 restriction we get a shift/reduce conflict from e.g.
1390 c8-\partcombine c8 -. */
1391 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic post_event {
1392 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1394 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1395 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1403 | SKIP duration_length {
1404 $$ = MAKE_SYNTAX ("skip-music", @$, $2);
1407 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1408 m->set_property ("span-direction", scm_from_int (START));
1410 $$ = m->unprotect();
1413 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1414 m->set_property ("span-direction", scm_from_int (STOP));
1416 $$ = m->unprotect ();
1419 $$ = MAKE_SYNTAX ("voice-separator", @$, SCM_UNDEFINED);
1422 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1424 Music *m = unsmob_music (pipe);
1429 $$ = m->unprotect ();
1432 $$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
1435 | PARTIAL duration_length {
1436 Moment m = - unsmob_duration ($2)->get_length ();
1437 $$ = MAKE_SYNTAX ("property-operation", @$, SCM_BOOL_F, ly_symbol2scm ("Timing"), ly_symbol2scm ("PropertySet"), ly_symbol2scm ("measurePosition"), m.smobbed_copy ());
1438 $$ = MAKE_SYNTAX ("context-specification", @$, ly_symbol2scm ("Score"), SCM_BOOL_F, $$, SCM_EOL, SCM_BOOL_F);
1442 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1444 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1447 SCM proc = ly_lily_module_constant ("make-mark-set");
1449 $$ = scm_call_1 (proc, $2);
1455 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent")->unprotect ();
1458 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1459 $$ = m->unprotect ();
1465 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1466 $$ = key->unprotect ();
1468 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1470 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1471 if (scm_ilength ($3) > 0)
1473 key->set_property ("pitch-alist", $3);
1474 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1475 key->transpose (* unsmob_pitch ($2));
1477 PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1480 $$ = key->unprotect ();
1489 | post_events post_event {
1490 unsmob_music ($2)->set_spot (@2);
1491 $$ = scm_cons ($2, $$);
1496 direction_less_event {
1499 | '-' music_function_event {
1500 $$ = run_music_function (PARSER, $2);
1503 if (!PARSER->lexer_->is_lyric_state ())
1504 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1505 $$ = MY_MAKE_MUSIC ("HyphenEvent")->unprotect ();
1508 if (!PARSER->lexer_->is_lyric_state ())
1509 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1510 $$ = MY_MAKE_MUSIC ("ExtenderEvent")->unprotect ();
1512 | script_dir direction_reqd_event {
1515 Music *m = unsmob_music ($2);
1516 m->set_property ("direction", scm_from_int ($1));
1520 | script_dir direction_less_event {
1523 Music *m = unsmob_music ($2);
1524 m->set_property ("direction", scm_from_int ($1));
1528 | string_number_event
1531 string_number_event:
1533 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1534 s->set_property ("string-number", scm_from_int ($1));
1536 $$ = s->unprotect ();
1540 direction_less_char:
1542 $$ = ly_symbol2scm ("bracketOpenSymbol");
1545 $$ = ly_symbol2scm ("bracketCloseSymbol");
1548 $$ = ly_symbol2scm ("tildeSymbol");
1551 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1554 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1557 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1560 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1563 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1566 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1569 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1573 direction_less_event:
1574 direction_less_char {
1575 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
1577 if (unsmob_music (predefd))
1579 m = unsmob_music (predefd)->clone ();
1583 m = MY_MAKE_MUSIC ("Music");
1586 $$ = m->unprotect ();
1588 | EVENT_IDENTIFIER {
1592 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1594 a->set_property ("tremolo-type", scm_from_int ($1));
1595 $$ = a->unprotect ();
1599 direction_reqd_event:
1603 | script_abbreviation {
1604 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1605 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1606 if (scm_is_string (s))
1607 a->set_property ("articulation-type", s);
1608 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
1609 $$ = a->unprotect ();
1614 /**/ { $$ = SCM_EOL; }
1615 | '=' { $$ = scm_from_int (0); }
1616 | '=' sub_quotes { $$ = scm_from_int ($2); }
1617 | '=' sup_quotes { $$ = scm_from_int ($2); }
1642 | NOTENAME_PITCH sup_quotes {
1643 Pitch p = *unsmob_pitch ($1);
1644 p = p.transposed (Pitch ($2,0,0));
1645 $$ = p.smobbed_copy ();
1647 | NOTENAME_PITCH sub_quotes {
1648 Pitch p =* unsmob_pitch ($1);
1649 p = p.transposed (Pitch (-$2,0,0));
1650 $$ = p.smobbed_copy ();
1662 | TONICNAME_PITCH sup_quotes {
1663 Pitch p = *unsmob_pitch ($1);
1664 p = p.transposed (Pitch ($2,0,0));
1665 $$ = p.smobbed_copy ();
1667 | TONICNAME_PITCH sub_quotes {
1668 Pitch p =* unsmob_pitch ($1);
1670 p = p.transposed (Pitch (-$2,0,0));
1671 $$ = p.smobbed_copy ();
1681 pitch_also_in_chords:
1688 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1689 t->set_property ("text", $1);
1691 $$ = t->unprotect ();
1694 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1695 t->set_property ("text",
1696 make_simple_markup ($1));
1698 $$ = t->unprotect ();
1701 Music *t = MY_MAKE_MUSIC ("FingeringEvent");
1702 t->set_property ("digit", scm_from_int ($1));
1704 $$ = t->unprotect ();
1708 script_abbreviation:
1710 $$ = scm_makfrom0str ("Hat");
1713 $$ = scm_makfrom0str ("Plus");
1716 $$ = scm_makfrom0str ("Dash");
1719 $$ = scm_makfrom0str ("Bar");
1722 $$ = scm_makfrom0str ("Larger");
1725 $$ = scm_makfrom0str ("Dot");
1728 $$ = scm_makfrom0str ("Underscore");
1735 | '-' { $$ = CENTER; }
1746 multiplied_duration {
1751 optional_notemode_duration:
1753 Duration dd = PARSER->default_duration_;
1754 $$ = dd.smobbed_copy ();
1756 | multiplied_duration {
1758 PARSER->default_duration_ = *unsmob_duration ($$);
1763 bare_unsigned dots {
1765 if (!is_duration ($1))
1766 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
1770 $$ = Duration (len, $2).smobbed_copy ();
1772 | DURATION_IDENTIFIER dots {
1773 Duration *d = unsmob_duration ($1);
1774 Duration k (d->duration_log (), d->dot_count () + $2);
1780 multiplied_duration:
1784 | multiplied_duration '*' bare_unsigned {
1785 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1787 | multiplied_duration '*' FRACTION {
1788 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1790 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1795 FRACTION { $$ = $1; }
1796 | UNSIGNED '/' UNSIGNED {
1797 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
1814 | ':' bare_unsigned {
1815 if (!is_duration ($2))
1816 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
1823 $$ = scm_from_int ($1);
1826 $$ = scm_from_int ($1);
1828 | STRING { $$ = $1; }
1829 | full_markup { $$ = $1; }
1832 figured_bass_alteration:
1840 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
1841 $$ = bfr->self_scm ();
1846 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
1847 $$ = bfr->self_scm ();
1849 if (scm_is_number ($1))
1850 bfr->set_property ("figure", $1);
1851 else if (Text_interface::is_markup ($1))
1852 bfr->set_property ("text", $1);
1859 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
1861 | bass_figure figured_bass_alteration {
1862 Music *m = unsmob_music ($1);
1864 SCM salter = m->get_property ("alteration");
1865 int alter = scm_is_number (salter) ? scm_to_int (salter) : 0;
1866 m->set_property ("alteration",
1867 scm_from_int (alter + $2));
1869 m->set_property ("alteration", scm_from_int (0));
1872 | bass_figure figured_bass_modification {
1873 Music *m = unsmob_music ($1);
1874 if ($2 == ly_symbol2scm ("plus"))
1876 m->set_property ("augmented", SCM_BOOL_T);
1878 else if ($2 == ly_symbol2scm ("slash"))
1880 m->set_property ("diminished", SCM_BOOL_T);
1882 else if ($2 == ly_symbol2scm ("exclamation"))
1884 m->set_property ("no-continuation", SCM_BOOL_T);
1890 figured_bass_modification:
1892 $$ = ly_symbol2scm ("plus");
1895 $$ = ly_symbol2scm ("exclamation");
1898 $$ = ly_symbol2scm ("slash");
1908 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
1916 | figure_list br_bass_figure {
1917 $$ = scm_cons ($2, $1);
1922 FIGURE_OPEN figure_list FIGURE_CLOSE {
1923 $$ = scm_reverse_x ($2, SCM_EOL);
1934 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
1935 if (!PARSER->lexer_->is_note_state ())
1936 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
1940 n = MY_MAKE_MUSIC ("RestEvent");
1942 n = MY_MAKE_MUSIC ("NoteEvent");
1944 n->set_property ("pitch", $1);
1945 n->set_property ("duration", $5);
1947 if (scm_is_number ($4))
1949 int q = scm_to_int ($4);
1950 n->set_property ("absolute-octave", scm_from_int (q-1));
1954 n->set_property ("cautionary", SCM_BOOL_T);
1955 if ($2 % 2 || $3 % 2)
1956 n->set_property ("force-accidental", SCM_BOOL_T);
1959 $$ = n->unprotect ();
1961 | DRUM_PITCH optional_notemode_duration {
1962 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1963 n->set_property ("duration", $2);
1964 n->set_property ("drum-type", $1);
1966 $$ = n->unprotect ();
1968 | RESTNAME optional_notemode_duration {
1970 if (ly_scm2string ($1) == "s") {
1972 ev = MY_MAKE_MUSIC ("SkipEvent");
1975 ev = MY_MAKE_MUSIC ("RestEvent");
1978 ev->set_property ("duration", $2);
1980 $$ = ev->unprotect ();
1982 | lyric_element optional_notemode_duration {
1983 if (!PARSER->lexer_->is_lyric_state ())
1984 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1986 Music *levent = MY_MAKE_MUSIC ("LyricEvent");
1987 levent->set_property ("text", $1);
1988 levent->set_property ("duration",$2);
1989 levent->set_spot (@$);
1990 $$= levent->unprotect ();
1994 simple_chord_elements:
1996 $$ = scm_list_1 ($1);
1999 if (!PARSER->lexer_->is_chord_state ())
2000 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2003 | figure_spec optional_notemode_duration {
2004 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2006 unsmob_music (scm_car (s))->set_property ("duration", $2);
2022 steno_tonic_pitch optional_notemode_duration {
2023 $$ = make_chord_elements ($1, $2, SCM_EOL);
2025 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2026 SCM its = scm_reverse_x ($4, SCM_EOL);
2027 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2035 | chord_items chord_item {
2036 $$ = scm_cons ($2, $$);
2042 $$ = ly_symbol2scm ("chord-colon");
2045 $$ = ly_symbol2scm ("chord-caret");
2047 | CHORD_SLASH steno_tonic_pitch {
2048 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2050 | CHORD_BASS steno_tonic_pitch {
2051 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2060 $$ = scm_reverse_x ($1, SCM_EOL);
2068 step_number { $$ = scm_cons ($1, SCM_EOL); }
2069 | step_numbers '.' step_number {
2070 $$ = scm_cons ($3, $$);
2076 $$ = make_chord_step ($1, 0);
2078 | bare_unsigned '+' {
2079 $$ = make_chord_step ($1, SHARP);
2081 | bare_unsigned CHORD_MINUS {
2082 $$ = make_chord_step ($1, FLAT);
2089 TODO: should deprecate in favor of Scheme?
2093 number_expression '+' number_term {
2094 $$ = scm_sum ($1, $3);
2096 | number_expression '-' number_term {
2097 $$ = scm_difference ($1, $3);
2106 | number_factor '*' number_factor {
2107 $$ = scm_product ($1, $3);
2109 | number_factor '/' number_factor {
2110 $$ = scm_divide ($1, $3);
2115 '-' number_factor { /* %prec UNARY_MINUS */
2116 $$ = scm_difference ($2, SCM_UNDEFINED);
2124 $$ = scm_from_int ($1);
2129 | NUMBER_IDENTIFIER {
2132 | REAL NUMBER_IDENTIFIER {
2133 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2135 | UNSIGNED NUMBER_IDENTIFIER {
2136 $$ = scm_from_double ($1 *scm_to_double ($2));
2152 | exclamations '!' { $$ ++; }
2157 | questions '?' { $$ ++; }
2161 This should be done more dynamically if possible.
2165 LYRIC_MARKUP_IDENTIFIER {
2169 { PARSER->lexer_->push_markup_state (); }
2172 PARSER->lexer_->pop_state ();
2181 { PARSER->lexer_->push_markup_state (); }
2184 PARSER->lexer_->pop_state ();
2190 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2192 | markup_head_1_list simple_markup {
2193 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2201 markup_composed_list {
2204 | markup_braced_list {
2209 markup_composed_list:
2210 markup_head_1_list markup_braced_list {
2211 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2217 '{' markup_braced_list_body '}' {
2218 $$ = scm_reverse_x ($2, SCM_EOL);
2222 markup_braced_list_body:
2223 /* empty */ { $$ = SCM_EOL; }
2224 | markup_braced_list_body markup {
2225 $$ = scm_cons ($2, $1);
2227 | markup_braced_list_body markup_list {
2228 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2233 MARKUP_HEAD_MARKUP0 {
2234 $$ = scm_list_1 ($1);
2236 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2237 $$ = scm_list_2 ($1, $2);
2239 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2240 $$ = scm_list_3 ($1, $2, $3);
2245 markup_head_1_item {
2246 $$ = scm_list_1 ($1);
2248 | markup_head_1_list markup_head_1_item {
2249 $$ = scm_cons ($2, $1);
2255 $$ = make_simple_markup ($1);
2257 | MARKUP_IDENTIFIER {
2260 | LYRIC_MARKUP_IDENTIFIER {
2263 | STRING_IDENTIFIER {
2267 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2268 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2269 } '{' score_body '}' {
2271 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2273 PARSER->lexer_->pop_state ();
2275 | MARKUP_HEAD_SCM0 embedded_scm {
2276 $$ = scm_list_2 ($1, $2);
2278 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2279 $$ = scm_list_4 ($1, $2, $3, $4);
2281 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2282 $$ = scm_list_3 ($1, $2, $3);
2284 | MARKUP_HEAD_EMPTY {
2285 $$ = scm_list_1 ($1);
2287 | MARKUP_HEAD_LIST0 markup_list {
2288 $$ = scm_list_2 ($1,$2);
2290 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2291 $$ = scm_list_3 ($1, $2, $3);
2296 markup_head_1_list simple_markup {
2297 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2298 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2308 Lily_parser::set_yydebug (bool x)
2314 Lily_parser::do_yyparse ()
2316 yyparse ((void*)this);
2325 It is a little strange to have this function in this file, but
2326 otherwise, we have to import music classes into the lexer.
2330 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2332 if (scm_is_string (sid)) {
2334 return STRING_IDENTIFIER;
2335 } else if (unsmob_book (sid)) {
2336 Book *book = unsmob_book (sid)->clone ();
2337 *destination = book->self_scm ();
2340 return BOOK_IDENTIFIER;
2341 } else if (scm_is_number (sid)) {
2343 return NUMBER_IDENTIFIER;
2344 } else if (unsmob_context_def (sid)) {
2345 Context_def *def= unsmob_context_def (sid)->clone ();
2347 *destination = def->self_scm ();
2350 return CONTEXT_DEF_IDENTIFIER;
2351 } else if (unsmob_score (sid)) {
2352 Score *score = new Score (*unsmob_score (sid));
2353 *destination = score->self_scm ();
2355 score->unprotect ();
2356 return SCORE_IDENTIFIER;
2357 } else if (Music *mus = unsmob_music (sid)) {
2358 mus = mus->clone ();
2359 *destination = mus->self_scm ();
2360 unsmob_music (*destination)->
2361 set_property ("origin", make_input (last_input_));
2363 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2367 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2368 } else if (unsmob_duration (sid)) {
2369 *destination = unsmob_duration (sid)->smobbed_copy ();
2370 return DURATION_IDENTIFIER;
2371 } else if (unsmob_output_def (sid)) {
2372 Output_def *p = unsmob_output_def (sid);
2375 *destination = p->self_scm ();
2377 return OUTPUT_DEF_IDENTIFIER;
2378 } else if (Text_interface::is_markup (sid)) {
2380 if (is_lyric_state ())
2381 return LYRIC_MARKUP_IDENTIFIER;
2382 return MARKUP_IDENTIFIER;
2389 get_next_unique_context_id ()
2391 return scm_makfrom0str ("$uniqueContextId");
2396 get_next_unique_lyrics_context_id ()
2398 static int new_context_count;
2400 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2401 return scm_makfrom0str (s);
2406 run_music_function (Lily_parser *parser, SCM expr)
2408 SCM func = scm_car (expr);
2409 Input *loc = unsmob_input (scm_cadr (expr));
2410 SCM args = scm_cddr (expr);
2411 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2413 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2415 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2417 parser->error_level_ = 1;
2418 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (*loc)));
2421 SCM syntax_args = scm_list_4 (parser->self_scm (), make_input (*loc), func, args);
2422 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
2426 is_regular_identifier (SCM id)
2428 string str = ly_scm2string (id);
2429 char const *s = str.c_str ();
2438 v = v && isalnum (*s);
2446 get_first_context_id (SCM type, Music *m)
2448 SCM id = m->get_property ("context-id");
2449 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2450 && scm_is_string (m->get_property ("context-id"))
2451 && scm_c_string_length (id) > 0)
2459 make_simple_markup (SCM a)
2467 return t && t == 1 << intlog2 (t);
2471 set_music_properties (Music *p, SCM a)
2473 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2474 p->internal_set_property (scm_caar (k), scm_cdar (k));
2479 make_chord_step (int step, int alter)
2486 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2487 return m.smobbed_copy ();
2492 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
2494 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
2495 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
2499 /* Todo: actually also use apply iso. call too ... */
2501 ly_input_procedure_p (SCM x)
2503 return ly_is_procedure (x)
2504 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2508 make_music_relative (Pitch start, SCM music)
2510 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
2511 relative->set_property ("element", music);
2513 Music *m = unsmob_music (music);
2514 Pitch last = m->to_relative_octave (start);
2515 if (lily_1_8_relative)
2516 m->set_property ("last-pitch", last.smobbed_copy ());
2517 return relative->unprotect ();
2521 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2523 Lily_parser *pars = (Lily_parser*) v;
2524 Lily_lexer *lex = pars->lexer_;
2526 lex->lexval = (void*) s;
2528 lex->prepare_for_next_token ();
2529 return lex->yylex ();