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. */
47 /* The above precedences tackle the shift/reduce problem
50 \repeat .. \alternative
52 \repeat { \repeat .. \alternative }
56 \repeat { \repeat } \alternative
59 %right FUNCTION_ARGUMENTS
60 MARKUP LYRICS_STRING MARKUP_IDENTIFIER STRING STRING_IDENTIFIER
61 SEQUENTIAL SIMULTANEOUS DOUBLE_ANGLE_OPEN MUSIC_IDENTIFIER '{'
62 PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
63 SCM_FUNCTION SCM_IDENTIFIER SCM_TOKEN
64 UNSIGNED DURATION_IDENTIFIER
65 CHORDMODE CHORDS DRUMMODE DRUMS FIGUREMODE FIGURES LYRICMODE LYRICS
67 CONTEXT TIMES NEWCONTEXT
69 /* The above are the symbols that can start function arguments */
82 %{ // -*-Fundamental-*-
87 * The rules for who is protecting what are very shady. Uniformise
90 * There are too many lexical modes?
101 #include "context-def.hh"
102 #include "context-mod.hh"
103 #include "dimensions.hh"
104 #include "file-path.hh"
106 #include "international.hh"
107 #include "lily-guile.hh"
108 #include "lily-lexer.hh"
109 #include "lily-parser.hh"
113 #include "output-def.hh"
114 #include "paper-book.hh"
115 #include "scm-hash.hh"
117 #include "text-interface.hh"
120 #define MYBACKUP(Token, Value, Location) \
122 if (yychar == YYEMPTY) \
123 PARSER->lexer_->push_extra_token (Token, Value); \
125 PARSER->parser_error \
126 (Location, _("cannot backup token")); \
134 Output_def *outputdef;
144 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
147 - Don't use lily module, create a new module instead.
148 - delay application of the function
150 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
151 scm_apply_0 (proc, args)
152 /* Syntactic Sugar. */
153 #define MAKE_SYNTAX(name, location, ...) \
154 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location), ##__VA_ARGS__, SCM_UNDEFINED));
155 #define START_MAKE_SYNTAX(name, ...) \
156 scm_list_n (ly_lily_module_constant (name), ##__VA_ARGS__, SCM_UNDEFINED)
157 #define FINISH_MAKE_SYNTAX(start, location, ...) \
158 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (PARSER->self_scm (), make_input (location), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
160 SCM get_next_unique_context_id ();
161 SCM get_next_unique_lyrics_context_id ();
168 #define _(x) gettext (x)
172 static Music *make_music_with_input (SCM name, Input where);
173 SCM check_scheme_arg (Lily_parser *parser, Input loc, SCM fallback,
174 SCM arg, SCM args, SCM pred);
175 SCM loc_on_music (Input loc, SCM arg);
176 SCM get_first_context_id (SCM type, Music *m);
177 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
178 SCM make_chord_step (int step, Rational alter);
179 SCM make_simple_markup (SCM a);
180 bool is_duration (int t);
181 bool is_regular_identifier (SCM id);
182 bool ly_input_procedure_p (SCM x);
183 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
184 void set_music_properties (Music *p, SCM a);
188 /* The third option is an alias that will be used to display the
189 syntax error. Bison CVS now correctly handles backslash escapes.
191 FIXME: Bison needs to translate some of these, eg, STRING.
195 /* Keyword tokens with plain escaped name. */
196 %token ACCEPTS "\\accepts"
197 %token ADDLYRICS "\\addlyrics"
198 %token ALIAS "\\alias"
199 %token ALTERNATIVE "\\alternative"
201 %token BOOKPART "\\bookpart"
202 %token CHANGE "\\change"
203 %token CHORDMODE "\\chordmode"
204 %token CHORDS "\\chords"
205 %token CONSISTS "\\consists"
206 %token CONTEXT "\\context"
207 %token DEFAULT "\\default"
208 %token DEFAULTCHILD "\\defaultchild"
209 %token DENIES "\\denies"
210 %token DESCRIPTION "\\description"
211 %token DRUMMODE "\\drummode"
212 %token DRUMS "\\drums"
213 %token FIGUREMODE "\\figuremode"
214 %token FIGURES "\\figures"
215 %token GROBDESCRIPTIONS "\\grobdescriptions"
216 %token HEADER "\\header"
217 %token INVALID "\\version-error"
219 %token LAYOUT "\\layout"
220 %token LYRICMODE "\\lyricmode"
221 %token LYRICS "\\lyrics"
222 %token LYRICSTO "\\lyricsto"
224 %token MARKUP "\\markup"
225 %token MARKUPLINES "\\markuplines"
228 %token NOTEMODE "\\notemode"
230 %token OVERRIDE "\\override"
231 %token PAPER "\\paper"
232 %token REMOVE "\\remove"
233 %token REPEAT "\\repeat"
235 %token REVERT "\\revert"
236 %token SCORE "\\score"
237 %token SEQUENTIAL "\\sequential"
239 %token SIMULTANEOUS "\\simultaneous"
240 %token TEMPO "\\tempo"
241 %token TIMES "\\times"
243 %token UNSET "\\unset"
246 /* Keyword token exceptions. */
247 %token TIME_T "\\time"
248 %token NEWCONTEXT "\\new"
251 /* Other string tokens. */
253 %token CHORD_BASS "/+"
254 %token CHORD_CARET "^"
255 %token CHORD_COLON ":"
256 %token CHORD_MINUS "-"
257 %token CHORD_SLASH "/"
258 %token ANGLE_OPEN "<"
259 %token ANGLE_CLOSE ">"
260 %token DOUBLE_ANGLE_OPEN "<<"
261 %token DOUBLE_ANGLE_CLOSE ">>"
262 %token E_BACKSLASH "\\"
263 %token E_ANGLE_CLOSE "\\>"
264 %token E_CHAR "\\C[haracter]"
266 %token E_EXCLAMATION "\\!"
267 %token E_BRACKET_OPEN "\\["
269 %token E_BRACKET_CLOSE "\\]"
270 %token E_ANGLE_OPEN "\\<"
276 If we give names, Bison complains.
278 %token FIGURE_CLOSE /* "\\>" */
279 %token FIGURE_OPEN /* "\\<" */
280 %token FIGURE_SPACE "_"
283 %token CHORDMODIFIERS
285 %token MULTI_MEASURE_REST
288 %token <i> E_UNSIGNED
291 /* Artificial tokens, for more generic function syntax */
292 %token <i> EXPECT_MARKUP "markup?"
293 %token <i> EXPECT_MUSIC "ly:music?"
294 %token <i> EXPECT_PITCH "ly:pitch?"
295 %token <i> EXPECT_DURATION "ly:duration?"
296 %token <scm> EXPECT_SCM "scheme?"
297 %token <scm> SKIPPED_SCM "(scheme?)"
298 %token <i> EXPECT_MARKUP_LIST "markup-list?"
299 %token <scm> EXPECT_OPTIONAL "optional?"
300 /* After the last argument. */
301 %token <i> EXPECT_NO_MORE_ARGS;
303 /* An artificial token for parsing embedded Lilypond */
304 %token <i> EMBEDDED_LILY "#{"
306 %token <scm> BOOK_IDENTIFIER
307 %token <scm> CHORDMODIFIER_PITCH
308 %token <scm> CHORD_MODIFIER
309 %token <scm> CHORD_REPETITION
310 %token <scm> CONTEXT_DEF_IDENTIFIER
311 %token <scm> CONTEXT_MOD_IDENTIFIER
312 %token <scm> DRUM_PITCH
313 %token <scm> PITCH_IDENTIFIER
314 %token <scm> DURATION_IDENTIFIER
315 %token <scm> EVENT_IDENTIFIER
316 %token <scm> EVENT_FUNCTION
317 %token <scm> FRACTION
318 %token <scm> LYRICS_STRING
319 %token <scm> LYRIC_MARKUP_IDENTIFIER
320 %token <scm> MARKUP_FUNCTION
321 %token <scm> MARKUP_LIST_FUNCTION
322 %token <scm> MARKUP_IDENTIFIER
323 %token <scm> MARKUPLINES_IDENTIFIER
324 %token <scm> MUSIC_FUNCTION
325 %token <scm> MUSIC_IDENTIFIER
326 %token <scm> NOTENAME_PITCH
327 %token <scm> NUMBER_IDENTIFIER
328 %token <scm> OUTPUT_DEF_IDENTIFIER
330 %token <scm> RESTNAME
331 %token <scm> SCM_FUNCTION
332 %token <scm> SCM_IDENTIFIER
333 %token <scm> SCM_TOKEN
334 %token <scm> SCORE_IDENTIFIER
336 %token <scm> STRING_IDENTIFIER
337 %token <scm> TONICNAME_PITCH
340 %type <book> book_block
341 %type <book> book_body
342 %type <book> bookpart_block
343 %type <book> bookpart_body
345 %type <i> bare_unsigned
346 %type <scm> figured_bass_alteration
348 %type <i> exclamations
349 %type <i> optional_rest
354 %type <i> tremolo_type
357 %type <scm> composite_music
358 %type <scm> grouped_music_list
359 %type <scm> braced_music_list
360 %type <scm> closed_music
362 %type <scm> music_bare
363 %type <scm> complex_music
364 %type <scm> complex_music_prefix
365 %type <scm> mode_changed_music
366 %type <scm> repeated_music
367 %type <scm> sequential_music
368 %type <scm> simple_music
369 %type <scm> simultaneous_music
370 %type <scm> chord_body
371 %type <scm> chord_body_element
372 %type <scm> command_element
373 %type <scm> command_event
374 %type <scm> context_modification
375 %type <scm> context_change
376 %type <scm> direction_less_event
377 %type <scm> direction_reqd_event
378 %type <scm> embedded_lilypond
379 %type <scm> event_chord
380 %type <scm> fingering
381 %type <scm> gen_text_def
382 %type <scm> music_property_def
383 %type <scm> note_chord_element
384 %type <scm> post_event
385 %type <scm> post_event_nofinger
386 %type <scm> re_rhythmed_music
387 %type <scm> simple_element
388 %type <scm> simple_music_property_def
389 %type <scm> start_symbol
390 %type <scm> string_number_event
391 %type <scm> tempo_event
393 %type <outputdef> output_def_body
394 %type <outputdef> output_def_head
395 %type <outputdef> output_def_head_with_mode_switch
396 %type <outputdef> output_def
397 %type <outputdef> paper_block
399 %type <scm> music_function_call
400 %type <scm> music_list
401 %type <scm> assignment_id
402 %type <scm> bare_number
403 %type <scm> unsigned_number
404 %type <scm> bass_figure
405 %type <scm> figured_bass_modification
406 %type <scm> br_bass_figure
407 %type <scm> bass_number
408 %type <scm> chord_body_elements
409 %type <scm> chord_item
410 %type <scm> chord_items
411 %type <scm> chord_separator
412 %type <scm> context_def_mod
413 %type <scm> context_def_spec_block
414 %type <scm> context_def_spec_body
415 %type <scm> context_mod
416 %type <scm> context_mod_list
417 %type <scm> context_prop_spec
418 %type <scm> direction_less_char
419 %type <scm> duration_length
420 %type <scm> embedded_scm
421 %type <scm> embedded_scm_bare
422 %type <scm> embedded_scm_closed
423 %type <scm> embedded_scm_chord_body
424 %type <scm> embedded_scm_event
425 %type <scm> event_function_event
426 %type <scm> figure_list
427 %type <scm> figure_spec
429 %type <scm> full_markup
430 %type <scm> full_markup_list
431 %type <scm> function_arglist
432 %type <scm> function_arglist_optional
433 %type <scm> function_arglist_keep
434 %type <scm> function_arglist_bare
435 %type <scm> function_arglist_closed
436 %type <scm> function_arglist_closed_optional
437 %type <scm> function_arglist_closed_keep
438 %type <scm> identifier_init
440 %type <scm> lilypond_header
441 %type <scm> lilypond_header_body
442 %type <scm> lyric_element
443 %type <scm> lyric_markup
445 %type <scm> markup_braced_list
446 %type <scm> markup_braced_list_body
447 %type <scm> markup_composed_list
448 %type <scm> markup_command_list
449 %type <scm> markup_command_list_arguments
450 %type <scm> markup_command_basic_arguments
451 %type <scm> markup_head_1_item
452 %type <scm> markup_head_1_list
453 %type <scm> markup_list
454 %type <scm> markup_top
455 %type <scm> mode_changing_head
456 %type <scm> mode_changing_head_with_context
457 %type <scm> multiplied_duration
458 %type <scm> music_function_event
459 %type <scm> music_function_event_arglist
460 %type <scm> music_function_chord_body
461 %type <scm> music_function_chord_body_arglist
462 %type <scm> new_chord
463 %type <scm> new_lyrics
464 %type <scm> number_expression
465 %type <scm> number_factor
466 %type <scm> number_term
467 %type <scm> octave_check
468 %type <scm> optional_context_mod
469 %type <scm> optional_id
470 %type <scm> optional_notemode_duration
472 %type <scm> pitch_also_in_chords
473 %type <scm> post_events
474 %type <scm> property_operation
475 %type <scm> property_path property_path_revved
477 %type <scm> scalar_bare
478 %type <scm> scalar_closed
479 %type <scm> scm_function_call
480 %type <scm> scm_function_call_closed
481 %type <scm> script_abbreviation
482 %type <scm> simple_chord_elements
483 %type <scm> simple_markup
484 %type <scm> simple_string
485 %type <scm> steno_duration
486 %type <scm> steno_pitch
487 %type <scm> steno_tonic_pitch
488 %type <scm> step_number
489 %type <scm> step_numbers
491 %type <scm> tempo_range
493 %type <score> score_block
494 %type <score> score_body
499 /* We don't assign precedence to / and *, because we might need varied
500 prec levels in different prods */
509 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
510 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
511 } embedded_lilypond {
512 PARSER->lexer_->pop_state ();
513 PARSER->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
517 lilypond: /* empty */ { }
518 | lilypond toplevel_expression {
520 | lilypond assignment {
523 PARSER->error_level_ = 1;
526 PARSER->error_level_ = 1;
533 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
537 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
538 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
543 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
544 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
545 bookpart->unprotect ();
550 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
551 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
555 Music *music = unsmob_music ($1);
556 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
557 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
560 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
561 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
564 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
565 scm_call_2 (proc, PARSER->self_scm (), $1);
569 Output_def * od = $1;
571 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
572 id = ly_symbol2scm ("$defaultpaper");
573 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
574 id = ly_symbol2scm ("$defaultmidi");
575 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
576 id = ly_symbol2scm ("$defaultlayout");
578 PARSER->lexer_->set_identifier (id, od->self_scm ());
588 /* The generic version may end in music, or not */
596 SCM_FUNCTION function_arglist {
597 $$ = MAKE_SYNTAX ("music-function", @$,
605 $$ = MAKE_SYNTAX ("void-music", @$);
608 | music music music_list {
609 $$ = MAKE_SYNTAX ("sequential-music", @$,
610 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
613 PARSER->error_level_ = 1;
615 | INVALID embedded_lilypond {
616 PARSER->error_level_ = 1;
621 lilypond_header_body:
623 $$ = get_header (PARSER);
624 PARSER->lexer_->add_scope ($$);
626 | lilypond_header_body assignment {
632 HEADER '{' lilypond_header_body '}' {
633 $$ = PARSER->lexer_->remove_scope ();
642 | LYRICS_STRING { $$ = $1; }
646 assignment_id '=' identifier_init {
647 PARSER->lexer_->set_identifier ($1, $3);
649 | assignment_id property_path '=' identifier_init {
650 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
651 PARSER->lexer_->set_identifier (path, $4);
654 TODO: devise standard for protection in parser.
656 The parser stack lives on the C-stack, which means that
657 all objects can be unprotected as soon as they're here.
667 $$ = $1->self_scm ();
671 $$ = $1->self_scm ();
675 $$ = $1->self_scm ();
679 $$ = $1->self_scm ();
682 | context_def_spec_block {
686 /* Hack: Create event-chord around standalone events.
687 Prevents the identifier from being interpreted as a post-event. */
688 Music *mus = unsmob_music ($1);
689 bool is_event = mus &&
690 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
695 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
697 | post_event_nofinger {
700 | number_expression {
715 | context_modification {
720 context_def_spec_block:
721 CONTEXT '{' context_def_spec_body '}'
727 context_def_spec_body:
729 $$ = Context_def::make_scm ();
730 unsmob_context_def ($$)->origin ()->set_spot (@$);
732 | CONTEXT_DEF_IDENTIFIER {
734 unsmob_context_def ($$)->origin ()->set_spot (@$);
736 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
737 Context_def*td = unsmob_context_def ($$);
739 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
740 SCM tag = scm_caar (p);
742 /* TODO: should make new tag "grob-definition" ? */
743 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
744 tag, scm_cons (scm_cdar (p), SCM_EOL)));
747 | context_def_spec_body context_mod {
748 unsmob_context_def ($$)->add_context_mod ($2);
750 | context_def_spec_body context_modification {
751 Context_def *td = unsmob_context_def ($$);
752 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
753 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
754 td->add_context_mod (scm_car (m));
762 BOOK '{' book_body '}' {
765 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
770 * Use 'handlers' like for toplevel-* stuff?
771 * grok \layout and \midi? */
775 init_papers (PARSER);
776 $$->origin ()->set_spot (@$);
777 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
778 $$->paper_->unprotect ();
779 push_paper (PARSER, $$->paper_);
780 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
781 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
782 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
783 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
786 $$ = unsmob_book ($1);
788 $$->origin ()->set_spot (@$);
789 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
791 | book_body paper_block {
794 set_paper (PARSER, $2);
796 | book_body bookpart_block {
798 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
799 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
800 bookpart->unprotect ();
802 | book_body score_block {
804 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
805 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
808 | book_body composite_music {
809 Music *music = unsmob_music ($2);
810 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
811 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
813 | book_body full_markup {
814 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
815 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
817 | book_body full_markup_list {
818 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
819 scm_call_2 (proc, $$->self_scm (), $2);
821 | book_body lilypond_header {
824 | book_body embedded_scm { }
827 $$->scores_ = SCM_EOL;
828 $$->bookparts_ = SCM_EOL;
833 BOOKPART '{' bookpart_body '}' {
835 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
842 $$->origin ()->set_spot (@$);
843 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
846 $$ = unsmob_book ($1);
848 $$->origin ()->set_spot (@$);
849 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
851 | bookpart_body paper_block {
855 | bookpart_body score_block {
857 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
858 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
861 | bookpart_body composite_music {
862 Music *music = unsmob_music ($2);
863 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
864 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
866 | bookpart_body full_markup {
867 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
868 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
870 | bookpart_body full_markup_list {
871 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
872 scm_call_2 (proc, $$->self_scm (), $2);
874 | bookpart_body lilypond_header {
877 | bookpart_body embedded_scm { }
878 | bookpart_body error {
880 $$->scores_ = SCM_EOL;
885 SCORE '{' score_body '}' {
893 SCM scorify = ly_lily_module_constant ("scorify-music");
894 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
896 // pass ownernship to C++ again.
897 $$ = unsmob_score (score);
899 $$->origin ()->set_spot (@$);
902 $$ = unsmob_score ($1);
904 $$->origin ()->set_spot (@$);
906 | score_body lilypond_header {
909 | score_body output_def {
910 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
912 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
917 $$->add_output_def ($2);
922 $$->error_found_ = true;
934 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
936 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
938 $$ = get_paper (PARSER);
945 output_def_body '}' {
948 PARSER->lexer_->remove_scope ();
949 PARSER->lexer_->pop_state ();
955 $$ = get_paper (PARSER);
956 $$->input_origin_ = @$;
957 PARSER->lexer_->add_scope ($$->scope_);
960 Output_def *p = get_midi (PARSER);
962 PARSER->lexer_->add_scope (p->scope_);
965 Output_def *p = get_layout (PARSER);
967 PARSER->lexer_->add_scope (p->scope_);
972 output_def_head_with_mode_switch:
974 PARSER->lexer_->push_initial_state ();
980 output_def_head_with_mode_switch '{' {
982 $$->input_origin_.set_spot (@$);
984 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
987 Output_def *o = unsmob_output_def ($3);
988 o->input_origin_.set_spot (@$);
991 PARSER->lexer_->remove_scope ();
992 PARSER->lexer_->add_scope (o->scope_);
994 | output_def_body assignment {
997 | output_def_body context_def_spec_block {
998 assign_context_def ($$, $2);
1000 | output_def_body error {
1006 TEMPO steno_duration '=' tempo_range {
1007 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1009 | TEMPO scalar_closed steno_duration '=' tempo_range {
1010 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1013 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1018 The representation of a list is reversed to have efficient append. */
1024 | music_list music {
1025 $$ = scm_cons ($2, $1);
1027 | music_list embedded_scm {
1030 | music_list error {
1031 Music *m = MY_MAKE_MUSIC("Music", @$);
1033 m->set_property ("error-found", SCM_BOOL_T);
1034 $$ = scm_cons (m->self_scm (), $1);
1035 m->unprotect (); /* UGH */
1042 $$ = scm_reverse_x ($2, SCM_EOL);
1048 | composite_music %prec FUNCTION_ARGUMENTS
1053 REPEAT simple_string unsigned_number music
1055 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1057 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1059 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1064 SEQUENTIAL braced_music_list {
1065 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1067 | braced_music_list {
1068 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1073 SIMULTANEOUS braced_music_list {
1074 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1076 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1077 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1083 | music_property_def
1087 context_modification:
1088 WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1090 PARSER->lexer_->pop_state ();
1093 | WITH CONTEXT_MOD_IDENTIFIER
1097 | CONTEXT_MOD_IDENTIFIER
1103 optional_context_mod:
1107 | context_modification
1115 $$ = Context_mod ().smobbed_copy ();
1117 | context_mod_list context_mod {
1118 unsmob_context_mod ($1)->add_context_mod ($2);
1120 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1121 Context_mod *md = unsmob_context_mod ($2);
1123 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1132 /* Music that can be parsed without lookahead */
1135 | complex_music_prefix closed_music
1137 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1144 | grouped_music_list
1148 simultaneous_music { $$ = $1; }
1149 | sequential_music { $$ = $1; }
1152 /* An argument list. If a function \foo expects scm scm music, then the lexer expands \foo into the token sequence:
1153 MUSIC_FUNCTION EXPECT_MUSIC EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1154 and this rule returns the reversed list of arguments. */
1158 function_arglist_bare
1159 | EXPECT_MUSIC function_arglist_optional music
1161 $$ = scm_cons ($3, $2);
1163 | EXPECT_SCM function_arglist_optional embedded_scm
1165 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED, $3, $2, $1);
1169 function_arglist_optional:
1170 function_arglist_keep %prec FUNCTION_ARGUMENTS
1171 | EXPECT_OPTIONAL EXPECT_MUSIC function_arglist_optional
1173 $$ = scm_cons (loc_on_music (@3, $1), $3);
1175 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1177 $$ = scm_cons ($1, $3);
1179 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1181 $$ = scm_cons ($1, $3);
1183 | EXPECT_OPTIONAL EXPECT_MARKUP function_arglist_optional
1185 $$ = scm_cons ($1, $3);
1187 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_optional
1189 $$ = scm_cons (loc_on_music (@3, $1), $3);
1193 function_arglist_keep:
1194 EXPECT_OPTIONAL EXPECT_MARKUP function_arglist_keep full_markup {
1195 $$ = scm_cons ($4, $3);
1197 | EXPECT_OPTIONAL EXPECT_MARKUP function_arglist_keep simple_string {
1198 $$ = scm_cons ($4, $3);
1200 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords {
1201 $$ = scm_cons ($4, $3);
1203 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length {
1204 $$ = scm_cons ($4, $3);
1206 | EXPECT_OPTIONAL EXPECT_MUSIC function_arglist_keep closed_music
1208 $$ = scm_cons ($4, $3);
1211 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep simple_string
1213 if (scm_is_true (scm_call_1 ($2, $4)))
1215 $$ = scm_cons ($4, $3);
1217 $$ = scm_cons (loc_on_music (@3, $1), $3);
1218 MYBACKUP (SKIPPED_SCM, $4, @4);
1221 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_closed
1223 if (scm_is_true (scm_call_1 ($2, $4)))
1225 $$ = scm_cons ($4, $3);
1227 $$ = scm_cons (loc_on_music (@3, $1), $3);
1228 MYBACKUP (SKIPPED_SCM, $4, @4);
1234 function_arglist_closed:
1235 function_arglist_bare
1236 | EXPECT_MUSIC function_arglist_optional closed_music
1238 $$ = scm_cons ($3, $2);
1240 | EXPECT_SCM function_arglist_optional embedded_scm_closed
1242 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED, $3, $2, $1);
1246 function_arglist_closed_optional:
1247 function_arglist_closed_keep %prec FUNCTION_ARGUMENTS
1248 | EXPECT_OPTIONAL EXPECT_MUSIC function_arglist_closed_optional
1250 $$ = scm_cons (loc_on_music (@3, $1), $3);
1252 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1254 $$ = scm_cons ($1, $3);
1256 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1258 $$ = scm_cons ($1, $3);
1260 | EXPECT_OPTIONAL EXPECT_MARKUP function_arglist_closed_optional
1262 $$ = scm_cons ($1, $3);
1264 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_optional
1266 $$ = scm_cons (loc_on_music (@3, $1), $3);
1270 function_arglist_closed_keep:
1271 EXPECT_OPTIONAL EXPECT_MARKUP function_arglist_keep full_markup {
1272 $$ = scm_cons ($4, $3);
1274 | EXPECT_OPTIONAL EXPECT_MARKUP function_arglist_keep simple_string {
1275 $$ = scm_cons ($4, $3);
1277 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords {
1278 $$ = scm_cons ($4, $3);
1280 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length {
1281 $$ = scm_cons ($4, $3);
1283 | EXPECT_OPTIONAL EXPECT_MUSIC function_arglist_keep closed_music
1285 $$ = scm_cons ($4, $3);
1287 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep simple_string
1289 if (scm_is_true (scm_call_1 ($2, $4)))
1291 $$ = scm_cons ($4, $3);
1293 $$ = scm_cons (loc_on_music (@3, $1), $3);
1294 MYBACKUP (SKIPPED_SCM, $4, @4);
1297 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_closed
1299 if (scm_is_true (scm_call_1 ($2, $4)))
1301 $$ = scm_cons ($4, $3);
1303 $$ = scm_cons (loc_on_music (@3, $1), $3);
1304 MYBACKUP (SKIPPED_SCM, $4, @4);
1307 | function_arglist_closed
1310 embedded_scm_closed:
1312 | scm_function_call_closed
1315 scm_function_call_closed:
1316 SCM_FUNCTION function_arglist_closed {
1317 $$ = MAKE_SYNTAX ("music-function", @$,
1322 function_arglist_bare:
1323 EXPECT_NO_MORE_ARGS {
1326 | EXPECT_MARKUP function_arglist_optional full_markup {
1327 $$ = scm_cons ($3, $2);
1329 | EXPECT_MARKUP function_arglist_optional simple_string {
1330 $$ = scm_cons ($3, $2);
1332 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1333 $$ = scm_cons ($3, $2);
1335 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1336 $$ = scm_cons ($3, $2);
1338 | EXPECT_SCM function_arglist_optional simple_string {
1339 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED, $3, $2, $1);
1341 | EXPECT_SCM function_arglist_optional SKIPPED_SCM
1343 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED, $3, $2, $1);
1347 music_function_call:
1348 MUSIC_FUNCTION function_arglist {
1349 $$ = MAKE_SYNTAX ("music-function", @$,
1356 /**/ { $$ = SCM_EOL; }
1357 | '=' simple_string {
1364 | repeated_music { $$ = $1; }
1365 | re_rhythmed_music { $$ = $1; }
1366 | complex_music_prefix music
1368 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1372 complex_music_prefix:
1373 CONTEXT simple_string optional_id optional_context_mod {
1374 Context_mod *ctxmod = unsmob_context_mod ($4);
1377 mods = ctxmod->get_mods ();
1378 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1380 | NEWCONTEXT simple_string optional_id optional_context_mod {
1381 Context_mod *ctxmod = unsmob_context_mod ($4);
1384 mods = ctxmod->get_mods ();
1385 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1388 $$ = START_MAKE_SYNTAX ("time-scaled-music", $2);
1393 mode_changing_head grouped_music_list {
1394 if ($1 == ly_symbol2scm ("chords"))
1396 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1402 PARSER->lexer_->pop_state ();
1404 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1405 Context_mod *ctxmod = unsmob_context_mod ($2);
1408 mods = ctxmod->get_mods ();
1409 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1410 if ($1 == ly_symbol2scm ("ChordNames"))
1412 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1414 PARSER->lexer_->pop_state ();
1420 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1421 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1423 $$ = ly_symbol2scm ("notes");
1427 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1428 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1430 $$ = ly_symbol2scm ("drums");
1433 PARSER->lexer_->push_figuredbass_state ();
1435 $$ = ly_symbol2scm ("figures");
1438 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1439 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1440 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1441 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1442 $$ = ly_symbol2scm ("chords");
1446 { PARSER->lexer_->push_lyric_state ();
1447 $$ = ly_symbol2scm ("lyrics");
1451 mode_changing_head_with_context:
1453 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1454 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1456 $$ = ly_symbol2scm ("DrumStaff");
1459 PARSER->lexer_->push_figuredbass_state ();
1461 $$ = ly_symbol2scm ("FiguredBass");
1464 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1465 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1466 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1467 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1468 $$ = ly_symbol2scm ("ChordNames");
1471 { PARSER->lexer_->push_lyric_state ();
1472 $$ = ly_symbol2scm ("Lyrics");
1477 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1480 /* Can also use music at the expensive of two S/Rs similar to
1481 \repeat \alternative */
1482 PARSER->lexer_->pop_state ();
1484 $$ = scm_cons ($3, SCM_EOL);
1486 | new_lyrics ADDLYRICS {
1487 PARSER->lexer_->push_lyric_state ();
1489 PARSER->lexer_->pop_state ();
1490 $$ = scm_cons ($4, $1);
1495 composite_music new_lyrics {
1496 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1497 } %prec FUNCTION_ARGUMENTS
1498 | LYRICSTO simple_string {
1499 PARSER->lexer_->push_lyric_state ();
1501 PARSER->lexer_->pop_state ();
1502 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1507 CHANGE STRING '=' STRING {
1508 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1513 property_path_revved:
1514 embedded_scm_closed {
1515 $$ = scm_cons ($1, SCM_EOL);
1517 | property_path_revved embedded_scm_closed {
1518 $$ = scm_cons ($2, $1);
1523 property_path_revved {
1524 $$ = scm_reverse_x ($1, SCM_EOL);
1530 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1531 scm_string_to_symbol ($1), $3);
1533 | UNSET simple_string {
1534 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1535 scm_string_to_symbol ($2));
1537 | OVERRIDE simple_string property_path '=' scalar {
1538 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1539 scm_string_to_symbol ($2), $5),
1542 | REVERT simple_string embedded_scm {
1543 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1544 scm_string_to_symbol ($2), $3);
1549 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1550 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1552 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1553 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1554 | DENIES { $$ = ly_symbol2scm ("denies"); }
1556 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1557 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1558 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1559 | NAME { $$ = ly_symbol2scm ("context-name"); }
1563 property_operation { $$ = $1; }
1564 | context_def_mod STRING {
1565 $$ = scm_list_2 ($1, $2);
1567 | context_def_mod embedded_scm {
1568 if (ly_symbol2scm ("consists") != $1)
1571 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1575 $$ = scm_list_2 ($1, $2);
1582 if (!is_regular_identifier ($1))
1584 @$.error (_("Grob name should be alphanumeric"));
1587 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1588 scm_string_to_symbol ($1));
1590 | simple_string '.' simple_string {
1591 $$ = scm_list_2 (scm_string_to_symbol ($1),
1592 scm_string_to_symbol ($3));
1596 simple_music_property_def:
1597 OVERRIDE context_prop_spec property_path '=' scalar {
1598 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1599 ly_symbol2scm ("OverrideProperty"),
1604 | REVERT context_prop_spec embedded_scm {
1605 $$ = scm_list_4 (scm_car ($2),
1606 ly_symbol2scm ("RevertProperty"),
1610 | SET context_prop_spec '=' scalar {
1611 $$ = scm_list_4 (scm_car ($2),
1612 ly_symbol2scm ("PropertySet"),
1616 | UNSET context_prop_spec {
1617 $$ = scm_list_3 (scm_car ($2),
1618 ly_symbol2scm ("PropertyUnset"),
1624 simple_music_property_def {
1625 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1627 | ONCE simple_music_property_def {
1628 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1636 | STRING_IDENTIFIER {
1639 | string '+' string {
1640 $$ = scm_string_append (scm_list_2 ($1, $3));
1644 simple_string: STRING {
1650 | STRING_IDENTIFIER {
1665 | embedded_scm_bare {
1680 scm_function_call_closed
1685 /* TODO: Create a special case that avoids the creation of
1686 EventChords around simple_elements that have no post_events?
1688 simple_chord_elements post_events {
1689 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1692 /* why is this giving wrong start location? -ns
1694 i.set_location (@1, @2);
1695 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1697 | CHORD_REPETITION optional_notemode_duration post_events {
1699 i.set_location (@1, @3);
1700 $$ = MAKE_SYNTAX ("repetition-chord", i,
1701 PARSER->lexer_->chord_repetition_.last_chord_,
1702 PARSER->lexer_->chord_repetition_.repetition_function_,
1703 $2, scm_reverse_x ($3, SCM_EOL));
1705 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1707 i.set_location (@1, @3);
1708 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1709 scm_reverse_x ($3, SCM_EOL));
1712 /* note chord elements are memorized into
1713 PARSER->lexer_->chord_repetition_ so that the chord repetition
1714 mechanism copy them when a chord repetition symbol is found
1716 | note_chord_element {
1717 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
1723 chord_body optional_notemode_duration post_events
1725 Music *m = unsmob_music ($1);
1726 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1727 SCM es = m->get_property ("elements");
1728 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1730 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1731 unsmob_music (scm_car (s))->set_property ("duration", dur);
1732 es = ly_append2 (es, postevs);
1734 m-> set_property ("elements", es);
1736 $$ = m->self_scm ();
1741 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1743 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1747 chord_body_elements:
1748 /* empty */ { $$ = SCM_EOL; }
1749 | chord_body_elements chord_body_element {
1750 $$ = scm_cons ($2, $1);
1755 pitch exclamations questions octave_check post_events
1762 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1763 n->set_property ("pitch", $1);
1765 n->set_property ("cautionary", SCM_BOOL_T);
1766 if (ex % 2 || q % 2)
1767 n->set_property ("force-accidental", SCM_BOOL_T);
1769 if (scm_is_pair (post)) {
1770 SCM arts = scm_reverse_x (post, SCM_EOL);
1771 n->set_property ("articulations", arts);
1773 if (scm_is_number (check))
1775 int q = scm_to_int (check);
1776 n->set_property ("absolute-octave", scm_from_int (q-1));
1779 $$ = n->unprotect ();
1781 | DRUM_PITCH post_events {
1782 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1783 n->set_property ("drum-type", $1);
1785 if (scm_is_pair ($2)) {
1786 SCM arts = scm_reverse_x ($2, SCM_EOL);
1787 n->set_property ("articulations", arts);
1789 $$ = n->unprotect ();
1791 | music_function_chord_body
1794 /* We can't accept a music argument, not even a closed one,
1795 * immediately before chord_body_elements, otherwise a function \fun
1796 * with a signature of two music arguments can't be sorted out
1797 * properly in a construct like
1798 * <\fun { c } \fun { c } c>
1799 * The second call could be interpreted either as a chord constituent
1800 * or a music expression.
1803 music_function_chord_body_arglist:
1804 function_arglist_bare
1805 | EXPECT_MUSIC music_function_chord_body_arglist chord_body_element {
1806 $$ = scm_cons ($3, $2);
1808 | EXPECT_SCM function_arglist_optional embedded_scm_chord_body {
1809 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED, $3, $2, $1);
1813 embedded_scm_chord_body:
1815 | SCM_FUNCTION music_function_chord_body_arglist {
1816 $$ = MAKE_SYNTAX ("music-function", @$,
1821 music_function_chord_body:
1822 MUSIC_FUNCTION music_function_chord_body_arglist {
1823 $$ = MAKE_SYNTAX ("music-function", @$,
1828 /* We could accept a closed music argument before the post events
1829 * indicated by a trailing argument list. For symmetry with chord
1830 * bodies and in order to avoid too tricky and complex behavior, we
1831 * refrain from doing so.
1833 music_function_event_arglist:
1834 function_arglist_bare
1835 | EXPECT_MUSIC music_function_event_arglist post_event {
1836 $$ = scm_cons ($3, $2);
1838 | EXPECT_SCM function_arglist_optional embedded_scm_event {
1839 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED, $3, $2, $1);
1845 | SCM_FUNCTION music_function_event_arglist {
1846 $$ = MAKE_SYNTAX ("music-function", @$,
1851 music_function_event:
1852 MUSIC_FUNCTION music_function_event_arglist {
1853 $$ = MAKE_SYNTAX ("music-function", @$,
1858 event_function_event:
1859 EVENT_FUNCTION music_function_event_arglist {
1860 $$ = MAKE_SYNTAX ("music-function", @$,
1870 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1871 m->set_property ("span-direction", scm_from_int (START));
1872 $$ = m->unprotect();
1875 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1876 m->set_property ("span-direction", scm_from_int (STOP));
1877 $$ = m->unprotect ();
1880 $$ = MAKE_SYNTAX ("voice-separator", @$);
1883 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1885 Music *m = unsmob_music (pipe);
1890 $$ = m->unprotect ();
1893 $$ = MAKE_SYNTAX ("bar-check", @$);
1897 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1899 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1902 $$ = MAKE_SYNTAX ("make-mark-set", @$, $2);
1908 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
1911 Music *m = MY_MAKE_MUSIC ("MarkEvent", @$);
1912 $$ = m->unprotect ();
1918 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1919 $$ = key->unprotect ();
1921 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1923 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1924 if (scm_ilength ($3) > 0)
1926 key->set_property ("pitch-alist", $3);
1927 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1928 key->transpose (* unsmob_pitch ($2));
1930 PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1933 $$ = key->unprotect ();
1942 | post_events post_event {
1943 unsmob_music ($2)->set_spot (@2);
1944 $$ = scm_cons ($2, $$);
1948 post_event_nofinger:
1949 direction_less_event {
1952 | script_dir music_function_event {
1956 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
1960 if (!PARSER->lexer_->is_lyric_state ())
1961 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1962 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
1965 if (!PARSER->lexer_->is_lyric_state ())
1966 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1967 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
1969 | script_dir direction_reqd_event {
1972 Music *m = unsmob_music ($2);
1973 m->set_property ("direction", scm_from_int ($1));
1977 | script_dir direction_less_event {
1980 Music *m = unsmob_music ($2);
1981 m->set_property ("direction", scm_from_int ($1));
1985 | string_number_event
1990 | script_dir fingering {
1993 Music *m = unsmob_music ($2);
1994 m->set_property ("direction", scm_from_int ($1));
2000 string_number_event:
2002 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2003 s->set_property ("string-number", scm_from_int ($1));
2004 $$ = s->unprotect ();
2008 direction_less_char:
2010 $$ = ly_symbol2scm ("bracketOpenSymbol");
2013 $$ = ly_symbol2scm ("bracketCloseSymbol");
2016 $$ = ly_symbol2scm ("tildeSymbol");
2019 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2022 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2025 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2028 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2031 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2034 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2037 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2041 direction_less_event:
2042 direction_less_char {
2043 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
2045 if (unsmob_music (predefd))
2047 m = unsmob_music (predefd)->clone ();
2052 m = MY_MAKE_MUSIC ("Music", @$);
2054 $$ = m->unprotect ();
2056 | EVENT_IDENTIFIER {
2060 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2061 a->set_property ("tremolo-type", scm_from_int ($1));
2062 $$ = a->unprotect ();
2064 | event_function_event
2067 direction_reqd_event:
2071 | script_abbreviation {
2072 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2073 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2074 if (scm_is_string (s))
2075 a->set_property ("articulation-type", s);
2076 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
2077 $$ = a->unprotect ();
2082 /**/ { $$ = SCM_EOL; }
2083 | '=' { $$ = scm_from_int (0); }
2084 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2085 | '=' sup_quotes { $$ = scm_from_int ($2); }
2110 | NOTENAME_PITCH sup_quotes {
2111 Pitch p = *unsmob_pitch ($1);
2112 p = p.transposed (Pitch ($2,0,0));
2113 $$ = p.smobbed_copy ();
2115 | NOTENAME_PITCH sub_quotes {
2116 Pitch p =* unsmob_pitch ($1);
2117 p = p.transposed (Pitch (-$2,0,0));
2118 $$ = p.smobbed_copy ();
2130 | TONICNAME_PITCH sup_quotes {
2131 Pitch p = *unsmob_pitch ($1);
2132 p = p.transposed (Pitch ($2,0,0));
2133 $$ = p.smobbed_copy ();
2135 | TONICNAME_PITCH sub_quotes {
2136 Pitch p = *unsmob_pitch ($1);
2138 p = p.transposed (Pitch (-$2,0,0));
2139 $$ = p.smobbed_copy ();
2150 pitch_also_in_chords:
2157 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2158 t->set_property ("text", $1);
2159 $$ = t->unprotect ();
2162 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2163 t->set_property ("text",
2164 make_simple_markup ($1));
2165 $$ = t->unprotect ();
2171 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2172 t->set_property ("digit", scm_from_int ($1));
2173 $$ = t->unprotect ();
2177 script_abbreviation:
2179 $$ = scm_from_locale_string ("Hat");
2182 $$ = scm_from_locale_string ("Plus");
2185 $$ = scm_from_locale_string ("Dash");
2188 $$ = scm_from_locale_string ("Bar");
2191 $$ = scm_from_locale_string ("Larger");
2194 $$ = scm_from_locale_string ("Dot");
2197 $$ = scm_from_locale_string ("Underscore");
2204 | '-' { $$ = CENTER; }
2208 multiplied_duration {
2213 optional_notemode_duration:
2215 Duration dd = PARSER->default_duration_;
2216 $$ = dd.smobbed_copy ();
2218 | multiplied_duration {
2220 PARSER->default_duration_ = *unsmob_duration ($$);
2225 bare_unsigned dots {
2227 if (!is_duration ($1))
2228 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
2232 $$ = Duration (len, $2).smobbed_copy ();
2234 | DURATION_IDENTIFIER dots {
2235 Duration *d = unsmob_duration ($1);
2236 Duration k (d->duration_log (), d->dot_count () + $2);
2237 k = k.compressed (d->factor ());
2243 multiplied_duration:
2247 | multiplied_duration '*' bare_unsigned {
2248 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2250 | multiplied_duration '*' FRACTION {
2251 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2253 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2258 FRACTION { $$ = $1; }
2259 | UNSIGNED '/' UNSIGNED {
2260 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2277 | ':' bare_unsigned {
2278 if (!is_duration ($2))
2279 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2286 $$ = scm_from_int ($1);
2288 | STRING { $$ = $1; }
2289 | full_markup { $$ = $1; }
2292 figured_bass_alteration:
2293 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2294 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2295 | '!' { $$ = scm_from_int (0); }
2300 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2301 $$ = bfr->unprotect ();
2304 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2305 $$ = bfr->self_scm ();
2307 if (scm_is_number ($1))
2308 bfr->set_property ("figure", $1);
2309 else if (Text_interface::is_markup ($1))
2310 bfr->set_property ("text", $1);
2316 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2318 | bass_figure figured_bass_alteration {
2319 Music *m = unsmob_music ($1);
2320 if (scm_to_double ($2)) {
2321 SCM salter = m->get_property ("alteration");
2322 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2323 m->set_property ("alteration",
2324 scm_sum (alter, $2));
2326 m->set_property ("alteration", scm_from_int (0));
2329 | bass_figure figured_bass_modification {
2330 Music *m = unsmob_music ($1);
2331 if ($2 == ly_symbol2scm ("plus"))
2333 m->set_property ("augmented", SCM_BOOL_T);
2335 else if ($2 == ly_symbol2scm ("slash"))
2337 m->set_property ("diminished", SCM_BOOL_T);
2339 else if ($2 == ly_symbol2scm ("exclamation"))
2341 m->set_property ("no-continuation", SCM_BOOL_T);
2343 else if ($2 == ly_symbol2scm ("backslash"))
2345 m->set_property ("augmented-slash", SCM_BOOL_T);
2351 figured_bass_modification:
2353 $$ = ly_symbol2scm ("plus");
2356 $$ = ly_symbol2scm ("exclamation");
2359 $$ = ly_symbol2scm ("slash");
2362 $$ = ly_symbol2scm ("backslash");
2372 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2380 | figure_list br_bass_figure {
2381 $$ = scm_cons ($2, $1);
2386 FIGURE_OPEN figure_list FIGURE_CLOSE {
2387 $$ = scm_reverse_x ($2, SCM_EOL);
2398 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2399 if (!PARSER->lexer_->is_note_state ())
2400 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2404 n = MY_MAKE_MUSIC ("RestEvent", @$);
2406 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2408 n->set_property ("pitch", $1);
2409 n->set_property ("duration", $5);
2411 if (scm_is_number ($4))
2413 int q = scm_to_int ($4);
2414 n->set_property ("absolute-octave", scm_from_int (q-1));
2418 n->set_property ("cautionary", SCM_BOOL_T);
2419 if ($2 % 2 || $3 % 2)
2420 n->set_property ("force-accidental", SCM_BOOL_T);
2422 $$ = n->unprotect ();
2424 | DRUM_PITCH optional_notemode_duration {
2425 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2426 n->set_property ("duration", $2);
2427 n->set_property ("drum-type", $1);
2429 $$ = n->unprotect ();
2431 | RESTNAME optional_notemode_duration {
2433 if (ly_scm2string ($1) == "s") {
2435 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2438 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2441 ev->set_property ("duration", $2);
2442 $$ = ev->unprotect ();
2444 | lyric_element optional_notemode_duration {
2445 if (!PARSER->lexer_->is_lyric_state ())
2446 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2448 Music *levent = MY_MAKE_MUSIC ("LyricEvent", @$);
2449 levent->set_property ("text", $1);
2450 levent->set_property ("duration",$2);
2451 $$= levent->unprotect ();
2455 simple_chord_elements:
2457 $$ = scm_list_1 ($1);
2460 if (!PARSER->lexer_->is_chord_state ())
2461 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2464 | figure_spec optional_notemode_duration {
2465 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2467 unsmob_music (scm_car (s))->set_property ("duration", $2);
2483 steno_tonic_pitch optional_notemode_duration {
2484 $$ = make_chord_elements ($1, $2, SCM_EOL);
2486 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2487 SCM its = scm_reverse_x ($4, SCM_EOL);
2488 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2496 | chord_items chord_item {
2497 $$ = scm_cons ($2, $$);
2503 $$ = ly_symbol2scm ("chord-colon");
2506 $$ = ly_symbol2scm ("chord-caret");
2508 | CHORD_SLASH steno_tonic_pitch {
2509 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2511 | CHORD_BASS steno_tonic_pitch {
2512 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2521 $$ = scm_reverse_x ($1, SCM_EOL);
2529 step_number { $$ = scm_cons ($1, SCM_EOL); }
2530 | step_numbers '.' step_number {
2531 $$ = scm_cons ($3, $$);
2537 $$ = make_chord_step ($1, 0);
2539 | bare_unsigned '+' {
2540 $$ = make_chord_step ($1, SHARP_ALTERATION);
2542 | bare_unsigned CHORD_MINUS {
2543 $$ = make_chord_step ($1, FLAT_ALTERATION);
2549 $$ = scm_from_int ($1);
2551 | bare_unsigned '~' bare_unsigned {
2552 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2559 TODO: should deprecate in favor of Scheme?
2563 number_expression '+' number_term {
2564 $$ = scm_sum ($1, $3);
2566 | number_expression '-' number_term {
2567 $$ = scm_difference ($1, $3);
2576 | number_factor '*' number_factor {
2577 $$ = scm_product ($1, $3);
2579 | number_factor '/' number_factor {
2580 $$ = scm_divide ($1, $3);
2585 '-' number_factor { /* %prec UNARY_MINUS */
2586 $$ = scm_difference ($2, SCM_UNDEFINED);
2594 $$ = scm_from_int ($1);
2599 | NUMBER_IDENTIFIER {
2602 | REAL NUMBER_IDENTIFIER {
2603 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2605 | UNSIGNED NUMBER_IDENTIFIER {
2606 $$ = scm_from_double ($1 *scm_to_double ($2));
2618 bare_unsigned { $$ = scm_from_int ($1); }
2619 | NUMBER_IDENTIFIER {
2626 | exclamations '!' { $$ ++; }
2631 | questions '?' { $$ ++; }
2635 This should be done more dynamically if possible.
2639 LYRIC_MARKUP_IDENTIFIER {
2643 { PARSER->lexer_->push_markup_state (); }
2646 PARSER->lexer_->pop_state ();
2651 MARKUPLINES_IDENTIFIER {
2655 { PARSER->lexer_->push_markup_state (); }
2658 PARSER->lexer_->pop_state ();
2667 { PARSER->lexer_->push_markup_state (); }
2670 PARSER->lexer_->pop_state ();
2676 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2678 | markup_head_1_list simple_markup {
2679 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2687 MARKUPLINES_IDENTIFIER {
2690 | markup_composed_list {
2693 | markup_braced_list {
2696 | markup_command_list {
2697 $$ = scm_list_1 ($1);
2701 markup_composed_list:
2702 markup_head_1_list markup_braced_list {
2703 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2709 '{' markup_braced_list_body '}' {
2710 $$ = scm_reverse_x ($2, SCM_EOL);
2714 markup_braced_list_body:
2715 /* empty */ { $$ = SCM_EOL; }
2716 | markup_braced_list_body markup {
2717 $$ = scm_cons ($2, $1);
2719 | markup_braced_list_body markup_list {
2720 $$ = scm_reverse_x ($2, $1);
2724 markup_command_list:
2725 MARKUP_LIST_FUNCTION markup_command_list_arguments {
2726 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
2730 markup_command_basic_arguments:
2731 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
2732 $$ = scm_cons ($3, $2);
2734 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
2735 $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED, $3, $2, $1);
2737 | EXPECT_NO_MORE_ARGS {
2742 markup_command_list_arguments:
2743 markup_command_basic_arguments { $$ = $1; }
2744 | EXPECT_MARKUP markup_command_list_arguments markup {
2745 $$ = scm_cons ($3, $2);
2750 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
2751 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
2756 markup_head_1_item {
2757 $$ = scm_list_1 ($1);
2759 | markup_head_1_list markup_head_1_item {
2760 $$ = scm_cons ($2, $1);
2766 $$ = make_simple_markup ($1);
2768 | MARKUP_IDENTIFIER {
2771 | LYRIC_MARKUP_IDENTIFIER {
2774 | STRING_IDENTIFIER {
2778 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2779 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2780 } '{' score_body '}' {
2782 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2784 PARSER->lexer_->pop_state ();
2786 | MARKUP_FUNCTION markup_command_basic_arguments {
2787 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
2792 markup_head_1_list simple_markup {
2793 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2794 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2804 Lily_parser::set_yydebug (bool x)
2810 Lily_parser::do_yyparse ()
2812 yyparse ((void*)this);
2821 It is a little strange to have this function in this file, but
2822 otherwise, we have to import music classes into the lexer.
2826 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2828 if (scm_is_string (sid)) {
2830 return STRING_IDENTIFIER;
2831 } else if (unsmob_book (sid)) {
2832 Book *book = unsmob_book (sid)->clone ();
2833 *destination = book->self_scm ();
2836 return BOOK_IDENTIFIER;
2837 } else if (scm_is_number (sid)) {
2839 return NUMBER_IDENTIFIER;
2840 } else if (unsmob_context_def (sid)) {
2841 Context_def *def= unsmob_context_def (sid)->clone ();
2843 *destination = def->self_scm ();
2846 return CONTEXT_DEF_IDENTIFIER;
2847 } else if (unsmob_context_mod (sid)) {
2848 *destination = unsmob_context_mod (sid)->smobbed_copy ();
2850 return CONTEXT_MOD_IDENTIFIER;
2851 } else if (unsmob_score (sid)) {
2852 Score *score = new Score (*unsmob_score (sid));
2853 *destination = score->self_scm ();
2855 score->unprotect ();
2856 return SCORE_IDENTIFIER;
2857 } else if (Music *mus = unsmob_music (sid)) {
2858 mus = mus->clone ();
2859 *destination = mus->self_scm ();
2860 unsmob_music (*destination)->
2861 set_property ("origin", make_input (last_input_));
2863 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2867 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2868 } else if (unsmob_pitch (sid)) {
2869 *destination = unsmob_pitch (sid)->smobbed_copy ();
2870 return PITCH_IDENTIFIER;
2871 } else if (unsmob_duration (sid)) {
2872 *destination = unsmob_duration (sid)->smobbed_copy ();
2873 return DURATION_IDENTIFIER;
2874 } else if (unsmob_output_def (sid)) {
2875 Output_def *p = unsmob_output_def (sid);
2878 *destination = p->self_scm ();
2880 return OUTPUT_DEF_IDENTIFIER;
2881 } else if (Text_interface::is_markup (sid)) {
2883 if (is_lyric_state ())
2884 return LYRIC_MARKUP_IDENTIFIER;
2885 return MARKUP_IDENTIFIER;
2886 } else if (Text_interface::is_markup_list (sid)) {
2888 return MARKUPLINES_IDENTIFIER;
2895 get_next_unique_context_id ()
2897 return scm_from_locale_string ("$uniqueContextId");
2902 get_next_unique_lyrics_context_id ()
2904 static int new_context_count;
2906 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2907 return scm_from_locale_string (s);
2911 SCM check_scheme_arg (Lily_parser *parser, Input loc, SCM fallback,
2912 SCM arg, SCM args, SCM pred)
2914 SCM type_check_arg = ly_lily_module_constant ("type-check-arg");
2915 if (scm_is_false (scm_call_4 (type_check_arg, make_input (loc),
2918 if (SCM_UNBNDP (fallback))
2919 fallback = SCM_BOOL_F;
2921 fallback = loc_on_music (loc, fallback);
2923 parser->error_level_ = 1;
2925 return scm_cons (fallback, args);
2927 return scm_cons (arg, args);
2930 SCM loc_on_music (Input loc, SCM arg)
2932 if (Music *m = unsmob_music (arg))
2936 return m->unprotect ();
2942 is_regular_identifier (SCM id)
2944 string str = ly_scm2string (id);
2945 char const *s = str.c_str ();
2954 v = v && isalnum (*s);
2961 make_music_with_input (SCM name, Input where)
2963 Music *m = make_music_by_name (name);
2964 m->set_spot (where);
2969 get_first_context_id (SCM type, Music *m)
2971 SCM id = m->get_property ("context-id");
2972 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2973 && scm_is_string (m->get_property ("context-id"))
2974 && scm_c_string_length (id) > 0)
2982 make_simple_markup (SCM a)
2990 return t && t == 1 << intlog2 (t);
2994 set_music_properties (Music *p, SCM a)
2996 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2997 p->set_property (scm_caar (k), scm_cdar (k));
3002 make_chord_step (int step, Rational alter)
3005 alter += FLAT_ALTERATION;
3009 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3010 return m.smobbed_copy ();
3015 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
3017 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3018 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
3022 /* Todo: actually also use apply iso. call too ... */
3024 ly_input_procedure_p (SCM x)
3026 return ly_is_procedure (x)
3027 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
3031 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
3033 Lily_parser *pars = (Lily_parser*) v;
3034 Lily_lexer *lex = pars->lexer_;
3036 lex->lexval_ = (void*) s;
3038 lex->prepare_for_next_token ();
3039 return lex->yylex ();