2 parser.yy -- Bison/C++ parser for LilyPond
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
13 #define YYERROR_VERBOSE 1
14 #define YYPARSE_PARAM my_lily_parser
15 #define YYLEX_PARAM my_lily_parser
16 #define PARSER ((Lily_parser *) my_lily_parser)
18 #define yyerror PARSER->parser_error
20 /* We use custom location type: Input objects */
22 #define YYLLOC_DEFAULT(Current,Rhs,N) \
23 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
28 /* We use SCMs to do strings, because it saves us the trouble of
29 deleting them. Let's hope that a stack overflow doesnt trigger a move
30 of the parse stack onto the heap. */
38 /* One shift/reduce problem
41 \repeat .. \alternative
43 \repeat { \repeat .. \alternative }
47 \repeat { \repeat } \alternative
56 %{ // -*-Fundamental-*-
61 * The rules for who is protecting what are very shady. Uniformise
64 * There are too many lexical modes?
75 #include "context-def.hh"
76 #include "dimensions.hh"
77 #include "file-path.hh"
79 #include "international.hh"
80 #include "lily-guile.hh"
81 #include "lily-lexer.hh"
82 #include "lily-parser.hh"
87 #include "output-def.hh"
88 #include "paper-book.hh"
89 #include "program-option.hh"
90 #include "scm-hash.hh"
92 #include "text-interface.hh"
100 Output_def *outputdef;
110 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
113 - Don't use lily module, create a new module instead.
114 - delay application of the function
116 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
117 scm_apply_0 (proc, args)
118 /* Syntactic Sugar. */
119 #define MAKE_SYNTAX(name, location, ...) \
120 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location), __VA_ARGS__, SCM_UNDEFINED));
122 SCM get_next_unique_context_id ();
123 SCM get_next_unique_lyrics_context_id ();
130 #define _(x) gettext (x)
134 static Music *make_music_with_input (SCM name, Input where);
135 SCM make_music_relative (Pitch start, SCM music, Input loc);
136 SCM run_music_function (Lily_parser *, SCM expr);
137 SCM get_first_context_id (SCM type, Music *m);
138 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
139 SCM make_chord_step (int step, Rational alter);
140 SCM make_simple_markup (SCM a);
141 bool is_duration (int t);
142 bool is_regular_identifier (SCM id);
143 bool ly_input_procedure_p (SCM x);
144 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
145 void set_music_properties (Music *p, SCM a);
149 /* The third option is an alias that will be used to display the
150 syntax error. Bison CVS now correctly handles backslash escapes.
152 FIXME: Bison needs to translate some of these, eg, STRING.
156 /* Keyword tokens with plain escaped name. */
157 %token ACCEPTS "\\accepts"
158 %token ADDLYRICS "\\addlyrics"
159 %token ALIAS "\\alias"
160 %token ALTERNATIVE "\\alternative"
162 %token CHANGE "\\change"
163 %token CHORDMODE "\\chordmode"
164 %token CHORDS "\\chords"
165 %token CONSISTS "\\consists"
166 %token CONTEXT "\\context"
167 %token DEFAULT "\\default"
168 %token DEFAULTCHILD "\\defaultchild"
169 %token DENIES "\\denies"
170 %token DESCRIPTION "\\description"
171 %token DRUMMODE "\\drummode"
172 %token DRUMS "\\drums"
173 %token FIGUREMODE "\\figuremode"
174 %token FIGURES "\\figures"
175 %token GROBDESCRIPTIONS "\\grobdescriptions"
176 %token HEADER "\\header"
177 %token INVALID "\\invalid"
179 %token LAYOUT "\\layout"
180 %token LYRICMODE "\\lyricmode"
181 %token LYRICS "\\lyrics"
182 %token LYRICSTO "\\lyricsto"
184 %token MARKUP "\\markup"
185 %token MARKUPLINES "\\markuplines"
188 %token NOTEMODE "\\notemode"
189 %token OBJECTID "\\objectid"
190 %token OCTAVE "\\octave"
192 %token OVERRIDE "\\override"
193 %token PAPER "\\paper"
194 %token PARTIAL "\\partial"
195 %token RELATIVE "\\relative"
196 %token REMOVE "\\remove"
197 %token REPEAT "\\repeat"
199 %token REVERT "\\revert"
200 %token SCORE "\\score"
201 %token SEQUENTIAL "\\sequential"
203 %token SIMULTANEOUS "\\simultaneous"
205 %token TEMPO "\\tempo"
206 %token TIMES "\\times"
207 %token TRANSPOSE "\\transpose"
209 %token UNSET "\\unset"
212 /* Keyword token exceptions. */
213 %token TIME_T "\\time"
214 %token NEWCONTEXT "\\new"
217 /* Other string tokens. */
219 %token CHORD_BASS "/+"
220 %token CHORD_CARET "^"
221 %token CHORD_COLON ":"
222 %token CHORD_MINUS "-"
223 %token CHORD_SLASH "/"
224 %token ANGLE_OPEN "<"
225 %token ANGLE_CLOSE ">"
226 %token DOUBLE_ANGLE_OPEN "<<"
227 %token DOUBLE_ANGLE_CLOSE ">>"
228 %token E_BACKSLASH "\\"
229 %token E_ANGLE_CLOSE "\\>"
230 %token E_CHAR "\\C[haracter]"
232 %token E_EXCLAMATION "\\!"
233 %token E_BRACKET_OPEN "\\["
235 %token E_BRACKET_CLOSE "\\]"
236 %token E_ANGLE_OPEN "\\<"
242 If we give names, Bison complains.
244 %token FIGURE_CLOSE /* "\\>" */
245 %token FIGURE_OPEN /* "\\<" */
246 %token FIGURE_SPACE "_"
249 %token CHORDMODIFIERS
251 %token MULTI_MEASURE_REST
255 %token <i> E_UNSIGNED
258 /* Artificial tokens, for more generic function syntax */
259 %token <i> EXPECT_MARKUP;
260 %token <i> EXPECT_MUSIC;
261 %token <i> EXPECT_SCM;
262 /* After the last argument. */
263 %token <i> EXPECT_NO_MORE_ARGS;
265 %token <scm> BOOK_IDENTIFIER
266 %token <scm> CHORDMODIFIER_PITCH
267 %token <scm> CHORD_MODIFIER
268 %token <scm> CONTEXT_DEF_IDENTIFIER
269 %token <scm> DRUM_PITCH
270 %token <scm> DURATION_IDENTIFIER
271 %token <scm> EVENT_IDENTIFIER
272 %token <scm> FRACTION
273 %token <scm> LYRICS_STRING
274 %token <scm> LYRIC_MARKUP_IDENTIFIER
275 %token <scm> MARKUP_HEAD_EMPTY
276 %token <scm> MARKUP_HEAD_LIST0
277 %token <scm> MARKUP_HEAD_MARKUP0
278 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
279 %token <scm> MARKUP_HEAD_SCM0
280 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
281 %token <scm> MARKUP_HEAD_SCM0_SCM1
282 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
283 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2_MARKUP3
284 %token <scm> MARKUP_HEAD_SCM0_MARKUP1_MARKUP2
285 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
286 %token <scm> MARKUP_LIST_HEAD_EMPTY
287 %token <scm> MARKUP_LIST_HEAD_LIST0
288 %token <scm> MARKUP_LIST_HEAD_SCM0
289 %token <scm> MARKUP_LIST_HEAD_SCM0_LIST1
290 %token <scm> MARKUP_LIST_HEAD_SCM0_SCM1_LIST2
291 %token <scm> MARKUP_IDENTIFIER
292 %token <scm> MUSIC_FUNCTION
293 %token <scm> MUSIC_IDENTIFIER
294 %token <scm> NOTENAME_PITCH
295 %token <scm> NUMBER_IDENTIFIER
296 %token <scm> OUTPUT_DEF_IDENTIFIER
298 %token <scm> RESTNAME
299 %token <scm> SCM_IDENTIFIER
300 %token <scm> SCM_TOKEN
301 %token <scm> SCORE_IDENTIFIER
303 %token <scm> STRING_IDENTIFIER
304 %token <scm> TONICNAME_PITCH
307 %type <book> book_block
308 %type <book> book_body
310 %type <i> bare_unsigned
311 %type <scm> figured_bass_alteration
313 %type <i> exclamations
314 %type <i> optional_rest
319 %type <i> tremolo_type
322 %type <scm> composite_music
323 %type <scm> grouped_music_list
325 %type <scm> prefix_composite_music
326 %type <scm> repeated_music
327 %type <scm> sequential_music
328 %type <scm> simple_music
329 %type <scm> simultaneous_music
330 %type <scm> chord_body
331 %type <scm> chord_body_element
332 %type <scm> command_element
333 %type <scm> command_event
334 %type <scm> context_change
335 %type <scm> direction_less_event
336 %type <scm> direction_reqd_event
337 %type <scm> event_chord
338 %type <scm> gen_text_def
339 %type <scm> music_property_def
340 %type <scm> note_chord_element
341 %type <scm> post_event
342 %type <scm> re_rhythmed_music
343 %type <scm> relative_music
344 %type <scm> simple_element
345 %type <scm> simple_music_property_def
346 %type <scm> string_number_event
347 %type <scm> tempo_event
349 %type <outputdef> output_def_body
350 %type <outputdef> output_def_head
351 %type <outputdef> output_def_head_with_mode_switch
352 %type <outputdef> output_def
353 %type <outputdef> paper_block
355 %type <scm> alternative_music
356 %type <scm> generic_prefix_music_scm
357 %type <scm> music_list
358 %type <scm> absolute_pitch
359 %type <scm> assignment_id
360 %type <scm> bare_number
361 %type <scm> unsigned_number
362 %type <scm> bass_figure
363 %type <scm> figured_bass_modification
364 %type <scm> br_bass_figure
365 %type <scm> bass_number
366 %type <scm> chord_body_elements
367 %type <scm> chord_item
368 %type <scm> chord_items
369 %type <scm> chord_separator
370 %type <scm> context_def_mod
371 %type <scm> context_def_spec_block
372 %type <scm> context_def_spec_body
373 %type <scm> context_mod
374 %type <scm> context_mod_list
375 %type <scm> context_prop_spec
376 %type <scm> direction_less_char
377 %type <scm> duration_length
378 %type <scm> embedded_scm
379 %type <scm> figure_list
380 %type <scm> figure_spec
382 %type <scm> full_markup
383 %type <scm> full_markup_list
384 %type <scm> function_scm_argument
385 %type <scm> function_arglist
386 %type <scm> function_arglist_music_last
387 %type <scm> function_arglist_nonmusic_last
388 %type <scm> function_arglist_nonmusic
389 %type <scm> identifier_init
390 %type <scm> lilypond_header
391 %type <scm> lilypond_header_body
392 %type <scm> lyric_element
393 %type <scm> lyric_markup
395 %type <scm> markup_braced_list
396 %type <scm> markup_braced_list_body
397 %type <scm> markup_composed_list
398 %type <scm> markup_command_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> music_function_identifier_musicless_prefix
407 %type <scm> music_function_event
408 %type <scm> music_function_chord_body
409 %type <scm> new_chord
410 %type <scm> new_lyrics
411 %type <scm> number_expression
412 %type <scm> number_factor
413 %type <scm> number_term
414 %type <scm> object_id_setting
415 %type <scm> octave_check
416 %type <scm> optional_context_mod
417 %type <scm> optional_id
418 %type <scm> optional_notemode_duration
420 %type <scm> pitch_also_in_chords
421 %type <scm> post_events
422 %type <scm> property_operation
423 %type <scm> property_path property_path_revved
425 %type <scm> script_abbreviation
426 %type <scm> simple_chord_elements
427 %type <scm> simple_markup
428 %type <scm> simple_string
429 %type <scm> steno_duration
430 %type <scm> steno_pitch
431 %type <scm> steno_tonic_pitch
432 %type <scm> step_number
433 %type <scm> step_numbers
436 %type <score> score_block
437 %type <score> score_body
442 /* We don't assign precedence to / and *, because we might need varied
443 prec levels in different prods */
449 lilypond: /* empty */
450 | lilypond toplevel_expression {
452 | lilypond assignment {
455 PARSER->error_level_ = 1;
458 PARSER->error_level_ = 1;
464 OBJECTID STRING { $$ = $2; }
469 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
473 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
474 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
480 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
481 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
485 Music *music = unsmob_music ($1);
486 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
487 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
490 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
491 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
494 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
495 scm_call_2 (proc, PARSER->self_scm (), $1);
499 Output_def * od = $1;
501 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
502 id = ly_symbol2scm ("$defaultpaper");
503 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
504 id = ly_symbol2scm ("$defaultmidi");
505 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
506 id = ly_symbol2scm ("$defaultlayout");
508 PARSER->lexer_->set_identifier (id, od->self_scm ());
519 lilypond_header_body:
521 $$ = get_header (PARSER);
522 PARSER->lexer_->add_scope ($$);
524 | lilypond_header_body assignment {
530 HEADER '{' lilypond_header_body '}' {
531 $$ = PARSER->lexer_->remove_scope ();
540 | LYRICS_STRING { $$ = $1; }
544 assignment_id '=' identifier_init {
545 PARSER->lexer_->set_identifier ($1, $3);
548 TODO: devise standard for protection in parser.
550 The parser stack lives on the C-stack, which means that
551 all objects can be unprotected as soon as they're here.
561 $$ = $1->self_scm ();
565 $$ = $1->self_scm ();
569 $$ = $1->self_scm ();
572 | context_def_spec_block {
576 /* Hack: Create event-chord around standalone events.
577 Prevents the identifier from being interpreted as a post-event. */
578 Music *mus = unsmob_music ($1);
579 bool is_event = mus &&
580 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
585 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
590 | number_expression {
603 $$ = scm_from_int ($1);
607 context_def_spec_block:
608 CONTEXT '{' context_def_spec_body '}'
614 context_def_spec_body:
616 $$ = Context_def::make_scm ();
617 unsmob_context_def ($$)->origin ()->set_spot (@$);
619 | CONTEXT_DEF_IDENTIFIER {
621 unsmob_context_def ($$)->origin ()->set_spot (@$);
623 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
624 Context_def*td = unsmob_context_def ($$);
626 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
627 SCM tag = scm_caar (p);
629 /* TODO: should make new tag "grob-definition" ? */
630 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
631 tag, scm_cons (scm_cdar (p), SCM_EOL)));
634 | context_def_spec_body context_mod {
635 unsmob_context_def ($$)->add_context_mod ($2);
642 BOOK '{' book_body '}' {
648 * Use 'handlers' like for toplevel-* stuff?
649 * grok \layout and \midi? */
653 $$->origin ()->set_spot (@$);
654 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
655 $$->paper_->unprotect ();
656 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
659 $$ = unsmob_book ($1);
661 $$->origin ()->set_spot (@$);
663 | book_body paper_block {
667 | book_body score_block {
669 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
670 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
673 | book_body composite_music {
674 Music *music = unsmob_music ($2);
675 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
676 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
678 | book_body full_markup {
679 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
680 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
682 | book_body full_markup_list {
683 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
684 scm_call_2 (proc, $$->self_scm (), $2);
686 | book_body lilypond_header {
691 $$->scores_ = SCM_EOL;
693 | book_body object_id_setting {
694 $$->user_key_ = ly_scm2string ($2);
699 SCORE '{' score_body '}' {
707 SCM scorify = ly_lily_module_constant ("scorify-music");
708 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
710 // pass ownernship to C++ again.
711 $$ = unsmob_score (score);
713 $$->origin ()->set_spot (@$);
716 $$ = unsmob_score ($1);
718 $$->origin ()->set_spot (@$);
720 | score_body object_id_setting {
721 $$->user_key_ = ly_scm2string ($2);
723 | score_body lilypond_header {
726 | score_body output_def {
727 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
729 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
734 $$->add_output_def ($2);
739 $$->error_found_ = true;
751 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
753 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
755 $$ = get_paper (PARSER);
762 output_def_body '}' {
765 PARSER->lexer_->remove_scope ();
766 PARSER->lexer_->pop_state ();
772 $$ = get_paper (PARSER);
773 $$->input_origin_ = @$;
774 PARSER->lexer_->add_scope ($$->scope_);
777 Output_def *p = get_midi (PARSER);
779 PARSER->lexer_->add_scope (p->scope_);
782 Output_def *p = get_layout (PARSER);
784 PARSER->lexer_->add_scope (p->scope_);
789 output_def_head_with_mode_switch:
791 PARSER->lexer_->push_initial_state ();
797 output_def_head_with_mode_switch '{' {
799 $$->input_origin_.set_spot (@$);
801 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
804 Output_def *o = unsmob_output_def ($3);
805 o->input_origin_.set_spot (@$);
808 PARSER->lexer_->remove_scope ();
809 PARSER->lexer_->add_scope (o->scope_);
811 | output_def_body assignment {
814 | output_def_body context_def_spec_block {
815 assign_context_def ($$, $2);
817 | output_def_body error {
823 TEMPO steno_duration '=' bare_unsigned {
824 $$ = MAKE_SYNTAX ("tempo", @$, SCM_BOOL_F, $2, scm_int2num ($4));
826 | TEMPO string steno_duration '=' bare_unsigned {
827 $$ = MAKE_SYNTAX ("tempo", @$, make_simple_markup($2), $3, scm_int2num ($5));
829 | TEMPO full_markup steno_duration '=' bare_unsigned {
830 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, scm_int2num ($5));
833 $$ = MAKE_SYNTAX ("tempoText", @$, make_simple_markup($2) );
835 | TEMPO full_markup {
836 $$ = MAKE_SYNTAX ("tempoText", @$, $2 );
841 The representation of a list is the
845 to have efficient append. */
849 $$ = scm_cons (SCM_EOL, SCM_EOL);
853 SCM c = scm_cons ($2, SCM_EOL);
855 if (scm_is_pair (scm_cdr (s)))
856 scm_set_cdr_x (scm_cdr (s), c); /* append */
858 scm_set_car_x (s, c); /* set first cons */
859 scm_set_cdr_x (s, c); /* remember last cell */
861 | music_list embedded_scm {
865 Music *m = MY_MAKE_MUSIC("Music", @$);
867 m->set_property ("error-found", SCM_BOOL_T);
869 SCM c = scm_cons (m->self_scm (), SCM_EOL);
870 m->unprotect (); /* UGH */
872 if (scm_is_pair (scm_cdr (s)))
873 scm_set_cdr_x (scm_cdr (s), c); /* append */
875 scm_set_car_x (s, c); /* set first cons */
876 scm_set_cdr_x (s, c); /* remember last cell */
889 | ALTERNATIVE '{' music_list '}' {
896 REPEAT simple_string unsigned_number music alternative_music
898 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $5);
903 SEQUENTIAL '{' music_list '}' {
904 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($3));
906 | '{' music_list '}' {
907 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($2));
912 SIMULTANEOUS '{' music_list '}'{
913 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($3));
915 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
916 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($2));
927 optional_context_mod:
928 /**/ { $$ = SCM_EOL; }
929 | WITH { PARSER->lexer_->push_initial_state (); }
930 '{' context_mod_list '}'
932 PARSER->lexer_->pop_state ();
938 /* */ { $$ = SCM_EOL; }
939 | context_mod_list context_mod {
940 $$ = scm_cons ($2, $1);
945 prefix_composite_music { $$ = $1; }
946 | grouped_music_list { $$ = $1; }
950 simultaneous_music { $$ = $1; }
951 | sequential_music { $$ = $1; }
954 function_scm_argument:
959 /* An argument list. If a function \foo expects scm scm music, then the lexer expands \foo into the token sequence:
960 MUSIC_FUNCTION EXPECT_MUSIC EXPECT_SCM EXPECT_SCM
961 and this rule returns the reversed list of arguments. */
963 function_arglist_music_last:
964 EXPECT_MUSIC function_arglist music {
965 $$ = scm_cons ($3, $2);
969 function_arglist_nonmusic_last:
970 EXPECT_MARKUP function_arglist full_markup {
971 $$ = scm_cons ($3, $2);
973 | EXPECT_SCM function_arglist function_scm_argument {
974 $$ = scm_cons ($3, $2);
978 function_arglist_nonmusic: EXPECT_NO_MORE_ARGS {
981 | EXPECT_MARKUP function_arglist_nonmusic full_markup {
982 $$ = scm_cons ($3, $2);
984 | EXPECT_SCM function_arglist_nonmusic function_scm_argument {
985 $$ = scm_cons ($3, $2);
989 function_arglist: EXPECT_NO_MORE_ARGS {
990 /* This is for 0-ary functions, so they don't need to
991 read a lookahead token */
994 | function_arglist_music_last
995 | function_arglist_nonmusic_last
998 generic_prefix_music_scm:
999 MUSIC_FUNCTION function_arglist {
1000 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1006 /**/ { $$ = SCM_EOL; }
1007 | '=' simple_string {
1013 prefix_composite_music:
1014 generic_prefix_music_scm {
1015 $$ = run_music_function (PARSER, $1);
1017 | CONTEXT simple_string optional_id optional_context_mod music {
1018 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_F);
1020 | NEWCONTEXT simple_string optional_id optional_context_mod music {
1021 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_T);
1024 | TIMES fraction music {
1025 $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3);
1027 | repeated_music { $$ = $1; }
1028 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords music {
1029 Pitch from = *unsmob_pitch ($2);
1030 Pitch to = *unsmob_pitch ($3);
1031 SCM pitch = pitch_interval (from, to).smobbed_copy ();
1032 $$ = MAKE_SYNTAX ("transpose-music", @$, pitch, $4);
1034 | mode_changing_head grouped_music_list {
1035 if ($1 == ly_symbol2scm ("chords"))
1037 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1043 PARSER->lexer_->pop_state ();
1045 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1046 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, $3, $2, SCM_BOOL_T);
1047 if ($1 == ly_symbol2scm ("ChordNames"))
1049 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1051 PARSER->lexer_->pop_state ();
1053 | relative_music { $$ = $1; }
1054 | re_rhythmed_music { $$ = $1; }
1059 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1060 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1062 $$ = ly_symbol2scm ("notes");
1066 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1067 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1069 $$ = ly_symbol2scm ("drums");
1072 PARSER->lexer_->push_figuredbass_state ();
1074 $$ = ly_symbol2scm ("figures");
1077 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1078 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1079 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1080 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1081 $$ = ly_symbol2scm ("chords");
1085 { PARSER->lexer_->push_lyric_state ();
1086 $$ = ly_symbol2scm ("lyrics");
1090 mode_changing_head_with_context:
1092 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1093 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1095 $$ = ly_symbol2scm ("DrumStaff");
1098 PARSER->lexer_->push_figuredbass_state ();
1100 $$ = ly_symbol2scm ("FiguredBass");
1103 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1104 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1105 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1106 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1107 $$ = ly_symbol2scm ("ChordNames");
1110 { PARSER->lexer_->push_lyric_state ();
1111 $$ = ly_symbol2scm ("Lyrics");
1117 RELATIVE absolute_pitch music {
1118 Pitch start = *unsmob_pitch ($2);
1119 $$ = make_music_relative (start, $3, @$);
1121 | RELATIVE composite_music {
1122 Pitch middle_c (0, 0, 0);
1123 $$ = make_music_relative (middle_c, $2, @$);
1128 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1130 grouped_music_list {
1131 /* Can also use music at the expensive of two S/Rs similar to
1132 \repeat \alternative */
1133 PARSER->lexer_->pop_state ();
1135 $$ = scm_cons ($3, SCM_EOL);
1137 | new_lyrics ADDLYRICS {
1138 PARSER->lexer_->push_lyric_state ();
1139 } grouped_music_list {
1140 PARSER->lexer_->pop_state ();
1141 $$ = scm_cons ($4, $1);
1146 grouped_music_list new_lyrics {
1147 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1149 | LYRICSTO simple_string {
1150 PARSER->lexer_->push_lyric_state ();
1152 PARSER->lexer_->pop_state ();
1153 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1158 CHANGE STRING '=' STRING {
1159 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1164 property_path_revved:
1166 $$ = scm_cons ($1, SCM_EOL);
1168 | property_path_revved embedded_scm {
1169 $$ = scm_cons ($2, $1);
1174 property_path_revved {
1175 $$ = scm_reverse_x ($1, SCM_EOL);
1181 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1182 scm_string_to_symbol ($1), $3);
1184 | UNSET simple_string {
1185 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1186 scm_string_to_symbol ($2));
1188 | OVERRIDE simple_string property_path '=' embedded_scm {
1189 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1190 scm_string_to_symbol ($2), $5),
1193 | REVERT simple_string embedded_scm {
1194 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1195 scm_string_to_symbol ($2), $3);
1200 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1201 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1203 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1204 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1205 | DENIES { $$ = ly_symbol2scm ("denies"); }
1207 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1208 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1209 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1210 | NAME { $$ = ly_symbol2scm ("context-name"); }
1214 property_operation { $$ = $1; }
1215 | context_def_mod STRING {
1216 $$ = scm_list_2 ($1, $2);
1222 if (!is_regular_identifier ($1))
1224 @$.error (_("Grob name should be alphanumeric"));
1227 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1228 scm_string_to_symbol ($1));
1230 | simple_string '.' simple_string {
1231 $$ = scm_list_2 (scm_string_to_symbol ($1),
1232 scm_string_to_symbol ($3));
1236 simple_music_property_def:
1237 OVERRIDE context_prop_spec property_path '=' scalar {
1238 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1239 ly_symbol2scm ("OverrideProperty"),
1244 | REVERT context_prop_spec embedded_scm {
1245 $$ = scm_list_4 (scm_car ($2),
1246 ly_symbol2scm ("RevertProperty"),
1250 | SET context_prop_spec '=' scalar {
1251 $$ = scm_list_4 (scm_car ($2),
1252 ly_symbol2scm ("PropertySet"),
1256 | UNSET context_prop_spec {
1257 $$ = scm_list_3 (scm_car ($2),
1258 ly_symbol2scm ("PropertyUnset"),
1264 simple_music_property_def {
1265 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1267 | ONCE simple_music_property_def {
1268 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1276 | STRING_IDENTIFIER {
1279 | string '+' string {
1280 $$ = scm_string_append (scm_list_2 ($1, $3));
1284 simple_string: STRING {
1290 | STRING_IDENTIFIER {
1311 $$ = scm_from_int ($1);
1316 /* TODO: Create a special case that avoids the creation of
1317 EventChords around simple_elements that have no post_events?
1319 simple_chord_elements post_events {
1320 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1323 /* why is this giving wrong start location? -ns
1325 i.set_location (@1, @2);
1326 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1328 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1330 i.set_location (@1, @3);
1331 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2, $3);
1334 | note_chord_element
1339 chord_body optional_notemode_duration post_events
1341 Music *m = unsmob_music ($1);
1342 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1343 SCM es = m->get_property ("elements");
1344 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1346 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1347 unsmob_music (scm_car (s))->set_property ("duration", dur);
1348 es = ly_append2 (es, postevs);
1350 m-> set_property ("elements", es);
1352 $$ = m->self_scm ();
1357 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1359 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1363 chord_body_elements:
1364 /* empty */ { $$ = SCM_EOL; }
1365 | chord_body_elements chord_body_element {
1366 $$ = scm_cons ($2, $1);
1371 pitch exclamations questions octave_check post_events
1378 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1379 n->set_property ("pitch", $1);
1381 n->set_property ("cautionary", SCM_BOOL_T);
1382 if (ex % 2 || q % 2)
1383 n->set_property ("force-accidental", SCM_BOOL_T);
1385 if (scm_is_pair (post)) {
1386 SCM arts = scm_reverse_x (post, SCM_EOL);
1387 n->set_property ("articulations", arts);
1389 if (scm_is_number (check))
1391 int q = scm_to_int (check);
1392 n->set_property ("absolute-octave", scm_from_int (q-1));
1395 $$ = n->unprotect ();
1397 | DRUM_PITCH post_events {
1398 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1399 n->set_property ("duration", $2);
1400 n->set_property ("drum-type", $1);
1402 if (scm_is_pair ($2)) {
1403 SCM arts = scm_reverse_x ($2, SCM_EOL);
1404 n->set_property ("articulations", arts);
1406 $$ = n->unprotect ();
1408 | music_function_chord_body {
1409 $$ = run_music_function (PARSER, $1);
1413 music_function_identifier_musicless_prefix: MUSIC_FUNCTION {
1414 SCM sig = scm_object_property (yylval.scm, ly_symbol2scm ("music-function-signature"));
1415 if (scm_is_pair (sig) && to_boolean (scm_memq (ly_music_p_proc, scm_cdr (scm_reverse (sig)))))
1417 PARSER->parser_error (@$, "Music function applied to event may not have a Music argument, except as the last argument.");
1422 music_function_chord_body:
1423 /* We could allow chord functions to have multiple music arguments,
1424 but it's more consistent with music_function_event if we
1425 prohibit it here too */
1426 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic chord_body_element {
1427 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1429 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1430 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1434 music_function_event:
1435 /* Post-events can only have the last argument as music, without this
1436 restriction we get a shift/reduce conflict from e.g.
1437 c8-\partcombine c8 -. */
1438 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic post_event {
1439 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1441 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1442 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1450 | SKIP duration_length {
1451 $$ = MAKE_SYNTAX ("skip-music", @$, $2);
1454 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1455 m->set_property ("span-direction", scm_from_int (START));
1456 $$ = m->unprotect();
1459 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1460 m->set_property ("span-direction", scm_from_int (STOP));
1461 $$ = m->unprotect ();
1464 $$ = MAKE_SYNTAX ("voice-separator", @$, SCM_UNDEFINED);
1467 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1469 Music *m = unsmob_music (pipe);
1474 $$ = m->unprotect ();
1477 $$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
1480 | PARTIAL duration_length {
1481 Moment m = - unsmob_duration ($2)->get_length ();
1482 $$ = MAKE_SYNTAX ("property-operation", @$, SCM_BOOL_F, ly_symbol2scm ("Timing"), ly_symbol2scm ("PropertySet"), ly_symbol2scm ("measurePosition"), m.smobbed_copy ());
1483 $$ = MAKE_SYNTAX ("context-specification", @$, ly_symbol2scm ("Score"), SCM_BOOL_F, $$, SCM_EOL, SCM_BOOL_F);
1487 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1489 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1492 SCM proc = ly_lily_module_constant ("make-mark-set");
1494 $$ = scm_call_1 (proc, $2);
1500 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
1503 Music *m = MY_MAKE_MUSIC ("MarkEvent", @$);
1504 $$ = m->unprotect ();
1510 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1511 $$ = key->unprotect ();
1513 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1515 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1516 if (scm_ilength ($3) > 0)
1518 key->set_property ("pitch-alist", $3);
1519 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1520 key->transpose (* unsmob_pitch ($2));
1522 PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1525 $$ = key->unprotect ();
1534 | post_events post_event {
1535 unsmob_music ($2)->set_spot (@2);
1536 $$ = scm_cons ($2, $$);
1541 direction_less_event {
1544 | '-' music_function_event {
1545 $$ = run_music_function (PARSER, $2);
1548 if (!PARSER->lexer_->is_lyric_state ())
1549 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1550 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
1553 if (!PARSER->lexer_->is_lyric_state ())
1554 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1555 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
1557 | script_dir direction_reqd_event {
1560 Music *m = unsmob_music ($2);
1561 m->set_property ("direction", scm_from_int ($1));
1565 | script_dir direction_less_event {
1568 Music *m = unsmob_music ($2);
1569 m->set_property ("direction", scm_from_int ($1));
1573 | string_number_event
1576 string_number_event:
1578 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
1579 s->set_property ("string-number", scm_from_int ($1));
1580 $$ = s->unprotect ();
1584 direction_less_char:
1586 $$ = ly_symbol2scm ("bracketOpenSymbol");
1589 $$ = ly_symbol2scm ("bracketCloseSymbol");
1592 $$ = ly_symbol2scm ("tildeSymbol");
1595 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1598 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1601 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1604 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1607 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1610 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1613 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1617 direction_less_event:
1618 direction_less_char {
1619 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
1621 if (unsmob_music (predefd))
1623 m = unsmob_music (predefd)->clone ();
1628 m = MY_MAKE_MUSIC ("Music", @$);
1630 $$ = m->unprotect ();
1632 | EVENT_IDENTIFIER {
1636 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
1637 a->set_property ("tremolo-type", scm_from_int ($1));
1638 $$ = a->unprotect ();
1642 direction_reqd_event:
1646 | script_abbreviation {
1647 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1648 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
1649 if (scm_is_string (s))
1650 a->set_property ("articulation-type", s);
1651 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
1652 $$ = a->unprotect ();
1657 /**/ { $$ = SCM_EOL; }
1658 | '=' { $$ = scm_from_int (0); }
1659 | '=' sub_quotes { $$ = scm_from_int (-$2); }
1660 | '=' sup_quotes { $$ = scm_from_int ($2); }
1685 | NOTENAME_PITCH sup_quotes {
1686 Pitch p = *unsmob_pitch ($1);
1687 p = p.transposed (Pitch ($2,0,0));
1688 $$ = p.smobbed_copy ();
1690 | NOTENAME_PITCH sub_quotes {
1691 Pitch p =* unsmob_pitch ($1);
1692 p = p.transposed (Pitch (-$2,0,0));
1693 $$ = p.smobbed_copy ();
1705 | TONICNAME_PITCH sup_quotes {
1706 Pitch p = *unsmob_pitch ($1);
1707 p = p.transposed (Pitch ($2,0,0));
1708 $$ = p.smobbed_copy ();
1710 | TONICNAME_PITCH sub_quotes {
1711 Pitch p = *unsmob_pitch ($1);
1713 p = p.transposed (Pitch (-$2,0,0));
1714 $$ = p.smobbed_copy ();
1724 pitch_also_in_chords:
1731 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1732 t->set_property ("text", $1);
1733 $$ = t->unprotect ();
1736 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1737 t->set_property ("text",
1738 make_simple_markup ($1));
1739 $$ = t->unprotect ();
1742 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
1743 t->set_property ("digit", scm_from_int ($1));
1744 $$ = t->unprotect ();
1748 script_abbreviation:
1750 $$ = scm_from_locale_string ("Hat");
1753 $$ = scm_from_locale_string ("Plus");
1756 $$ = scm_from_locale_string ("Dash");
1759 $$ = scm_from_locale_string ("Bar");
1762 $$ = scm_from_locale_string ("Larger");
1765 $$ = scm_from_locale_string ("Dot");
1768 $$ = scm_from_locale_string ("Underscore");
1775 | '-' { $$ = CENTER; }
1786 multiplied_duration {
1791 optional_notemode_duration:
1793 Duration dd = PARSER->default_duration_;
1794 $$ = dd.smobbed_copy ();
1796 | multiplied_duration {
1798 PARSER->default_duration_ = *unsmob_duration ($$);
1803 bare_unsigned dots {
1805 if (!is_duration ($1))
1806 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
1810 $$ = Duration (len, $2).smobbed_copy ();
1812 | DURATION_IDENTIFIER dots {
1813 Duration *d = unsmob_duration ($1);
1814 Duration k (d->duration_log (), d->dot_count () + $2);
1820 multiplied_duration:
1824 | multiplied_duration '*' bare_unsigned {
1825 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1827 | multiplied_duration '*' FRACTION {
1828 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1830 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1835 FRACTION { $$ = $1; }
1836 | UNSIGNED '/' UNSIGNED {
1837 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
1854 | ':' bare_unsigned {
1855 if (!is_duration ($2))
1856 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
1863 $$ = scm_from_int ($1);
1866 $$ = scm_from_int ($1);
1868 | STRING { $$ = $1; }
1869 | full_markup { $$ = $1; }
1872 figured_bass_alteration:
1873 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
1874 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
1875 | '!' { $$ = scm_from_int (0); }
1880 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
1881 $$ = bfr->unprotect ();
1884 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
1885 $$ = bfr->self_scm ();
1887 if (scm_is_number ($1))
1888 bfr->set_property ("figure", $1);
1889 else if (Text_interface::is_markup ($1))
1890 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);
1900 if (scm_to_double ($2)) {
1901 SCM salter = m->get_property ("alteration");
1902 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
1903 m->set_property ("alteration",
1904 scm_sum (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);
1923 else if ($2 == ly_symbol2scm ("backslash"))
1925 m->set_property ("augmented-slash", SCM_BOOL_T);
1931 figured_bass_modification:
1933 $$ = ly_symbol2scm ("plus");
1936 $$ = ly_symbol2scm ("exclamation");
1939 $$ = ly_symbol2scm ("slash");
1942 $$ = ly_symbol2scm ("backslash");
1952 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
1960 | figure_list br_bass_figure {
1961 $$ = scm_cons ($2, $1);
1966 FIGURE_OPEN figure_list FIGURE_CLOSE {
1967 $$ = scm_reverse_x ($2, SCM_EOL);
1978 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
1979 if (!PARSER->lexer_->is_note_state ())
1980 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
1984 n = MY_MAKE_MUSIC ("RestEvent", @$);
1986 n = MY_MAKE_MUSIC ("NoteEvent", @$);
1988 n->set_property ("pitch", $1);
1989 n->set_property ("duration", $5);
1991 if (scm_is_number ($4))
1993 int q = scm_to_int ($4);
1994 n->set_property ("absolute-octave", scm_from_int (q-1));
1998 n->set_property ("cautionary", SCM_BOOL_T);
1999 if ($2 % 2 || $3 % 2)
2000 n->set_property ("force-accidental", SCM_BOOL_T);
2002 $$ = n->unprotect ();
2004 | DRUM_PITCH optional_notemode_duration {
2005 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2006 n->set_property ("duration", $2);
2007 n->set_property ("drum-type", $1);
2009 $$ = n->unprotect ();
2011 | RESTNAME optional_notemode_duration {
2013 if (ly_scm2string ($1) == "s") {
2015 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2018 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2021 ev->set_property ("duration", $2);
2022 $$ = ev->unprotect ();
2024 | lyric_element optional_notemode_duration {
2025 if (!PARSER->lexer_->is_lyric_state ())
2026 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2028 Music *levent = MY_MAKE_MUSIC ("LyricEvent", @$);
2029 levent->set_property ("text", $1);
2030 levent->set_property ("duration",$2);
2031 $$= levent->unprotect ();
2035 simple_chord_elements:
2037 $$ = scm_list_1 ($1);
2040 if (!PARSER->lexer_->is_chord_state ())
2041 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2044 | figure_spec optional_notemode_duration {
2045 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2047 unsmob_music (scm_car (s))->set_property ("duration", $2);
2063 steno_tonic_pitch optional_notemode_duration {
2064 $$ = make_chord_elements ($1, $2, SCM_EOL);
2066 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2067 SCM its = scm_reverse_x ($4, SCM_EOL);
2068 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2076 | chord_items chord_item {
2077 $$ = scm_cons ($2, $$);
2083 $$ = ly_symbol2scm ("chord-colon");
2086 $$ = ly_symbol2scm ("chord-caret");
2088 | CHORD_SLASH steno_tonic_pitch {
2089 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2091 | CHORD_BASS steno_tonic_pitch {
2092 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2101 $$ = scm_reverse_x ($1, SCM_EOL);
2109 step_number { $$ = scm_cons ($1, SCM_EOL); }
2110 | step_numbers '.' step_number {
2111 $$ = scm_cons ($3, $$);
2117 $$ = make_chord_step ($1, 0);
2119 | bare_unsigned '+' {
2120 $$ = make_chord_step ($1, SHARP_ALTERATION);
2122 | bare_unsigned CHORD_MINUS {
2123 $$ = make_chord_step ($1, FLAT_ALTERATION);
2130 TODO: should deprecate in favor of Scheme?
2134 number_expression '+' number_term {
2135 $$ = scm_sum ($1, $3);
2137 | number_expression '-' number_term {
2138 $$ = scm_difference ($1, $3);
2147 | number_factor '*' number_factor {
2148 $$ = scm_product ($1, $3);
2150 | number_factor '/' number_factor {
2151 $$ = scm_divide ($1, $3);
2156 '-' number_factor { /* %prec UNARY_MINUS */
2157 $$ = scm_difference ($2, SCM_UNDEFINED);
2165 $$ = scm_from_int ($1);
2170 | NUMBER_IDENTIFIER {
2173 | REAL NUMBER_IDENTIFIER {
2174 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2176 | UNSIGNED NUMBER_IDENTIFIER {
2177 $$ = scm_from_double ($1 *scm_to_double ($2));
2192 bare_unsigned { $$ = scm_from_int ($1); }
2193 | NUMBER_IDENTIFIER {
2201 | exclamations '!' { $$ ++; }
2206 | questions '?' { $$ ++; }
2210 This should be done more dynamically if possible.
2214 LYRIC_MARKUP_IDENTIFIER {
2218 { PARSER->lexer_->push_markup_state (); }
2221 PARSER->lexer_->pop_state ();
2227 { PARSER->lexer_->push_markup_state (); }
2230 PARSER->lexer_->pop_state ();
2239 { PARSER->lexer_->push_markup_state (); }
2242 PARSER->lexer_->pop_state ();
2248 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2250 | markup_head_1_list simple_markup {
2251 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2259 markup_composed_list {
2262 | markup_braced_list {
2265 | markup_command_list {
2266 $$ = scm_list_1 ($1);
2270 markup_composed_list:
2271 markup_head_1_list markup_braced_list {
2272 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2278 '{' markup_braced_list_body '}' {
2279 $$ = scm_reverse_x ($2, SCM_EOL);
2283 markup_braced_list_body:
2284 /* empty */ { $$ = SCM_EOL; }
2285 | markup_braced_list_body markup {
2286 $$ = scm_cons ($2, $1);
2288 | markup_braced_list_body markup_list {
2289 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2293 markup_command_list:
2294 MARKUP_LIST_HEAD_EMPTY {
2295 $$ = scm_list_1 ($1);
2297 | MARKUP_LIST_HEAD_LIST0 markup_list {
2298 $$ = scm_list_2 ($1, $2);
2300 | MARKUP_LIST_HEAD_SCM0 embedded_scm {
2301 $$ = scm_list_2 ($1, $2);
2303 | MARKUP_LIST_HEAD_SCM0_LIST1 embedded_scm markup_list {
2304 $$ = scm_list_3 ($1, $2, $3);
2306 | MARKUP_LIST_HEAD_SCM0_SCM1_LIST2 embedded_scm embedded_scm markup_list {
2307 $$ = scm_list_4 ($1, $2, $3, $4);
2312 MARKUP_HEAD_MARKUP0 {
2313 $$ = scm_list_1 ($1);
2315 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2316 $$ = scm_list_2 ($1, $2);
2318 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2319 $$ = scm_list_3 ($1, $2, $3);
2324 markup_head_1_item {
2325 $$ = scm_list_1 ($1);
2327 | markup_head_1_list markup_head_1_item {
2328 $$ = scm_cons ($2, $1);
2334 $$ = make_simple_markup ($1);
2336 | MARKUP_IDENTIFIER {
2339 | LYRIC_MARKUP_IDENTIFIER {
2342 | STRING_IDENTIFIER {
2346 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2347 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2348 } '{' score_body '}' {
2350 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2352 PARSER->lexer_->pop_state ();
2354 | MARKUP_HEAD_SCM0 embedded_scm {
2355 $$ = scm_list_2 ($1, $2);
2357 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2358 $$ = scm_list_4 ($1, $2, $3, $4);
2360 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2361 $$ = scm_list_3 ($1, $2, $3);
2363 | MARKUP_HEAD_SCM0_MARKUP1_MARKUP2 embedded_scm markup markup {
2364 $$ = scm_list_4 ($1, $2, $3, $4);
2366 | MARKUP_HEAD_SCM0_SCM1_MARKUP2_MARKUP3 embedded_scm embedded_scm markup markup {
2367 $$ = scm_list_5 ($1, $2, $3, $4, $5);
2369 | MARKUP_HEAD_EMPTY {
2370 $$ = scm_list_1 ($1);
2372 | MARKUP_HEAD_LIST0 markup_list {
2373 $$ = scm_list_2 ($1,$2);
2375 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2376 $$ = scm_list_3 ($1, $2, $3);
2381 markup_head_1_list simple_markup {
2382 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2383 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2393 Lily_parser::set_yydebug (bool x)
2399 Lily_parser::do_yyparse ()
2401 yyparse ((void*)this);
2410 It is a little strange to have this function in this file, but
2411 otherwise, we have to import music classes into the lexer.
2415 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2417 if (scm_is_string (sid)) {
2419 return STRING_IDENTIFIER;
2420 } else if (unsmob_book (sid)) {
2421 Book *book = unsmob_book (sid)->clone ();
2422 *destination = book->self_scm ();
2425 return BOOK_IDENTIFIER;
2426 } else if (scm_is_number (sid)) {
2428 return NUMBER_IDENTIFIER;
2429 } else if (unsmob_context_def (sid)) {
2430 Context_def *def= unsmob_context_def (sid)->clone ();
2432 *destination = def->self_scm ();
2435 return CONTEXT_DEF_IDENTIFIER;
2436 } else if (unsmob_score (sid)) {
2437 Score *score = new Score (*unsmob_score (sid));
2438 *destination = score->self_scm ();
2440 score->unprotect ();
2441 return SCORE_IDENTIFIER;
2442 } else if (Music *mus = unsmob_music (sid)) {
2443 mus = mus->clone ();
2444 *destination = mus->self_scm ();
2445 unsmob_music (*destination)->
2446 set_property ("origin", make_input (last_input_));
2448 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2452 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2453 } else if (unsmob_duration (sid)) {
2454 *destination = unsmob_duration (sid)->smobbed_copy ();
2455 return DURATION_IDENTIFIER;
2456 } else if (unsmob_output_def (sid)) {
2457 Output_def *p = unsmob_output_def (sid);
2460 *destination = p->self_scm ();
2462 return OUTPUT_DEF_IDENTIFIER;
2463 } else if (Text_interface::is_markup (sid)) {
2465 if (is_lyric_state ())
2466 return LYRIC_MARKUP_IDENTIFIER;
2467 return MARKUP_IDENTIFIER;
2474 get_next_unique_context_id ()
2476 return scm_from_locale_string ("$uniqueContextId");
2481 get_next_unique_lyrics_context_id ()
2483 static int new_context_count;
2485 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2486 return scm_from_locale_string (s);
2491 run_music_function (Lily_parser *parser, SCM expr)
2493 SCM func = scm_car (expr);
2494 Input *loc = unsmob_input (scm_cadr (expr));
2495 SCM args = scm_cddr (expr);
2496 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2498 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2500 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2502 parser->error_level_ = 1;
2503 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (*loc)));
2506 SCM syntax_args = scm_list_4 (parser->self_scm (), make_input (*loc), func, args);
2507 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
2511 is_regular_identifier (SCM id)
2513 string str = ly_scm2string (id);
2514 char const *s = str.c_str ();
2523 v = v && isalnum (*s);
2530 make_music_with_input (SCM name, Input where)
2532 Music *m = make_music_by_name (name);
2533 m->set_spot (where);
2538 get_first_context_id (SCM type, Music *m)
2540 SCM id = m->get_property ("context-id");
2541 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2542 && scm_is_string (m->get_property ("context-id"))
2543 && scm_c_string_length (id) > 0)
2551 make_simple_markup (SCM a)
2559 return t && t == 1 << intlog2 (t);
2563 set_music_properties (Music *p, SCM a)
2565 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2566 p->set_property (scm_caar (k), scm_cdar (k));
2571 make_chord_step (int step, Rational alter)
2574 alter += FLAT_ALTERATION;
2578 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2579 return m.smobbed_copy ();
2584 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
2586 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
2587 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
2591 /* Todo: actually also use apply iso. call too ... */
2593 ly_input_procedure_p (SCM x)
2595 return ly_is_procedure (x)
2596 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2600 make_music_relative (Pitch start, SCM music, Input loc)
2602 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic", loc);
2603 relative->set_property ("element", music);
2605 Music *m = unsmob_music (music);
2606 Pitch last = m->to_relative_octave (start);
2607 if (lily_1_8_relative)
2608 m->set_property ("last-pitch", last.smobbed_copy ());
2609 return relative->unprotect ();
2613 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2615 Lily_parser *pars = (Lily_parser*) v;
2616 Lily_lexer *lex = pars->lexer_;
2618 lex->lexval = (void*) s;
2620 lex->prepare_for_next_token ();
2621 return lex->yylex ();