2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 Jan Nieuwenhuizen <janneke@gnu.org>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
24 #define YYERROR_VERBOSE 1
25 #define YYPARSE_PARAM my_lily_parser
26 #define YYLEX_PARAM my_lily_parser
27 #define PARSER ((Lily_parser *) my_lily_parser)
29 #define yyerror PARSER->parser_error
31 /* We use custom location type: Input objects */
33 #define YYLLOC_DEFAULT(Current,Rhs,N) \
34 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
39 /* We use SCMs to do strings, because it saves us the trouble of
40 deleting them. Let's hope that a stack overflow doesnt trigger a move
41 of the parse stack onto the heap. */
49 /* One shift/reduce problem
52 \repeat .. \alternative
54 \repeat { \repeat .. \alternative }
58 \repeat { \repeat } \alternative
67 %{ // -*-Fundamental-*-
72 * The rules for who is protecting what are very shady. Uniformise
75 * There are too many lexical modes?
86 #include "context-def.hh"
87 #include "context-mod.hh"
88 #include "dimensions.hh"
89 #include "file-path.hh"
91 #include "international.hh"
92 #include "lily-guile.hh"
93 #include "lily-lexer.hh"
94 #include "lily-parser.hh"
99 #include "output-def.hh"
100 #include "paper-book.hh"
101 #include "program-option.hh"
102 #include "scm-hash.hh"
104 #include "text-interface.hh"
112 Output_def *outputdef;
122 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
125 - Don't use lily module, create a new module instead.
126 - delay application of the function
128 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
129 scm_apply_0 (proc, args)
130 /* Syntactic Sugar. */
131 #define MAKE_SYNTAX(name, location, ...) \
132 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location), __VA_ARGS__, SCM_UNDEFINED));
134 SCM get_next_unique_context_id ();
135 SCM get_next_unique_lyrics_context_id ();
142 #define _(x) gettext (x)
146 static Music *make_music_with_input (SCM name, Input where);
147 SCM make_music_relative (Pitch start, SCM music, Input loc);
148 SCM run_music_function (Lily_parser *parser, Input loc, SCM func, SCM args);
149 SCM get_first_context_id (SCM type, Music *m);
150 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
151 SCM make_chord_step (int step, Rational alter);
152 SCM make_simple_markup (SCM a);
153 bool is_duration (int t);
154 bool is_regular_identifier (SCM id);
155 bool ly_input_procedure_p (SCM x);
156 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
157 void set_music_properties (Music *p, SCM a);
161 /* The third option is an alias that will be used to display the
162 syntax error. Bison CVS now correctly handles backslash escapes.
164 FIXME: Bison needs to translate some of these, eg, STRING.
168 /* Keyword tokens with plain escaped name. */
169 %token ACCEPTS "\\accepts"
170 %token ADDLYRICS "\\addlyrics"
171 %token ALIAS "\\alias"
172 %token ALTERNATIVE "\\alternative"
174 %token BOOKPART "\\bookpart"
175 %token CHANGE "\\change"
176 %token CHORDMODE "\\chordmode"
177 %token CHORDS "\\chords"
178 %token CONSISTS "\\consists"
179 %token CONTEXT "\\context"
180 %token DEFAULT "\\default"
181 %token DEFAULTCHILD "\\defaultchild"
182 %token DENIES "\\denies"
183 %token DESCRIPTION "\\description"
184 %token DRUMMODE "\\drummode"
185 %token DRUMS "\\drums"
186 %token FIGUREMODE "\\figuremode"
187 %token FIGURES "\\figures"
188 %token GROBDESCRIPTIONS "\\grobdescriptions"
189 %token HEADER "\\header"
190 %token INVALID "\\version-error"
192 %token LAYOUT "\\layout"
193 %token LYRICMODE "\\lyricmode"
194 %token LYRICS "\\lyrics"
195 %token LYRICSTO "\\lyricsto"
197 %token MARKUP "\\markup"
198 %token MARKUPLINES "\\markuplines"
201 %token NOTEMODE "\\notemode"
203 %token OVERRIDE "\\override"
204 %token PAPER "\\paper"
205 %token PARTIAL "\\partial"
206 %token RELATIVE "\\relative"
207 %token REMOVE "\\remove"
208 %token REPEAT "\\repeat"
210 %token REVERT "\\revert"
211 %token SCORE "\\score"
212 %token SEQUENTIAL "\\sequential"
214 %token SIMULTANEOUS "\\simultaneous"
216 %token TEMPO "\\tempo"
217 %token TIMES "\\times"
219 %token UNSET "\\unset"
222 /* Keyword token exceptions. */
223 %token TIME_T "\\time"
224 %token NEWCONTEXT "\\new"
227 /* Other string tokens. */
229 %token CHORD_BASS "/+"
230 %token CHORD_CARET "^"
231 %token CHORD_COLON ":"
232 %token CHORD_MINUS "-"
233 %token CHORD_SLASH "/"
234 %token ANGLE_OPEN "<"
235 %token ANGLE_CLOSE ">"
236 %token DOUBLE_ANGLE_OPEN "<<"
237 %token DOUBLE_ANGLE_CLOSE ">>"
238 %token E_BACKSLASH "\\"
239 %token E_ANGLE_CLOSE "\\>"
240 %token E_CHAR "\\C[haracter]"
242 %token E_EXCLAMATION "\\!"
243 %token E_BRACKET_OPEN "\\["
245 %token E_BRACKET_CLOSE "\\]"
246 %token E_ANGLE_OPEN "\\<"
252 If we give names, Bison complains.
254 %token FIGURE_CLOSE /* "\\>" */
255 %token FIGURE_OPEN /* "\\<" */
256 %token FIGURE_SPACE "_"
259 %token CHORDMODIFIERS
261 %token MULTI_MEASURE_REST
264 %token <i> E_UNSIGNED
267 /* Artificial tokens, for more generic function syntax */
268 %token <i> EXPECT_MARKUP "markup?"
269 %token <i> EXPECT_MUSIC "ly:music?"
270 %token <i> EXPECT_PITCH "ly:pitch?"
271 %token <i> EXPECT_DURATION "ly:duration?"
272 %token <i> EXPECT_SCM "scheme?"
273 %token <i> EXPECT_MARKUP_LIST "markup-list?"
274 /* After the last argument. */
275 %token <i> EXPECT_NO_MORE_ARGS;
277 /* An artificial token for parsing embedded Lilypond */
278 %token <i> EMBEDDED_LILY "#{"
280 %token <scm> BOOK_IDENTIFIER
281 %token <scm> CHORDMODIFIER_PITCH
282 %token <scm> CHORD_MODIFIER
283 %token <scm> CHORD_REPETITION
284 %token <scm> CONTEXT_DEF_IDENTIFIER
285 %token <scm> CONTEXT_MOD_IDENTIFIER
286 %token <scm> DRUM_PITCH
287 %token <scm> DURATION_IDENTIFIER
288 %token <scm> EVENT_IDENTIFIER
289 %token <scm> FRACTION
290 %token <scm> LYRICS_STRING
291 %token <scm> LYRIC_MARKUP_IDENTIFIER
292 %token <scm> MARKUP_FUNCTION
293 %token <scm> MARKUP_LIST_FUNCTION
294 %token <scm> MARKUP_IDENTIFIER
295 %token <scm> MARKUPLINES_IDENTIFIER
296 %token <scm> MUSIC_FUNCTION
297 %token <scm> MUSIC_IDENTIFIER
298 %token <scm> NOTENAME_PITCH
299 %token <scm> NUMBER_IDENTIFIER
300 %token <scm> OUTPUT_DEF_IDENTIFIER
302 %token <scm> RESTNAME
303 %token <scm> SCM_FUNCTION
304 %token <scm> SCM_IDENTIFIER
305 %token <scm> SCM_TOKEN
306 %token <scm> SCORE_IDENTIFIER
308 %token <scm> STRING_IDENTIFIER
309 %token <scm> TONICNAME_PITCH
312 %type <book> book_block
313 %type <book> book_body
314 %type <book> bookpart_block
315 %type <book> bookpart_body
317 %type <i> bare_unsigned
318 %type <scm> figured_bass_alteration
320 %type <i> exclamations
321 %type <i> optional_rest
326 %type <i> tremolo_type
329 %type <scm> composite_music
330 %type <scm> grouped_music_list
331 %type <scm> closed_music
332 %type <scm> open_music
334 %type <scm> prefix_composite_music
335 %type <scm> repeated_music
336 %type <scm> sequential_music
337 %type <scm> simple_music
338 %type <scm> simultaneous_music
339 %type <scm> chord_body
340 %type <scm> chord_body_element
341 %type <scm> command_element
342 %type <scm> command_event
343 %type <scm> context_modification
344 %type <scm> context_change
345 %type <scm> direction_less_event
346 %type <scm> direction_reqd_event
347 %type <scm> embedded_lilypond
348 %type <scm> event_chord
349 %type <scm> fingering
350 %type <scm> gen_text_def
351 %type <scm> music_property_def
352 %type <scm> note_chord_element
353 %type <scm> post_event
354 %type <scm> post_event_nofinger
355 %type <scm> re_rhythmed_music
356 %type <scm> relative_music
357 %type <scm> simple_element
358 %type <scm> simple_music_property_def
359 %type <scm> start_symbol
360 %type <scm> string_number_event
361 %type <scm> tempo_event
363 %type <outputdef> output_def_body
364 %type <outputdef> output_def_head
365 %type <outputdef> output_def_head_with_mode_switch
366 %type <outputdef> output_def
367 %type <outputdef> paper_block
369 %type <scm> alternative_music
370 %type <scm> generic_prefix_music_scm
371 %type <scm> music_list
372 %type <scm> absolute_pitch
373 %type <scm> assignment_id
374 %type <scm> bare_number
375 %type <scm> unsigned_number
376 %type <scm> bass_figure
377 %type <scm> figured_bass_modification
378 %type <scm> br_bass_figure
379 %type <scm> bass_number
380 %type <scm> chord_body_elements
381 %type <scm> chord_item
382 %type <scm> chord_items
383 %type <scm> chord_separator
384 %type <scm> context_def_mod
385 %type <scm> context_def_spec_block
386 %type <scm> context_def_spec_body
387 %type <scm> context_mod
388 %type <scm> context_mod_list
389 %type <scm> context_prop_spec
390 %type <scm> direction_less_char
391 %type <scm> duration_length
392 %type <scm> closed_embedded_scm
393 %type <scm> embedded_scm
394 %type <scm> figure_list
395 %type <scm> figure_spec
397 %type <scm> full_markup
398 %type <scm> full_markup_list
399 %type <scm> function_scm_argument
400 %type <scm> function_arglist
401 %type <scm> function_arglist_nonmusic_last
402 %type <scm> closed_function_arglist
403 %type <scm> open_function_arglist
404 %type <scm> identifier_init
406 %type <scm> lilypond_header
407 %type <scm> lilypond_header_body
408 %type <scm> lyric_element
409 %type <scm> lyric_markup
411 %type <scm> markup_braced_list
412 %type <scm> markup_braced_list_body
413 %type <scm> markup_composed_list
414 %type <scm> markup_command_list
415 %type <scm> markup_command_list_arguments
416 %type <scm> closed_markup_command_list_arguments
417 %type <scm> markup_command_basic_arguments
418 %type <scm> markup_head_1_item
419 %type <scm> markup_head_1_list
420 %type <scm> markup_list
421 %type <scm> markup_top
422 %type <scm> mode_changing_head
423 %type <scm> mode_changing_head_with_context
424 %type <scm> multiplied_duration
425 %type <scm> music_function_event
426 %type <scm> music_function_event_arglist
427 %type <scm> music_function_chord_body
428 %type <scm> music_function_chord_body_arglist
429 %type <scm> new_chord
430 %type <scm> new_lyrics
431 %type <scm> number_expression
432 %type <scm> number_factor
433 %type <scm> number_term
434 %type <scm> octave_check
435 %type <scm> optional_context_mod
436 %type <scm> optional_id
437 %type <scm> optional_notemode_duration
439 %type <scm> pitch_also_in_chords
440 %type <scm> post_events
441 %type <scm> property_operation
442 %type <scm> property_path property_path_revved
444 %type <scm> closed_scalar
445 %type <scm> open_scm_function_call
446 %type <scm> closed_scm_function_call
447 %type <scm> script_abbreviation
448 %type <scm> simple_chord_elements
449 %type <scm> simple_markup
450 %type <scm> simple_string
451 %type <scm> steno_duration
452 %type <scm> steno_pitch
453 %type <scm> steno_tonic_pitch
454 %type <scm> step_number
455 %type <scm> step_numbers
457 %type <scm> tempo_range
459 %type <score> score_block
460 %type <score> score_body
465 /* We don't assign precedence to / and *, because we might need varied
466 prec levels in different prods */
475 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
476 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
477 } embedded_lilypond {
478 PARSER->lexer_->pop_state ();
479 PARSER->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
483 lilypond: /* empty */ { }
484 | lilypond toplevel_expression {
486 | lilypond assignment {
489 PARSER->error_level_ = 1;
492 PARSER->error_level_ = 1;
499 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
503 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
504 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
509 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
510 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
511 bookpart->unprotect ();
516 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
517 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
521 Music *music = unsmob_music ($1);
522 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
523 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
526 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
527 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
530 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
531 scm_call_2 (proc, PARSER->self_scm (), $1);
535 Output_def * od = $1;
537 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
538 id = ly_symbol2scm ("$defaultpaper");
539 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
540 id = ly_symbol2scm ("$defaultmidi");
541 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
542 id = ly_symbol2scm ("$defaultlayout");
544 PARSER->lexer_->set_identifier (id, od->self_scm ());
552 | closed_scm_function_call
557 | open_scm_function_call
560 closed_scm_function_call:
561 SCM_FUNCTION closed_function_arglist
563 $$ = run_music_function (PARSER, @$,
568 open_scm_function_call:
569 SCM_FUNCTION open_function_arglist
571 $$ = run_music_function (PARSER, @$,
577 { $$ = MAKE_SYNTAX ("void-music", @$, SCM_UNDEFINED); }
579 | music music music_list {
580 $$ = MAKE_SYNTAX ("sequential-music", @$,
581 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
584 PARSER->error_level_ = 1;
586 | INVALID embedded_lilypond {
587 PARSER->error_level_ = 1;
592 lilypond_header_body:
594 $$ = get_header (PARSER);
595 PARSER->lexer_->add_scope ($$);
597 | lilypond_header_body assignment {
603 HEADER '{' lilypond_header_body '}' {
604 $$ = PARSER->lexer_->remove_scope ();
613 | LYRICS_STRING { $$ = $1; }
617 assignment_id '=' identifier_init {
618 PARSER->lexer_->set_identifier ($1, $3);
620 | assignment_id property_path '=' identifier_init {
621 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
622 PARSER->lexer_->set_identifier (path, $4);
625 TODO: devise standard for protection in parser.
627 The parser stack lives on the C-stack, which means that
628 all objects can be unprotected as soon as they're here.
638 $$ = $1->self_scm ();
642 $$ = $1->self_scm ();
646 $$ = $1->self_scm ();
650 $$ = $1->self_scm ();
653 | context_def_spec_block {
657 /* Hack: Create event-chord around standalone events.
658 Prevents the identifier from being interpreted as a post-event. */
659 Music *mus = unsmob_music ($1);
660 bool is_event = mus &&
661 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
666 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
668 | post_event_nofinger {
671 | number_expression {
686 | context_modification {
691 context_def_spec_block:
692 CONTEXT '{' context_def_spec_body '}'
698 context_def_spec_body:
700 $$ = Context_def::make_scm ();
701 unsmob_context_def ($$)->origin ()->set_spot (@$);
703 | CONTEXT_DEF_IDENTIFIER {
705 unsmob_context_def ($$)->origin ()->set_spot (@$);
707 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
708 Context_def*td = unsmob_context_def ($$);
710 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
711 SCM tag = scm_caar (p);
713 /* TODO: should make new tag "grob-definition" ? */
714 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
715 tag, scm_cons (scm_cdar (p), SCM_EOL)));
718 | context_def_spec_body context_mod {
719 unsmob_context_def ($$)->add_context_mod ($2);
721 | context_def_spec_body context_modification {
722 Context_def *td = unsmob_context_def ($$);
723 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
724 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
725 td->add_context_mod (scm_car (m));
733 BOOK '{' book_body '}' {
736 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
741 * Use 'handlers' like for toplevel-* stuff?
742 * grok \layout and \midi? */
746 init_papers (PARSER);
747 $$->origin ()->set_spot (@$);
748 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
749 $$->paper_->unprotect ();
750 push_paper (PARSER, $$->paper_);
751 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
752 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
753 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
754 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
757 $$ = unsmob_book ($1);
759 $$->origin ()->set_spot (@$);
760 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
762 | book_body paper_block {
765 set_paper (PARSER, $2);
767 | book_body bookpart_block {
769 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
770 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
771 bookpart->unprotect ();
773 | book_body score_block {
775 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
776 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
779 | book_body composite_music {
780 Music *music = unsmob_music ($2);
781 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
782 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
784 | book_body full_markup {
785 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
786 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
788 | book_body full_markup_list {
789 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
790 scm_call_2 (proc, $$->self_scm (), $2);
792 | book_body lilypond_header {
797 $$->scores_ = SCM_EOL;
798 $$->bookparts_ = SCM_EOL;
803 BOOKPART '{' bookpart_body '}' {
805 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
812 $$->origin ()->set_spot (@$);
813 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
816 $$ = unsmob_book ($1);
818 $$->origin ()->set_spot (@$);
819 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
821 | bookpart_body paper_block {
825 | bookpart_body score_block {
827 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
828 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
831 | bookpart_body composite_music {
832 Music *music = unsmob_music ($2);
833 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
834 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
836 | bookpart_body full_markup {
837 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
838 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
840 | bookpart_body full_markup_list {
841 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
842 scm_call_2 (proc, $$->self_scm (), $2);
844 | bookpart_body lilypond_header {
847 | bookpart_body error {
849 $$->scores_ = SCM_EOL;
854 SCORE '{' score_body '}' {
862 SCM scorify = ly_lily_module_constant ("scorify-music");
863 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
865 // pass ownernship to C++ again.
866 $$ = unsmob_score (score);
868 $$->origin ()->set_spot (@$);
871 $$ = unsmob_score ($1);
873 $$->origin ()->set_spot (@$);
875 | score_body lilypond_header {
878 | score_body output_def {
879 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
881 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
886 $$->add_output_def ($2);
891 $$->error_found_ = true;
903 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
905 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
907 $$ = get_paper (PARSER);
914 output_def_body '}' {
917 PARSER->lexer_->remove_scope ();
918 PARSER->lexer_->pop_state ();
924 $$ = get_paper (PARSER);
925 $$->input_origin_ = @$;
926 PARSER->lexer_->add_scope ($$->scope_);
929 Output_def *p = get_midi (PARSER);
931 PARSER->lexer_->add_scope (p->scope_);
934 Output_def *p = get_layout (PARSER);
936 PARSER->lexer_->add_scope (p->scope_);
941 output_def_head_with_mode_switch:
943 PARSER->lexer_->push_initial_state ();
949 output_def_head_with_mode_switch '{' {
951 $$->input_origin_.set_spot (@$);
953 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
956 Output_def *o = unsmob_output_def ($3);
957 o->input_origin_.set_spot (@$);
960 PARSER->lexer_->remove_scope ();
961 PARSER->lexer_->add_scope (o->scope_);
963 | output_def_body assignment {
966 | output_def_body context_def_spec_block {
967 assign_context_def ($$, $2);
969 | output_def_body error {
975 TEMPO steno_duration '=' tempo_range {
976 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
978 | TEMPO closed_scalar steno_duration '=' tempo_range {
979 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
981 | TEMPO closed_scalar {
982 $$ = MAKE_SYNTAX ("tempo", @$, $2);
987 The representation of a list is reversed to have efficient append. */
994 $$ = scm_cons ($2, $1);
996 | music_list embedded_scm {
1000 Music *m = MY_MAKE_MUSIC("Music", @$);
1002 m->set_property ("error-found", SCM_BOOL_T);
1003 $$ = scm_cons (m->self_scm (), $1);
1004 m->unprotect (); /* UGH */
1018 | ALTERNATIVE '{' music_list '}' {
1019 $$ = scm_reverse_x ($3, SCM_EOL);
1025 REPEAT simple_string unsigned_number music alternative_music
1027 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $5);
1032 SEQUENTIAL '{' music_list '}' {
1033 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_reverse_x ($3, SCM_EOL));
1035 | '{' music_list '}' {
1036 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_reverse_x ($2, SCM_EOL));
1041 SIMULTANEOUS '{' music_list '}'{
1042 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($3, SCM_EOL));
1044 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1045 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1051 | music_property_def
1055 context_modification:
1056 WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1058 PARSER->lexer_->pop_state ();
1061 | WITH CONTEXT_MOD_IDENTIFIER
1065 | CONTEXT_MOD_IDENTIFIER
1071 optional_context_mod:
1075 | context_modification
1083 $$ = Context_mod ().smobbed_copy ();
1085 | context_mod_list context_mod {
1086 unsmob_context_mod ($1)->add_context_mod ($2);
1088 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1089 Context_mod *md = unsmob_context_mod ($2);
1091 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1096 prefix_composite_music { $$ = $1; }
1097 | grouped_music_list { $$ = $1; }
1100 /* Music that can't be followed by additional events or durations */
1103 | grouped_music_list
1106 /* Music that potentially accepts additional events or durations */
1109 | prefix_composite_music
1113 simultaneous_music { $$ = $1; }
1114 | sequential_music { $$ = $1; }
1117 function_scm_argument:
1122 /* An argument list. If a function \foo expects scm scm music, then the lexer expands \foo into the token sequence:
1123 MUSIC_FUNCTION EXPECT_MUSIC EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1124 and this rule returns the reversed list of arguments. */
1128 closed_function_arglist
1129 | open_function_arglist
1132 open_function_arglist:
1133 EXPECT_MUSIC function_arglist open_music {
1134 $$ = scm_cons ($3, $2);
1136 | EXPECT_SCM function_arglist open_scm_function_call {
1137 $$ = scm_cons ($3, $2);
1141 /* a closed argument list is one that does not end in a music
1142 expression that could still take a duration or event */
1144 closed_function_arglist:
1145 function_arglist_nonmusic_last
1146 | EXPECT_MUSIC function_arglist closed_music {
1147 $$ = scm_cons ($3, $2);
1151 function_arglist_nonmusic_last:
1152 EXPECT_NO_MORE_ARGS {
1153 /* This is for 0-ary functions, so they don't need to
1154 read a lookahead token */
1157 | EXPECT_MARKUP function_arglist full_markup {
1158 $$ = scm_cons ($3, $2);
1160 | EXPECT_MARKUP function_arglist simple_string {
1161 $$ = scm_cons ($3, $2);
1163 | EXPECT_PITCH function_arglist pitch_also_in_chords {
1164 $$ = scm_cons ($3, $2);
1166 | EXPECT_DURATION closed_function_arglist duration_length {
1167 $$ = scm_cons ($3, $2);
1169 | EXPECT_SCM function_arglist function_scm_argument {
1170 $$ = scm_cons ($3, $2);
1174 generic_prefix_music_scm:
1175 MUSIC_FUNCTION function_arglist {
1176 $$ = run_music_function (PARSER, @$,
1183 /**/ { $$ = SCM_EOL; }
1184 | '=' simple_string {
1190 prefix_composite_music:
1191 generic_prefix_music_scm
1192 | CONTEXT simple_string optional_id optional_context_mod music {
1193 Context_mod *ctxmod = unsmob_context_mod ($4);
1196 mods = ctxmod->get_mods ();
1197 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, mods, SCM_BOOL_F);
1199 | NEWCONTEXT simple_string optional_id optional_context_mod music {
1200 Context_mod *ctxmod = unsmob_context_mod ($4);
1203 mods = ctxmod->get_mods ();
1204 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, mods, SCM_BOOL_T);
1207 | TIMES fraction music {
1208 $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3);
1210 | repeated_music { $$ = $1; }
1211 | mode_changing_head grouped_music_list {
1212 if ($1 == ly_symbol2scm ("chords"))
1214 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1220 PARSER->lexer_->pop_state ();
1222 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1223 Context_mod *ctxmod = unsmob_context_mod ($2);
1226 mods = ctxmod->get_mods ();
1227 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, $3, mods, SCM_BOOL_T);
1228 if ($1 == ly_symbol2scm ("ChordNames"))
1230 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1232 PARSER->lexer_->pop_state ();
1234 | relative_music { $$ = $1; }
1235 | re_rhythmed_music { $$ = $1; }
1240 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1241 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1243 $$ = ly_symbol2scm ("notes");
1247 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1248 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1250 $$ = ly_symbol2scm ("drums");
1253 PARSER->lexer_->push_figuredbass_state ();
1255 $$ = ly_symbol2scm ("figures");
1258 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1259 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1260 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1261 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1262 $$ = ly_symbol2scm ("chords");
1266 { PARSER->lexer_->push_lyric_state ();
1267 $$ = ly_symbol2scm ("lyrics");
1271 mode_changing_head_with_context:
1273 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1274 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1276 $$ = ly_symbol2scm ("DrumStaff");
1279 PARSER->lexer_->push_figuredbass_state ();
1281 $$ = ly_symbol2scm ("FiguredBass");
1284 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1285 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1286 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1287 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1288 $$ = ly_symbol2scm ("ChordNames");
1291 { PARSER->lexer_->push_lyric_state ();
1292 $$ = ly_symbol2scm ("Lyrics");
1298 RELATIVE absolute_pitch music {
1299 Pitch start = *unsmob_pitch ($2);
1300 $$ = make_music_relative (start, $3, @$);
1302 | RELATIVE composite_music {
1303 Pitch middle_c (0, 0, 0);
1304 $$ = make_music_relative (middle_c, $2, @$);
1309 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1312 /* Can also use music at the expensive of two S/Rs similar to
1313 \repeat \alternative */
1314 PARSER->lexer_->pop_state ();
1316 $$ = scm_cons ($3, SCM_EOL);
1318 | new_lyrics ADDLYRICS {
1319 PARSER->lexer_->push_lyric_state ();
1321 PARSER->lexer_->pop_state ();
1322 $$ = scm_cons ($4, $1);
1327 closed_music new_lyrics {
1328 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1330 | LYRICSTO simple_string {
1331 PARSER->lexer_->push_lyric_state ();
1333 PARSER->lexer_->pop_state ();
1334 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1339 CHANGE STRING '=' STRING {
1340 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1345 property_path_revved:
1346 closed_embedded_scm {
1347 $$ = scm_cons ($1, SCM_EOL);
1349 | property_path_revved closed_embedded_scm {
1350 $$ = scm_cons ($2, $1);
1355 property_path_revved {
1356 $$ = scm_reverse_x ($1, SCM_EOL);
1362 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1363 scm_string_to_symbol ($1), $3);
1365 | UNSET simple_string {
1366 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1367 scm_string_to_symbol ($2));
1369 | OVERRIDE simple_string property_path '=' scalar {
1370 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1371 scm_string_to_symbol ($2), $5),
1374 | REVERT simple_string embedded_scm {
1375 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1376 scm_string_to_symbol ($2), $3);
1381 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1382 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1384 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1385 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1386 | DENIES { $$ = ly_symbol2scm ("denies"); }
1388 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1389 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1390 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1391 | NAME { $$ = ly_symbol2scm ("context-name"); }
1395 property_operation { $$ = $1; }
1396 | context_def_mod STRING {
1397 $$ = scm_list_2 ($1, $2);
1399 | context_def_mod embedded_scm {
1400 if (ly_symbol2scm ("consists") != $1)
1403 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1407 $$ = scm_list_2 ($1, $2);
1414 if (!is_regular_identifier ($1))
1416 @$.error (_("Grob name should be alphanumeric"));
1419 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1420 scm_string_to_symbol ($1));
1422 | simple_string '.' simple_string {
1423 $$ = scm_list_2 (scm_string_to_symbol ($1),
1424 scm_string_to_symbol ($3));
1428 simple_music_property_def:
1429 OVERRIDE context_prop_spec property_path '=' scalar {
1430 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1431 ly_symbol2scm ("OverrideProperty"),
1436 | REVERT context_prop_spec embedded_scm {
1437 $$ = scm_list_4 (scm_car ($2),
1438 ly_symbol2scm ("RevertProperty"),
1442 | SET context_prop_spec '=' scalar {
1443 $$ = scm_list_4 (scm_car ($2),
1444 ly_symbol2scm ("PropertySet"),
1448 | UNSET context_prop_spec {
1449 $$ = scm_list_3 (scm_car ($2),
1450 ly_symbol2scm ("PropertyUnset"),
1456 simple_music_property_def {
1457 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1459 | ONCE simple_music_property_def {
1460 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1468 | STRING_IDENTIFIER {
1471 | string '+' string {
1472 $$ = scm_string_append (scm_list_2 ($1, $3));
1476 simple_string: STRING {
1482 | STRING_IDENTIFIER {
1487 closed_scalar: string {
1496 | closed_embedded_scm {
1504 scalar: closed_scalar
1505 | open_scm_function_call
1509 /* TODO: Create a special case that avoids the creation of
1510 EventChords around simple_elements that have no post_events?
1512 simple_chord_elements post_events {
1513 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1516 /* why is this giving wrong start location? -ns
1518 i.set_location (@1, @2);
1519 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1521 | CHORD_REPETITION optional_notemode_duration post_events {
1523 i.set_location (@1, @3);
1524 $$ = MAKE_SYNTAX ("repetition-chord", i,
1525 PARSER->lexer_->chord_repetition_.last_chord_,
1526 PARSER->lexer_->chord_repetition_.repetition_function_,
1527 $2, scm_reverse_x ($3, SCM_EOL));
1529 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1531 i.set_location (@1, @3);
1532 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1533 scm_reverse_x ($3, SCM_EOL));
1536 /* note chord elements are memorized into
1537 PARSER->lexer_->chord_repetition_ so that the chord repetition
1538 mechanism copy them when a chord repetition symbol is found
1540 | note_chord_element {
1541 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
1547 chord_body optional_notemode_duration post_events
1549 Music *m = unsmob_music ($1);
1550 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1551 SCM es = m->get_property ("elements");
1552 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1554 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1555 unsmob_music (scm_car (s))->set_property ("duration", dur);
1556 es = ly_append2 (es, postevs);
1558 m-> set_property ("elements", es);
1560 $$ = m->self_scm ();
1565 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1567 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1571 chord_body_elements:
1572 /* empty */ { $$ = SCM_EOL; }
1573 | chord_body_elements chord_body_element {
1574 $$ = scm_cons ($2, $1);
1579 pitch exclamations questions octave_check post_events
1586 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1587 n->set_property ("pitch", $1);
1589 n->set_property ("cautionary", SCM_BOOL_T);
1590 if (ex % 2 || q % 2)
1591 n->set_property ("force-accidental", SCM_BOOL_T);
1593 if (scm_is_pair (post)) {
1594 SCM arts = scm_reverse_x (post, SCM_EOL);
1595 n->set_property ("articulations", arts);
1597 if (scm_is_number (check))
1599 int q = scm_to_int (check);
1600 n->set_property ("absolute-octave", scm_from_int (q-1));
1603 $$ = n->unprotect ();
1605 | DRUM_PITCH post_events {
1606 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1607 n->set_property ("drum-type", $1);
1609 if (scm_is_pair ($2)) {
1610 SCM arts = scm_reverse_x ($2, SCM_EOL);
1611 n->set_property ("articulations", arts);
1613 $$ = n->unprotect ();
1615 | music_function_chord_body
1618 /* We can't accept a music argument, not even a closed one,
1619 * immediately before chord_body_elements, otherwise a function \fun
1620 * with a signature of two music arguments can't be sorted out
1621 * properly in a construct like
1622 * <\fun { c } \fun { c } c>
1623 * The second call could be interpreted either as a chord constituent
1624 * or a music expression.
1627 music_function_chord_body_arglist:
1628 function_arglist_nonmusic_last
1629 | EXPECT_MUSIC music_function_chord_body_arglist chord_body_element {
1630 $$ = scm_cons ($3, $2);
1634 music_function_chord_body:
1635 MUSIC_FUNCTION music_function_chord_body_arglist {
1636 $$ = run_music_function (PARSER, @$,
1641 /* We could accept a closed music argument before the post events
1642 * indicated by a trailing argument list. For symmetry with chord
1643 * bodies and in order to avoid too tricky and complex behavior, we
1644 * refrain from doing so.
1646 music_function_event_arglist:
1647 function_arglist_nonmusic_last
1648 | EXPECT_MUSIC music_function_event_arglist post_event {
1649 $$ = scm_cons ($3, $2);
1653 music_function_event:
1654 MUSIC_FUNCTION music_function_event_arglist {
1655 $$ = run_music_function (PARSER, @$,
1664 | SKIP duration_length {
1665 $$ = MAKE_SYNTAX ("skip-music", @$, $2);
1668 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1669 m->set_property ("span-direction", scm_from_int (START));
1670 $$ = m->unprotect();
1673 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1674 m->set_property ("span-direction", scm_from_int (STOP));
1675 $$ = m->unprotect ();
1678 $$ = MAKE_SYNTAX ("voice-separator", @$, SCM_UNDEFINED);
1681 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1683 Music *m = unsmob_music (pipe);
1688 $$ = m->unprotect ();
1691 $$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
1694 | PARTIAL duration_length {
1695 $$ = MAKE_SYNTAX ("partial", @$, $2);
1699 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1701 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1704 $$ = MAKE_SYNTAX ("make-mark-set", @$, $2);
1710 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
1713 Music *m = MY_MAKE_MUSIC ("MarkEvent", @$);
1714 $$ = m->unprotect ();
1720 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1721 $$ = key->unprotect ();
1723 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1725 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1726 if (scm_ilength ($3) > 0)
1728 key->set_property ("pitch-alist", $3);
1729 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1730 key->transpose (* unsmob_pitch ($2));
1732 PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1735 $$ = key->unprotect ();
1744 | post_events post_event {
1745 unsmob_music ($2)->set_spot (@2);
1746 $$ = scm_cons ($2, $$);
1750 post_event_nofinger:
1751 direction_less_event {
1754 | script_dir music_function_event {
1758 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
1762 if (!PARSER->lexer_->is_lyric_state ())
1763 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1764 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
1767 if (!PARSER->lexer_->is_lyric_state ())
1768 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1769 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
1771 | script_dir direction_reqd_event {
1774 Music *m = unsmob_music ($2);
1775 m->set_property ("direction", scm_from_int ($1));
1779 | script_dir direction_less_event {
1782 Music *m = unsmob_music ($2);
1783 m->set_property ("direction", scm_from_int ($1));
1787 | string_number_event
1792 | script_dir fingering {
1795 Music *m = unsmob_music ($2);
1796 m->set_property ("direction", scm_from_int ($1));
1802 string_number_event:
1804 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
1805 s->set_property ("string-number", scm_from_int ($1));
1806 $$ = s->unprotect ();
1810 direction_less_char:
1812 $$ = ly_symbol2scm ("bracketOpenSymbol");
1815 $$ = ly_symbol2scm ("bracketCloseSymbol");
1818 $$ = ly_symbol2scm ("tildeSymbol");
1821 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1824 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1827 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1830 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1833 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1836 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1839 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1843 direction_less_event:
1844 direction_less_char {
1845 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
1847 if (unsmob_music (predefd))
1849 m = unsmob_music (predefd)->clone ();
1854 m = MY_MAKE_MUSIC ("Music", @$);
1856 $$ = m->unprotect ();
1858 | EVENT_IDENTIFIER {
1862 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
1863 a->set_property ("tremolo-type", scm_from_int ($1));
1864 $$ = a->unprotect ();
1868 direction_reqd_event:
1872 | script_abbreviation {
1873 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1874 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
1875 if (scm_is_string (s))
1876 a->set_property ("articulation-type", s);
1877 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
1878 $$ = a->unprotect ();
1883 /**/ { $$ = SCM_EOL; }
1884 | '=' { $$ = scm_from_int (0); }
1885 | '=' sub_quotes { $$ = scm_from_int (-$2); }
1886 | '=' sup_quotes { $$ = scm_from_int ($2); }
1911 | NOTENAME_PITCH sup_quotes {
1912 Pitch p = *unsmob_pitch ($1);
1913 p = p.transposed (Pitch ($2,0,0));
1914 $$ = p.smobbed_copy ();
1916 | NOTENAME_PITCH sub_quotes {
1917 Pitch p =* unsmob_pitch ($1);
1918 p = p.transposed (Pitch (-$2,0,0));
1919 $$ = p.smobbed_copy ();
1931 | TONICNAME_PITCH sup_quotes {
1932 Pitch p = *unsmob_pitch ($1);
1933 p = p.transposed (Pitch ($2,0,0));
1934 $$ = p.smobbed_copy ();
1936 | TONICNAME_PITCH sub_quotes {
1937 Pitch p = *unsmob_pitch ($1);
1939 p = p.transposed (Pitch (-$2,0,0));
1940 $$ = p.smobbed_copy ();
1950 pitch_also_in_chords:
1957 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1958 t->set_property ("text", $1);
1959 $$ = t->unprotect ();
1962 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1963 t->set_property ("text",
1964 make_simple_markup ($1));
1965 $$ = t->unprotect ();
1971 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
1972 t->set_property ("digit", scm_from_int ($1));
1973 $$ = t->unprotect ();
1977 script_abbreviation:
1979 $$ = scm_from_locale_string ("Hat");
1982 $$ = scm_from_locale_string ("Plus");
1985 $$ = scm_from_locale_string ("Dash");
1988 $$ = scm_from_locale_string ("Bar");
1991 $$ = scm_from_locale_string ("Larger");
1994 $$ = scm_from_locale_string ("Dot");
1997 $$ = scm_from_locale_string ("Underscore");
2004 | '-' { $$ = CENTER; }
2015 multiplied_duration {
2020 optional_notemode_duration:
2022 Duration dd = PARSER->default_duration_;
2023 $$ = dd.smobbed_copy ();
2025 | multiplied_duration {
2027 PARSER->default_duration_ = *unsmob_duration ($$);
2032 bare_unsigned dots {
2034 if (!is_duration ($1))
2035 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
2039 $$ = Duration (len, $2).smobbed_copy ();
2041 | DURATION_IDENTIFIER dots {
2042 Duration *d = unsmob_duration ($1);
2043 Duration k (d->duration_log (), d->dot_count () + $2);
2044 k = k.compressed (d->factor ());
2050 multiplied_duration:
2054 | multiplied_duration '*' bare_unsigned {
2055 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2057 | multiplied_duration '*' FRACTION {
2058 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2060 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2065 FRACTION { $$ = $1; }
2066 | UNSIGNED '/' UNSIGNED {
2067 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2084 | ':' bare_unsigned {
2085 if (!is_duration ($2))
2086 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2093 $$ = scm_from_int ($1);
2095 | STRING { $$ = $1; }
2096 | full_markup { $$ = $1; }
2099 figured_bass_alteration:
2100 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2101 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2102 | '!' { $$ = scm_from_int (0); }
2107 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2108 $$ = bfr->unprotect ();
2111 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2112 $$ = bfr->self_scm ();
2114 if (scm_is_number ($1))
2115 bfr->set_property ("figure", $1);
2116 else if (Text_interface::is_markup ($1))
2117 bfr->set_property ("text", $1);
2123 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2125 | bass_figure figured_bass_alteration {
2126 Music *m = unsmob_music ($1);
2127 if (scm_to_double ($2)) {
2128 SCM salter = m->get_property ("alteration");
2129 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2130 m->set_property ("alteration",
2131 scm_sum (alter, $2));
2133 m->set_property ("alteration", scm_from_int (0));
2136 | bass_figure figured_bass_modification {
2137 Music *m = unsmob_music ($1);
2138 if ($2 == ly_symbol2scm ("plus"))
2140 m->set_property ("augmented", SCM_BOOL_T);
2142 else if ($2 == ly_symbol2scm ("slash"))
2144 m->set_property ("diminished", SCM_BOOL_T);
2146 else if ($2 == ly_symbol2scm ("exclamation"))
2148 m->set_property ("no-continuation", SCM_BOOL_T);
2150 else if ($2 == ly_symbol2scm ("backslash"))
2152 m->set_property ("augmented-slash", SCM_BOOL_T);
2158 figured_bass_modification:
2160 $$ = ly_symbol2scm ("plus");
2163 $$ = ly_symbol2scm ("exclamation");
2166 $$ = ly_symbol2scm ("slash");
2169 $$ = ly_symbol2scm ("backslash");
2179 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2187 | figure_list br_bass_figure {
2188 $$ = scm_cons ($2, $1);
2193 FIGURE_OPEN figure_list FIGURE_CLOSE {
2194 $$ = scm_reverse_x ($2, SCM_EOL);
2205 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2206 if (!PARSER->lexer_->is_note_state ())
2207 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2211 n = MY_MAKE_MUSIC ("RestEvent", @$);
2213 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2215 n->set_property ("pitch", $1);
2216 n->set_property ("duration", $5);
2218 if (scm_is_number ($4))
2220 int q = scm_to_int ($4);
2221 n->set_property ("absolute-octave", scm_from_int (q-1));
2225 n->set_property ("cautionary", SCM_BOOL_T);
2226 if ($2 % 2 || $3 % 2)
2227 n->set_property ("force-accidental", SCM_BOOL_T);
2229 $$ = n->unprotect ();
2231 | DRUM_PITCH optional_notemode_duration {
2232 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2233 n->set_property ("duration", $2);
2234 n->set_property ("drum-type", $1);
2236 $$ = n->unprotect ();
2238 | RESTNAME optional_notemode_duration {
2240 if (ly_scm2string ($1) == "s") {
2242 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2245 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2248 ev->set_property ("duration", $2);
2249 $$ = ev->unprotect ();
2251 | lyric_element optional_notemode_duration {
2252 if (!PARSER->lexer_->is_lyric_state ())
2253 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2255 Music *levent = MY_MAKE_MUSIC ("LyricEvent", @$);
2256 levent->set_property ("text", $1);
2257 levent->set_property ("duration",$2);
2258 $$= levent->unprotect ();
2262 simple_chord_elements:
2264 $$ = scm_list_1 ($1);
2267 if (!PARSER->lexer_->is_chord_state ())
2268 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2271 | figure_spec optional_notemode_duration {
2272 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2274 unsmob_music (scm_car (s))->set_property ("duration", $2);
2290 steno_tonic_pitch optional_notemode_duration {
2291 $$ = make_chord_elements ($1, $2, SCM_EOL);
2293 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2294 SCM its = scm_reverse_x ($4, SCM_EOL);
2295 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2303 | chord_items chord_item {
2304 $$ = scm_cons ($2, $$);
2310 $$ = ly_symbol2scm ("chord-colon");
2313 $$ = ly_symbol2scm ("chord-caret");
2315 | CHORD_SLASH steno_tonic_pitch {
2316 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2318 | CHORD_BASS steno_tonic_pitch {
2319 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2328 $$ = scm_reverse_x ($1, SCM_EOL);
2336 step_number { $$ = scm_cons ($1, SCM_EOL); }
2337 | step_numbers '.' step_number {
2338 $$ = scm_cons ($3, $$);
2344 $$ = make_chord_step ($1, 0);
2346 | bare_unsigned '+' {
2347 $$ = make_chord_step ($1, SHARP_ALTERATION);
2349 | bare_unsigned CHORD_MINUS {
2350 $$ = make_chord_step ($1, FLAT_ALTERATION);
2356 $$ = scm_from_int ($1);
2358 | bare_unsigned '~' bare_unsigned {
2359 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2366 TODO: should deprecate in favor of Scheme?
2370 number_expression '+' number_term {
2371 $$ = scm_sum ($1, $3);
2373 | number_expression '-' number_term {
2374 $$ = scm_difference ($1, $3);
2383 | number_factor '*' number_factor {
2384 $$ = scm_product ($1, $3);
2386 | number_factor '/' number_factor {
2387 $$ = scm_divide ($1, $3);
2392 '-' number_factor { /* %prec UNARY_MINUS */
2393 $$ = scm_difference ($2, SCM_UNDEFINED);
2401 $$ = scm_from_int ($1);
2406 | NUMBER_IDENTIFIER {
2409 | REAL NUMBER_IDENTIFIER {
2410 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2412 | UNSIGNED NUMBER_IDENTIFIER {
2413 $$ = scm_from_double ($1 *scm_to_double ($2));
2425 bare_unsigned { $$ = scm_from_int ($1); }
2426 | NUMBER_IDENTIFIER {
2433 | exclamations '!' { $$ ++; }
2438 | questions '?' { $$ ++; }
2442 This should be done more dynamically if possible.
2446 LYRIC_MARKUP_IDENTIFIER {
2450 { PARSER->lexer_->push_markup_state (); }
2453 PARSER->lexer_->pop_state ();
2458 MARKUPLINES_IDENTIFIER {
2462 { PARSER->lexer_->push_markup_state (); }
2465 PARSER->lexer_->pop_state ();
2474 { PARSER->lexer_->push_markup_state (); }
2477 PARSER->lexer_->pop_state ();
2483 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2485 | markup_head_1_list simple_markup {
2486 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2494 MARKUPLINES_IDENTIFIER {
2497 | markup_composed_list {
2500 | markup_braced_list {
2503 | markup_command_list {
2504 $$ = scm_list_1 ($1);
2508 markup_composed_list:
2509 markup_head_1_list markup_braced_list {
2510 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2516 '{' markup_braced_list_body '}' {
2517 $$ = scm_reverse_x ($2, SCM_EOL);
2521 markup_braced_list_body:
2522 /* empty */ { $$ = SCM_EOL; }
2523 | markup_braced_list_body markup {
2524 $$ = scm_cons ($2, $1);
2526 | markup_braced_list_body markup_list {
2527 $$ = scm_reverse_x ($2, $1);
2531 markup_command_list:
2532 MARKUP_LIST_FUNCTION closed_markup_command_list_arguments {
2533 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
2537 markup_command_basic_arguments:
2538 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
2539 $$ = scm_cons ($3, $2);
2541 | EXPECT_SCM markup_command_list_arguments closed_embedded_scm {
2542 $$ = scm_cons ($3, $2);
2544 | EXPECT_NO_MORE_ARGS {
2549 closed_markup_command_list_arguments:
2550 markup_command_basic_arguments { $$ = $1; }
2551 | EXPECT_MARKUP markup_command_list_arguments markup {
2552 $$ = scm_cons ($3, $2);
2556 markup_command_list_arguments:
2557 closed_markup_command_list_arguments
2558 | EXPECT_SCM markup_command_list_arguments open_scm_function_call
2560 $$ = scm_cons ($3, $2);
2565 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
2566 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
2571 markup_head_1_item {
2572 $$ = scm_list_1 ($1);
2574 | markup_head_1_list markup_head_1_item {
2575 $$ = scm_cons ($2, $1);
2581 $$ = make_simple_markup ($1);
2583 | MARKUP_IDENTIFIER {
2586 | LYRIC_MARKUP_IDENTIFIER {
2589 | STRING_IDENTIFIER {
2593 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2594 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2595 } '{' score_body '}' {
2597 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2599 PARSER->lexer_->pop_state ();
2601 | MARKUP_FUNCTION markup_command_basic_arguments {
2602 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
2607 markup_head_1_list simple_markup {
2608 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2609 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2619 Lily_parser::set_yydebug (bool x)
2625 Lily_parser::do_yyparse ()
2627 yyparse ((void*)this);
2636 It is a little strange to have this function in this file, but
2637 otherwise, we have to import music classes into the lexer.
2641 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2643 if (scm_is_string (sid)) {
2645 return STRING_IDENTIFIER;
2646 } else if (unsmob_book (sid)) {
2647 Book *book = unsmob_book (sid)->clone ();
2648 *destination = book->self_scm ();
2651 return BOOK_IDENTIFIER;
2652 } else if (scm_is_number (sid)) {
2654 return NUMBER_IDENTIFIER;
2655 } else if (unsmob_context_def (sid)) {
2656 Context_def *def= unsmob_context_def (sid)->clone ();
2658 *destination = def->self_scm ();
2661 return CONTEXT_DEF_IDENTIFIER;
2662 } else if (unsmob_context_mod (sid)) {
2663 *destination = unsmob_context_mod (sid)->smobbed_copy ();
2665 return CONTEXT_MOD_IDENTIFIER;
2666 } else if (unsmob_score (sid)) {
2667 Score *score = new Score (*unsmob_score (sid));
2668 *destination = score->self_scm ();
2670 score->unprotect ();
2671 return SCORE_IDENTIFIER;
2672 } else if (Music *mus = unsmob_music (sid)) {
2673 mus = mus->clone ();
2674 *destination = mus->self_scm ();
2675 unsmob_music (*destination)->
2676 set_property ("origin", make_input (last_input_));
2678 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2682 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2683 } else if (unsmob_duration (sid)) {
2684 *destination = unsmob_duration (sid)->smobbed_copy ();
2685 return DURATION_IDENTIFIER;
2686 } else if (unsmob_output_def (sid)) {
2687 Output_def *p = unsmob_output_def (sid);
2690 *destination = p->self_scm ();
2692 return OUTPUT_DEF_IDENTIFIER;
2693 } else if (Text_interface::is_markup (sid)) {
2695 if (is_lyric_state ())
2696 return LYRIC_MARKUP_IDENTIFIER;
2697 return MARKUP_IDENTIFIER;
2698 } else if (Text_interface::is_markup_list (sid)) {
2700 return MARKUPLINES_IDENTIFIER;
2707 get_next_unique_context_id ()
2709 return scm_from_locale_string ("$uniqueContextId");
2714 get_next_unique_lyrics_context_id ()
2716 static int new_context_count;
2718 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2719 return scm_from_locale_string (s);
2724 run_music_function (Lily_parser *parser, Input loc, SCM func, SCM args)
2726 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2728 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2730 args = scm_reverse_x (args, SCM_EOL);
2732 if (!to_boolean (scm_call_3 (type_check_proc, make_input (loc), scm_cdr (sig), args)))
2734 parser->error_level_ = 1;
2735 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (loc)));
2738 SCM syntax_args = scm_list_5 (parser->self_scm (), make_input (loc), scm_car (sig), func, args);
2739 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
2743 is_regular_identifier (SCM id)
2745 string str = ly_scm2string (id);
2746 char const *s = str.c_str ();
2755 v = v && isalnum (*s);
2762 make_music_with_input (SCM name, Input where)
2764 Music *m = make_music_by_name (name);
2765 m->set_spot (where);
2770 get_first_context_id (SCM type, Music *m)
2772 SCM id = m->get_property ("context-id");
2773 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2774 && scm_is_string (m->get_property ("context-id"))
2775 && scm_c_string_length (id) > 0)
2783 make_simple_markup (SCM a)
2791 return t && t == 1 << intlog2 (t);
2795 set_music_properties (Music *p, SCM a)
2797 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2798 p->set_property (scm_caar (k), scm_cdar (k));
2803 make_chord_step (int step, Rational alter)
2806 alter += FLAT_ALTERATION;
2810 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2811 return m.smobbed_copy ();
2816 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
2818 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
2819 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
2823 /* Todo: actually also use apply iso. call too ... */
2825 ly_input_procedure_p (SCM x)
2827 return ly_is_procedure (x)
2828 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2832 make_music_relative (Pitch start, SCM music, Input loc)
2834 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic", loc);
2835 relative->set_property ("element", music);
2837 Music *m = unsmob_music (music);
2838 Pitch last = m->to_relative_octave (start);
2839 if (lily_1_8_relative)
2840 m->set_property ("last-pitch", last.smobbed_copy ());
2841 return relative->unprotect ();
2845 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2847 Lily_parser *pars = (Lily_parser*) v;
2848 Lily_lexer *lex = pars->lexer_;
2850 lex->lexval_ = (void*) s;
2852 lex->prepare_for_next_token ();
2853 return lex->yylex ();