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
62 /* ADDLYRICS needs to have lower precedence than argument scanning,
63 * or we won't be able to tell music apart from closed_music without
64 * lookahead in the context of function calls.
69 /* \default is only applied after exhausting function arguments */
71 %nonassoc FUNCTION_ARGLIST
73 /* expressions with units are permitted into argument lists */
75 %right PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
76 UNSIGNED REAL DURATION_IDENTIFIER ':'
78 /* The above are the symbols that can start optional function arguments
79 that are recognized in the grammar rather than by predicate
82 %nonassoc NUMBER_IDENTIFIER '/'
84 /* Number-unit expressions, where permitted, are concatenated into
85 * function arguments, just like fractions and tremoli. Tremoli must
86 * not have higher precedence than UNSIGNED, or Lilypond will not
87 * join ':' with a following optional number.
100 %{ // -*-Fundamental-*-
105 * The rules for who is protecting what are very shady. Uniformise
108 * There are too many lexical modes?
119 #include "context-def.hh"
120 #include "context-mod.hh"
121 #include "dimensions.hh"
122 #include "file-path.hh"
124 #include "international.hh"
125 #include "lily-guile.hh"
126 #include "lily-lexer.hh"
127 #include "lily-parser.hh"
131 #include "output-def.hh"
132 #include "paper-book.hh"
133 #include "scm-hash.hh"
135 #include "text-interface.hh"
138 #define MYBACKUP(Token, Value, Location) \
140 if (yychar == YYEMPTY) \
143 PARSER->lexer_->push_extra_token (Token, Value); \
144 PARSER->lexer_->push_extra_token (BACKUP); \
146 PARSER->parser_error \
147 (Location, _("Too much lookahead")); \
152 #define MYREPARSE(Location, Pred, Token, Value) \
154 if (yychar == YYEMPTY) \
156 PARSER->lexer_->push_extra_token (Token, Value); \
157 PARSER->lexer_->push_extra_token (REPARSE, \
160 PARSER->parser_error \
161 (Location, _("Too much lookahead")); \
170 Output_def *outputdef;
179 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
182 - Don't use lily module, create a new module instead.
183 - delay application of the function
185 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
186 scm_apply_0 (proc, args)
187 /* Syntactic Sugar. */
188 #define MAKE_SYNTAX(name, location, ...) \
189 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location) , ##__VA_ARGS__, SCM_UNDEFINED));
190 #define START_MAKE_SYNTAX(name, ...) \
191 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
192 #define FINISH_MAKE_SYNTAX(start, location, ...) \
193 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)))))
195 SCM get_next_unique_context_id ();
196 SCM get_next_unique_lyrics_context_id ();
203 #define _(x) gettext (x)
207 static Music *make_music_with_input (SCM name, Input where);
208 SCM check_scheme_arg (Lily_parser *parser, Input loc,
209 SCM arg, SCM args, SCM pred);
210 SCM loc_on_music (Input loc, SCM arg);
211 SCM get_first_context_id (SCM type, Music *m);
212 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
213 SCM make_chord_step (int step, Rational alter);
214 SCM make_simple_markup (SCM a);
215 bool is_duration (int t);
216 bool is_regular_identifier (SCM id);
217 bool ly_input_procedure_p (SCM x);
218 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
219 void set_music_properties (Music *p, SCM a);
223 /* The third option is an alias that will be used to display the
224 syntax error. Bison CVS now correctly handles backslash escapes.
226 FIXME: Bison needs to translate some of these, eg, STRING.
230 /* Keyword tokens with plain escaped name. */
231 %token ACCEPTS "\\accepts"
232 %token ADDLYRICS "\\addlyrics"
233 %token ALIAS "\\alias"
234 %token ALTERNATIVE "\\alternative"
236 %token BOOKPART "\\bookpart"
237 %token CHANGE "\\change"
238 %token CHORDMODE "\\chordmode"
239 %token CHORDS "\\chords"
240 %token CONSISTS "\\consists"
241 %token CONTEXT "\\context"
242 %token DEFAULT "\\default"
243 %token DEFAULTCHILD "\\defaultchild"
244 %token DENIES "\\denies"
245 %token DESCRIPTION "\\description"
246 %token DRUMMODE "\\drummode"
247 %token DRUMS "\\drums"
248 %token FIGUREMODE "\\figuremode"
249 %token FIGURES "\\figures"
250 %token GROBDESCRIPTIONS "\\grobdescriptions"
251 %token HEADER "\\header"
252 %token INVALID "\\version-error"
253 %token LAYOUT "\\layout"
254 %token LYRICMODE "\\lyricmode"
255 %token LYRICS "\\lyrics"
256 %token LYRICSTO "\\lyricsto"
257 %token MARKUP "\\markup"
258 %token MARKUPLIST "\\markuplist"
261 %token NOTEMODE "\\notemode"
262 %token OVERRIDE "\\override"
263 %token PAPER "\\paper"
264 %token REMOVE "\\remove"
265 %token REPEAT "\\repeat"
267 %token REVERT "\\revert"
268 %token SCORE "\\score"
269 %token SEQUENTIAL "\\sequential"
271 %token SIMULTANEOUS "\\simultaneous"
272 %token TEMPO "\\tempo"
274 %token UNSET "\\unset"
277 /* Keyword token exceptions. */
278 %token NEWCONTEXT "\\new"
281 /* Other string tokens. */
283 %token CHORD_BASS "/+"
284 %token CHORD_CARET "^"
285 %token CHORD_COLON ":"
286 %token CHORD_MINUS "-"
287 %token CHORD_SLASH "/"
288 %token ANGLE_OPEN "<"
289 %token ANGLE_CLOSE ">"
290 %token DOUBLE_ANGLE_OPEN "<<"
291 %token DOUBLE_ANGLE_CLOSE ">>"
292 %token E_BACKSLASH "\\"
293 %token E_ANGLE_CLOSE "\\>"
294 %token E_CHAR "\\C[haracter]"
296 %token E_EXCLAMATION "\\!"
297 %token E_BRACKET_OPEN "\\["
299 %token E_BRACKET_CLOSE "\\]"
300 %token E_ANGLE_OPEN "\\<"
306 If we give names, Bison complains.
308 %token FIGURE_CLOSE /* "\\>" */
309 %token FIGURE_OPEN /* "\\<" */
310 %token FIGURE_SPACE "_"
313 %token CHORDMODIFIERS
315 %token MULTI_MEASURE_REST
318 %token <i> E_UNSIGNED
319 %token <scm> UNSIGNED
321 /* Artificial tokens, for more generic function syntax */
322 %token <i> EXPECT_MARKUP "markup?"
323 %token <i> EXPECT_PITCH "ly:pitch?"
324 %token <i> EXPECT_DURATION "ly:duration?"
325 %token <scm> EXPECT_SCM "scheme?"
326 %token <scm> BACKUP "(backed-up?)"
327 %token <scm> REPARSE "(reparsed?)"
328 %token <i> EXPECT_MARKUP_LIST "markup-list?"
329 %token <scm> EXPECT_OPTIONAL "optional?"
330 /* After the last argument. */
331 %token <i> EXPECT_NO_MORE_ARGS;
333 /* An artificial token for parsing embedded Lilypond */
334 %token <i> EMBEDDED_LILY "#{"
336 %token <scm> BOOK_IDENTIFIER
337 %token <scm> CHORDMODIFIER_PITCH
338 %token <scm> CHORD_MODIFIER
339 %token <scm> CHORD_REPETITION
340 %token <scm> CONTEXT_DEF_IDENTIFIER
341 %token <scm> CONTEXT_MOD_IDENTIFIER
342 %token <scm> DRUM_PITCH
343 %token <scm> PITCH_IDENTIFIER
344 %token <scm> DURATION_IDENTIFIER
345 %token <scm> EVENT_IDENTIFIER
346 %token <scm> EVENT_FUNCTION
347 %token <scm> FRACTION
348 %token <scm> LYRICS_STRING
349 %token <scm> LYRIC_ELEMENT
350 %token <scm> LYRIC_ELEMENT_P
351 %token <scm> LYRIC_MARKUP_IDENTIFIER
352 %token <scm> MARKUP_FUNCTION
353 %token <scm> MARKUP_LIST_FUNCTION
354 %token <scm> MARKUP_IDENTIFIER
355 %token <scm> MARKUPLIST_IDENTIFIER
356 %token <scm> MUSIC_FUNCTION
357 %token <scm> MUSIC_IDENTIFIER
358 %token <scm> NOTENAME_PITCH
359 %token <scm> NUMBER_IDENTIFIER
360 %token <scm> OUTPUT_DEF_IDENTIFIER
362 %token <scm> RESTNAME
363 %token <scm> SCM_FUNCTION
364 %token <scm> SCM_IDENTIFIER
365 %token <scm> SCM_TOKEN
366 %token <scm> SCORE_IDENTIFIER
368 %token <scm> STRING_IDENTIFIER
369 %token <scm> TONICNAME_PITCH
372 %type <book> book_block
373 %type <book> book_body
374 %type <book> bookpart_block
375 %type <book> bookpart_body
377 %type <i> bare_unsigned
378 %type <scm> figured_bass_alteration
380 %type <i> exclamations
381 %type <i> optional_rest
386 %type <i> tremolo_type
389 %type <scm> composite_music
390 %type <scm> grouped_music_list
391 %type <scm> braced_music_list
392 %type <scm> closed_music
394 %type <scm> music_bare
395 %type <scm> music_arg
396 %type <scm> complex_music
397 %type <scm> complex_music_prefix
398 %type <scm> mode_changed_music
399 %type <scm> repeated_music
400 %type <scm> sequential_music
401 %type <scm> simple_music
402 %type <scm> simultaneous_music
403 %type <scm> chord_body
404 %type <scm> chord_body_element
405 %type <scm> command_element
406 %type <scm> command_event
407 %type <scm> context_modification
408 %type <scm> context_change
409 %type <scm> direction_less_event
410 %type <scm> direction_reqd_event
411 %type <scm> embedded_lilypond
412 %type <scm> event_chord
413 %type <scm> fingering
414 %type <scm> gen_text_def
415 %type <scm> music_property_def
416 %type <scm> note_chord_element
417 %type <scm> post_event
418 %type <scm> post_event_nofinger
419 %type <scm> re_rhythmed_music
420 %type <scm> simple_element
421 %type <scm> simple_music_property_def
422 %type <scm> start_symbol
423 %type <scm> string_number_event
424 %type <scm> tempo_event
426 %type <outputdef> output_def_body
427 %type <outputdef> output_def_head
428 %type <outputdef> output_def_head_with_mode_switch
429 %type <outputdef> output_def
430 %type <outputdef> paper_block
432 %type <scm> music_function_call
433 %type <scm> music_list
434 %type <scm> assignment_id
435 %type <scm> bare_number
436 %type <scm> bare_number_closed
437 %type <scm> unsigned_number
438 %type <scm> bass_figure
439 %type <scm> figured_bass_modification
440 %type <scm> br_bass_figure
441 %type <scm> bass_number
442 %type <scm> chord_body_elements
443 %type <scm> chord_item
444 %type <scm> chord_items
445 %type <scm> chord_separator
446 %type <scm> context_def_mod
447 %type <scm> context_def_spec_block
448 %type <scm> context_def_spec_body
449 %type <scm> context_mod
450 %type <scm> context_mod_list
451 %type <scm> context_prop_spec
452 %type <scm> direction_less_char
453 %type <scm> duration_length
454 %type <scm> embedded_scm
455 %type <scm> embedded_scm_arg
456 %type <scm> embedded_scm_arg_closed
457 %type <scm> embedded_scm_bare
458 %type <scm> embedded_scm_bare_arg
459 %type <scm> embedded_scm_closed
460 %type <scm> embedded_scm_chord_body
461 %type <scm> event_function_event
462 %type <scm> figure_list
463 %type <scm> figure_spec
465 %type <scm> full_markup
466 %type <scm> full_markup_list
467 %type <scm> function_arglist
468 %type <scm> function_arglist_optional
469 %type <scm> function_arglist_backup
470 %type <scm> function_arglist_nonbackup
471 %type <scm> function_arglist_skip
472 %type <scm> function_arglist_bare
473 %type <scm> function_arglist_closed
474 %type <scm> function_arglist_closed_optional
475 %type <scm> function_arglist_common
476 %type <scm> function_arglist_common_lyric
477 %type <scm> function_arglist_closed_common
478 %type <scm> function_arglist_keep
479 %type <scm> function_arglist_closed_keep
480 %type <scm> identifier_init
482 %type <scm> lilypond_header
483 %type <scm> lilypond_header_body
484 %type <scm> lyric_element
485 %type <scm> lyric_element_arg
486 %type <scm> lyric_element_music
487 %type <scm> lyric_markup
489 %type <scm> markup_braced_list
490 %type <scm> markup_braced_list_body
491 %type <scm> markup_composed_list
492 %type <scm> markup_command_list
493 %type <scm> markup_command_list_arguments
494 %type <scm> markup_command_basic_arguments
495 %type <scm> markup_head_1_item
496 %type <scm> markup_head_1_list
497 %type <scm> markup_list
498 %type <scm> markup_top
499 %type <scm> mode_changing_head
500 %type <scm> mode_changing_head_with_context
501 %type <scm> multiplied_duration
502 %type <scm> music_function_event
503 %type <scm> music_function_chord_body
504 %type <scm> music_function_chord_body_arglist
505 %type <scm> new_chord
506 %type <scm> new_lyrics
507 %type <scm> number_expression
508 %type <scm> number_factor
509 %type <scm> number_term
510 %type <scm> octave_check
511 %type <scm> optional_context_mod
512 %type <scm> optional_id
513 %type <scm> optional_notemode_duration
515 %type <scm> pitch_also_in_chords
516 %type <scm> post_events
517 %type <scm> property_operation
518 %type <scm> property_path property_path_revved
520 %type <scm> scalar_closed
521 %type <scm> scm_function_call
522 %type <scm> scm_function_call_closed
523 %type <scm> script_abbreviation
524 %type <scm> simple_chord_elements
525 %type <scm> simple_markup
526 %type <scm> simple_string
527 %type <scm> steno_duration
528 %type <scm> steno_pitch
529 %type <scm> steno_tonic_pitch
530 %type <scm> step_number
531 %type <scm> step_numbers
533 %type <scm> tempo_range
535 %type <score> score_block
536 %type <score> score_body
541 /* We don't assign precedence to / and *, because we might need varied
542 prec levels in different prods */
551 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
552 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
553 } embedded_lilypond {
554 PARSER->lexer_->pop_state ();
555 PARSER->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
559 lilypond: /* empty */ { }
560 | lilypond toplevel_expression {
562 | lilypond assignment {
565 PARSER->error_level_ = 1;
568 PARSER->error_level_ = 1;
575 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
579 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
580 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
585 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
586 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
587 bookpart->unprotect ();
592 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
593 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
597 Music *music = unsmob_music ($1);
598 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
599 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
602 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
603 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
606 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
607 scm_call_2 (proc, PARSER->self_scm (), $1);
611 Output_def * od = $1;
613 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
614 id = ly_symbol2scm ("$defaultpaper");
615 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
616 id = ly_symbol2scm ("$defaultmidi");
617 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
618 id = ly_symbol2scm ("$defaultlayout");
620 PARSER->lexer_->set_identifier (id, od->self_scm ());
628 $$ = PARSER->lexer_->eval_scm ($1);
633 embedded_scm_bare_arg:
639 | context_modification
642 $$ = $1->self_scm ();
645 | context_def_spec_block
648 $$ = $1->self_scm ();
653 $$ = $1->self_scm ();
658 $$ = $1->self_scm ();
663 /* The generic version may end in music, or not */
671 embedded_scm_bare_arg
677 SCM_FUNCTION function_arglist {
678 $$ = MAKE_SYNTAX ("music-function", @$,
686 $$ = MAKE_SYNTAX ("void-music", @$);
689 | music music music_list {
690 $$ = MAKE_SYNTAX ("sequential-music", @$,
691 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
694 PARSER->error_level_ = 1;
696 | INVALID embedded_lilypond {
697 PARSER->error_level_ = 1;
702 lilypond_header_body:
704 $$ = get_header (PARSER);
705 PARSER->lexer_->add_scope ($$);
707 | lilypond_header_body assignment {
713 HEADER '{' lilypond_header_body '}' {
714 $$ = PARSER->lexer_->remove_scope ();
723 | LYRICS_STRING { $$ = $1; }
727 assignment_id '=' identifier_init {
728 PARSER->lexer_->set_identifier ($1, $3);
730 | assignment_id property_path '=' identifier_init {
731 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
732 PARSER->lexer_->set_identifier (path, $4);
735 TODO: devise standard for protection in parser.
737 The parser stack lives on the C-stack, which means that
738 all objects can be unprotected as soon as they're here.
748 $$ = $1->self_scm ();
752 $$ = $1->self_scm ();
756 $$ = $1->self_scm ();
760 $$ = $1->self_scm ();
763 | context_def_spec_block {
767 /* Hack: Create event-chord around standalone events.
768 Prevents the identifier from being interpreted as a post-event. */
769 Music *mus = unsmob_music ($1);
770 bool is_event = mus &&
771 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
776 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
778 | post_event_nofinger {
781 | number_expression {
796 | context_modification {
801 context_def_spec_block:
802 CONTEXT '{' context_def_spec_body '}'
808 context_def_spec_body:
810 $$ = Context_def::make_scm ();
811 unsmob_context_def ($$)->origin ()->set_spot (@$);
813 | CONTEXT_DEF_IDENTIFIER {
815 unsmob_context_def ($$)->origin ()->set_spot (@$);
817 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
818 Context_def*td = unsmob_context_def ($$);
820 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
821 SCM tag = scm_caar (p);
823 /* TODO: should make new tag "grob-definition" ? */
824 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
825 tag, scm_cons (scm_cdar (p), SCM_EOL)));
828 | context_def_spec_body context_mod {
829 unsmob_context_def ($$)->add_context_mod ($2);
831 | context_def_spec_body context_modification {
832 Context_def *td = unsmob_context_def ($$);
833 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
834 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
835 td->add_context_mod (scm_car (m));
843 BOOK '{' book_body '}' {
846 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
851 * Use 'handlers' like for toplevel-* stuff?
852 * grok \layout and \midi? */
856 init_papers (PARSER);
857 $$->origin ()->set_spot (@$);
858 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
859 $$->paper_->unprotect ();
860 push_paper (PARSER, $$->paper_);
861 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
862 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
863 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
864 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
867 $$ = unsmob_book ($1);
869 $$->origin ()->set_spot (@$);
870 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
872 | book_body paper_block {
875 set_paper (PARSER, $2);
877 | book_body bookpart_block {
879 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
880 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
881 bookpart->unprotect ();
883 | book_body score_block {
885 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
886 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
889 | book_body composite_music {
890 Music *music = unsmob_music ($2);
891 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
892 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
894 | book_body full_markup {
895 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
896 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
898 | book_body full_markup_list {
899 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
900 scm_call_2 (proc, $$->self_scm (), $2);
902 | book_body lilypond_header {
905 | book_body embedded_scm { }
908 $$->scores_ = SCM_EOL;
909 $$->bookparts_ = SCM_EOL;
914 BOOKPART '{' bookpart_body '}' {
916 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
923 $$->origin ()->set_spot (@$);
924 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
927 $$ = unsmob_book ($1);
929 $$->origin ()->set_spot (@$);
930 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
932 | bookpart_body paper_block {
936 | bookpart_body score_block {
938 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
939 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
942 | bookpart_body composite_music {
943 Music *music = unsmob_music ($2);
944 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
945 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
947 | bookpart_body full_markup {
948 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
949 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
951 | bookpart_body full_markup_list {
952 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
953 scm_call_2 (proc, $$->self_scm (), $2);
955 | bookpart_body lilypond_header {
958 | bookpart_body embedded_scm { }
959 | bookpart_body error {
961 $$->scores_ = SCM_EOL;
966 SCORE '{' score_body '}' {
974 SCM scorify = ly_lily_module_constant ("scorify-music");
975 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
977 // pass ownernship to C++ again.
978 $$ = unsmob_score (score);
980 $$->origin ()->set_spot (@$);
983 $$ = unsmob_score ($1);
985 $$->origin ()->set_spot (@$);
987 | score_body lilypond_header {
990 | score_body output_def {
991 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
993 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
998 $$->add_output_def ($2);
1002 | score_body error {
1003 $$->error_found_ = true;
1015 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1017 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
1019 $$ = get_paper (PARSER);
1026 output_def_body '}' {
1029 PARSER->lexer_->remove_scope ();
1030 PARSER->lexer_->pop_state ();
1036 $$ = get_paper (PARSER);
1037 $$->input_origin_ = @$;
1038 PARSER->lexer_->add_scope ($$->scope_);
1041 Output_def *p = get_midi (PARSER);
1043 PARSER->lexer_->add_scope (p->scope_);
1046 Output_def *p = get_layout (PARSER);
1048 PARSER->lexer_->add_scope (p->scope_);
1053 output_def_head_with_mode_switch:
1055 PARSER->lexer_->push_initial_state ();
1061 output_def_head_with_mode_switch '{' {
1063 $$->input_origin_.set_spot (@$);
1065 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1068 Output_def *o = unsmob_output_def ($3);
1069 o->input_origin_.set_spot (@$);
1072 PARSER->lexer_->remove_scope ();
1073 PARSER->lexer_->add_scope (o->scope_);
1075 | output_def_body assignment {
1078 | output_def_body context_def_spec_block {
1079 assign_context_def ($$, $2);
1081 | output_def_body error {
1087 TEMPO steno_duration '=' tempo_range {
1088 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1090 | TEMPO scalar_closed steno_duration '=' tempo_range {
1091 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1094 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1099 The representation of a list is reversed to have efficient append. */
1105 | music_list music {
1106 $$ = scm_cons ($2, $1);
1108 | music_list embedded_scm {
1111 | music_list error {
1112 Music *m = MY_MAKE_MUSIC("Music", @$);
1114 m->set_property ("error-found", SCM_BOOL_T);
1115 $$ = scm_cons (m->self_scm (), $1);
1116 m->unprotect (); /* UGH */
1123 $$ = scm_reverse_x ($2, SCM_EOL);
1128 | lyric_element_music
1129 | composite_music %prec COMPOSITE
1134 | composite_music %prec COMPOSITE
1138 REPEAT simple_string unsigned_number music
1140 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1142 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1144 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1149 SEQUENTIAL braced_music_list {
1150 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1152 | braced_music_list {
1153 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1158 SIMULTANEOUS braced_music_list {
1159 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1161 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1162 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1168 | music_property_def
1172 context_modification:
1173 WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1175 PARSER->lexer_->pop_state ();
1178 | WITH CONTEXT_MOD_IDENTIFIER
1182 | CONTEXT_MOD_IDENTIFIER
1188 optional_context_mod:
1192 | context_modification
1200 $$ = Context_mod ().smobbed_copy ();
1202 | context_mod_list context_mod {
1203 unsmob_context_mod ($1)->add_context_mod ($2);
1205 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1206 Context_mod *md = unsmob_context_mod ($2);
1208 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1217 /* Music that can be parsed without lookahead */
1220 | complex_music_prefix closed_music
1222 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1229 | grouped_music_list
1233 simultaneous_music { $$ = $1; }
1234 | sequential_music { $$ = $1; }
1237 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1238 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1239 and this rule returns the reversed list of arguments. */
1241 function_arglist_skip:
1242 function_arglist_common
1243 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1245 $$ = scm_cons ($1, $3);
1246 } %prec FUNCTION_ARGLIST
1247 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1249 $$ = scm_cons ($1, $3);
1250 } %prec FUNCTION_ARGLIST
1251 | EXPECT_SCM EXPECT_DURATION function_arglist_skip
1253 $$ = scm_cons ($1, $3);
1254 } %prec FUNCTION_ARGLIST
1258 function_arglist_nonbackup:
1259 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1260 $$ = scm_cons ($4, $3);
1262 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1263 $$ = scm_cons ($4, $3);
1265 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1267 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1269 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1271 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1273 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed fraction
1275 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1277 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event
1279 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1284 function_arglist_keep:
1285 function_arglist_common
1286 | function_arglist_backup
1289 function_arglist_closed_keep:
1290 function_arglist_closed_common
1291 | function_arglist_backup
1294 function_arglist_backup:
1295 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1297 if (scm_is_true (scm_call_1 ($2, $4)))
1299 $$ = scm_cons ($4, $3);
1301 $$ = scm_cons (loc_on_music (@3, $1), $3);
1302 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1305 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event
1307 if (scm_is_true (scm_call_1 ($2, $4)))
1309 $$ = scm_cons ($4, $3);
1311 $$ = scm_cons (loc_on_music (@3, $1), $3);
1312 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1315 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1317 // There is no point interpreting a lyrics string as
1318 // an event, since we don't allow music possibly
1319 // followed by durations or postevent into closed
1320 // music, and we only accept closed music in optional
1321 // arguments at the moment. If this changes, more
1322 // complex schemes might become interesting here as
1323 // well: see how we do this at the mandatory argument
1325 if (scm_is_true (scm_call_1 ($2, $4)))
1326 $$ = scm_cons ($3, $2);
1328 $$ = scm_cons (loc_on_music (@3, $1), $3);
1329 MYBACKUP (LYRIC_MARKUP_IDENTIFIER, $4, @4);
1332 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1334 if (scm_is_true (scm_call_1 ($2, $4)))
1337 MYREPARSE (@4, $2, UNSIGNED, $4);
1339 $$ = scm_cons (loc_on_music (@3, $1), $3);
1340 MYBACKUP (UNSIGNED, $4, @4);
1343 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1345 if (scm_is_true (scm_call_1 ($2, $4)))
1348 MYREPARSE (@4, $2, REAL, $4);
1350 $$ = scm_cons (loc_on_music (@3, $1), $3);
1351 MYBACKUP (REAL, $4, @4);
1354 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1356 if (scm_is_true (scm_call_1 ($2, $4)))
1358 $$ = scm_cons ($4, $3);
1360 $$ = scm_cons (loc_on_music (@3, $1), $3);
1361 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1364 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1366 if (scm_is_true (scm_call_1 ($2, $4)))
1368 $$ = scm_cons ($4, $3);
1370 $$ = scm_cons (loc_on_music (@3, $1), $3);
1371 MYBACKUP (FRACTION, $4, @4);
1374 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1376 $$ = scm_cons ($4, $3);
1378 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1380 $$ = scm_cons ($4, $3);
1382 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1384 $$ = scm_cons ($1, $3);
1385 MYBACKUP(0, SCM_UNDEFINED, @3);
1387 | function_arglist_backup REPARSE embedded_scm_arg_closed
1389 $$ = check_scheme_arg (PARSER, @3,
1392 | function_arglist_backup REPARSE bare_number
1394 $$ = check_scheme_arg (PARSER, @3,
1397 | function_arglist_backup REPARSE fraction
1399 $$ = check_scheme_arg (PARSER, @3,
1405 function_arglist_common
1406 | function_arglist_nonbackup
1409 function_arglist_common:
1410 function_arglist_bare
1411 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1413 $$ = check_scheme_arg (PARSER, @3,
1416 | EXPECT_SCM function_arglist_closed_optional bare_number
1418 $$ = check_scheme_arg (PARSER, @3,
1421 | EXPECT_SCM function_arglist_closed_optional fraction
1423 $$ = check_scheme_arg (PARSER, @3,
1426 | EXPECT_SCM function_arglist_closed_optional post_event
1428 $$ = check_scheme_arg (PARSER, @3,
1431 | function_arglist_common_lyric
1434 function_arglist_common_lyric:
1435 EXPECT_SCM function_arglist_optional lyric_element
1437 // We check how the predicate thinks about a lyrics
1438 // event or about a markup. If it accepts neither, we
1439 // backup the original token. Otherwise we commit to
1440 // taking the token. Depending on what the predicate
1441 // is willing to accept, we interpret as a string, as
1442 // a lyric event, or ambiguously (meaning that if
1443 // something looking like a duration or post event
1444 // follows, we take the event, otherwise the string).
1445 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1446 PARSER->default_duration_.smobbed_copy ());
1447 if (scm_is_true (scm_call_1 ($1, $3)))
1448 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1451 MYREPARSE (@3, $1, LYRIC_ELEMENT_P, $3);
1453 $$ = scm_cons ($3, $2);
1455 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1458 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1460 // This is going to flag a syntax error, we
1461 // know the predicate to be false.
1462 check_scheme_arg (PARSER, @3,
1466 | function_arglist_common_lyric REPARSE lyric_element_arg
1468 // This should never be false
1469 $$ = check_scheme_arg (PARSER, @3,
1474 function_arglist_closed:
1475 function_arglist_closed_common
1476 | function_arglist_nonbackup
1479 function_arglist_closed_common:
1480 function_arglist_bare
1481 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1483 $$ = check_scheme_arg (PARSER, @3,
1486 | EXPECT_SCM function_arglist_closed_optional bare_number_closed
1488 $$ = check_scheme_arg (PARSER, @3,
1491 | EXPECT_SCM function_arglist_closed_optional post_event
1493 $$ = check_scheme_arg (PARSER, @3,
1496 | EXPECT_SCM function_arglist_closed_optional FRACTION
1498 $$ = check_scheme_arg (PARSER, @3,
1501 | EXPECT_SCM function_arglist_optional lyric_element
1503 $$ = check_scheme_arg (PARSER, @3,
1508 function_arglist_optional:
1509 function_arglist_keep %prec FUNCTION_ARGLIST
1510 | function_arglist_backup BACKUP
1511 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1513 $$ = scm_cons ($1, $3);
1515 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1517 $$ = scm_cons ($1, $3);
1521 function_arglist_closed_optional:
1522 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1523 | function_arglist_backup BACKUP
1524 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1526 $$ = scm_cons ($1, $3);
1528 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1530 $$ = scm_cons ($1, $3);
1534 embedded_scm_closed:
1536 | scm_function_call_closed
1539 embedded_scm_arg_closed:
1540 embedded_scm_bare_arg
1541 | scm_function_call_closed
1545 scm_function_call_closed:
1546 SCM_FUNCTION function_arglist_closed {
1547 $$ = MAKE_SYNTAX ("music-function", @$,
1549 } %prec FUNCTION_ARGLIST
1552 function_arglist_bare:
1553 EXPECT_NO_MORE_ARGS {
1556 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1557 $$ = scm_cons ($3, $2);
1559 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1560 $$ = scm_cons ($3, $2);
1562 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1563 $$ = scm_cons ($1, $3);
1565 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1566 $$ = scm_cons ($1, $3);
1568 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1569 $$ = scm_cons ($1, $3);
1573 music_function_call:
1574 MUSIC_FUNCTION function_arglist {
1575 $$ = MAKE_SYNTAX ("music-function", @$,
1582 /**/ { $$ = SCM_EOL; }
1583 | '=' simple_string {
1590 | repeated_music { $$ = $1; }
1591 | re_rhythmed_music { $$ = $1; }
1592 | complex_music_prefix music
1594 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1598 complex_music_prefix:
1599 CONTEXT simple_string optional_id optional_context_mod {
1600 Context_mod *ctxmod = unsmob_context_mod ($4);
1603 mods = ctxmod->get_mods ();
1604 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1606 | NEWCONTEXT simple_string optional_id optional_context_mod {
1607 Context_mod *ctxmod = unsmob_context_mod ($4);
1610 mods = ctxmod->get_mods ();
1611 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1616 mode_changing_head grouped_music_list {
1617 if ($1 == ly_symbol2scm ("chords"))
1619 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1625 PARSER->lexer_->pop_state ();
1627 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1628 Context_mod *ctxmod = unsmob_context_mod ($2);
1631 mods = ctxmod->get_mods ();
1632 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1633 if ($1 == ly_symbol2scm ("ChordNames"))
1635 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1637 PARSER->lexer_->pop_state ();
1643 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1644 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1646 $$ = ly_symbol2scm ("notes");
1650 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1651 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1653 $$ = ly_symbol2scm ("drums");
1656 PARSER->lexer_->push_figuredbass_state ();
1658 $$ = ly_symbol2scm ("figures");
1661 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1662 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1663 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1664 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1665 $$ = ly_symbol2scm ("chords");
1669 { PARSER->lexer_->push_lyric_state ();
1670 $$ = ly_symbol2scm ("lyrics");
1674 mode_changing_head_with_context:
1676 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1677 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1679 $$ = ly_symbol2scm ("DrumStaff");
1682 PARSER->lexer_->push_figuredbass_state ();
1684 $$ = ly_symbol2scm ("FiguredBass");
1687 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1688 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1689 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1690 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1691 $$ = ly_symbol2scm ("ChordNames");
1694 { PARSER->lexer_->push_lyric_state ();
1695 $$ = ly_symbol2scm ("Lyrics");
1700 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1703 /* Can also use music at the expensive of two S/Rs similar to
1704 \repeat \alternative */
1705 PARSER->lexer_->pop_state ();
1707 $$ = scm_cons ($3, SCM_EOL);
1709 | new_lyrics ADDLYRICS {
1710 PARSER->lexer_->push_lyric_state ();
1712 PARSER->lexer_->pop_state ();
1713 $$ = scm_cons ($4, $1);
1718 composite_music new_lyrics {
1719 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1721 | LYRICSTO simple_string {
1722 PARSER->lexer_->push_lyric_state ();
1724 PARSER->lexer_->pop_state ();
1725 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1730 CHANGE STRING '=' STRING {
1731 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1736 property_path_revved:
1737 embedded_scm_closed {
1738 $$ = scm_cons ($1, SCM_EOL);
1740 | property_path_revved embedded_scm_closed {
1741 $$ = scm_cons ($2, $1);
1746 property_path_revved {
1747 $$ = scm_reverse_x ($1, SCM_EOL);
1753 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1754 scm_string_to_symbol ($1), $3);
1756 | UNSET simple_string {
1757 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1758 scm_string_to_symbol ($2));
1760 | OVERRIDE simple_string property_path '=' scalar {
1761 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1762 scm_string_to_symbol ($2), $5),
1765 | REVERT simple_string embedded_scm {
1766 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1767 scm_string_to_symbol ($2), $3);
1772 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1773 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1775 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1776 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1777 | DENIES { $$ = ly_symbol2scm ("denies"); }
1779 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1780 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1781 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1782 | NAME { $$ = ly_symbol2scm ("context-name"); }
1786 property_operation { $$ = $1; }
1787 | context_def_mod STRING {
1788 $$ = scm_list_2 ($1, $2);
1790 | context_def_mod embedded_scm {
1791 if (ly_symbol2scm ("consists") != $1)
1794 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1798 $$ = scm_list_2 ($1, $2);
1805 if (!is_regular_identifier ($1))
1807 @$.error (_("Grob name should be alphanumeric"));
1810 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1811 scm_string_to_symbol ($1));
1813 | simple_string '.' simple_string {
1814 $$ = scm_list_2 (scm_string_to_symbol ($1),
1815 scm_string_to_symbol ($3));
1819 simple_music_property_def:
1820 OVERRIDE context_prop_spec property_path '=' scalar {
1821 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1822 ly_symbol2scm ("OverrideProperty"),
1827 | REVERT context_prop_spec embedded_scm {
1828 $$ = scm_list_4 (scm_car ($2),
1829 ly_symbol2scm ("RevertProperty"),
1833 | SET context_prop_spec '=' scalar {
1834 $$ = scm_list_4 (scm_car ($2),
1835 ly_symbol2scm ("PropertySet"),
1839 | UNSET context_prop_spec {
1840 $$ = scm_list_3 (scm_car ($2),
1841 ly_symbol2scm ("PropertyUnset"),
1847 simple_music_property_def {
1848 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (PARSER->self_scm (), make_input (@$), $1));
1856 | STRING_IDENTIFIER {
1859 | string '+' string {
1860 $$ = scm_string_append (scm_list_2 ($1, $3));
1864 simple_string: STRING {
1870 | STRING_IDENTIFIER {
1882 embedded_scm_arg_closed
1889 /* TODO: Create a special case that avoids the creation of
1890 EventChords around simple_elements that have no post_events?
1892 simple_chord_elements post_events {
1893 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1896 /* why is this giving wrong start location? -ns
1898 i.set_location (@1, @2);
1899 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1901 | CHORD_REPETITION optional_notemode_duration post_events {
1903 i.set_location (@1, @3);
1904 $$ = MAKE_SYNTAX ("repetition-chord", i,
1905 PARSER->lexer_->chord_repetition_.last_chord_,
1906 PARSER->lexer_->chord_repetition_.repetition_function_,
1907 $2, scm_reverse_x ($3, SCM_EOL));
1909 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1911 i.set_location (@1, @3);
1912 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1913 scm_reverse_x ($3, SCM_EOL));
1916 /* note chord elements are memorized into
1917 PARSER->lexer_->chord_repetition_ so that the chord repetition
1918 mechanism copy them when a chord repetition symbol is found
1920 | note_chord_element {
1921 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
1927 chord_body optional_notemode_duration post_events
1929 Music *m = unsmob_music ($1);
1930 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1931 SCM es = m->get_property ("elements");
1932 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1934 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1935 unsmob_music (scm_car (s))->set_property ("duration", dur);
1936 es = ly_append2 (es, postevs);
1938 m-> set_property ("elements", es);
1940 $$ = m->self_scm ();
1945 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1947 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1951 chord_body_elements:
1952 /* empty */ { $$ = SCM_EOL; }
1953 | chord_body_elements chord_body_element {
1954 $$ = scm_cons ($2, $1);
1959 pitch exclamations questions octave_check post_events
1966 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1967 n->set_property ("pitch", $1);
1969 n->set_property ("cautionary", SCM_BOOL_T);
1970 if (ex % 2 || q % 2)
1971 n->set_property ("force-accidental", SCM_BOOL_T);
1973 if (scm_is_pair (post)) {
1974 SCM arts = scm_reverse_x (post, SCM_EOL);
1975 n->set_property ("articulations", arts);
1977 if (scm_is_number (check))
1979 int q = scm_to_int (check);
1980 n->set_property ("absolute-octave", scm_from_int (q-1));
1983 $$ = n->unprotect ();
1985 | DRUM_PITCH post_events {
1986 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1987 n->set_property ("drum-type", $1);
1989 if (scm_is_pair ($2)) {
1990 SCM arts = scm_reverse_x ($2, SCM_EOL);
1991 n->set_property ("articulations", arts);
1993 $$ = n->unprotect ();
1995 | music_function_chord_body
1998 /* We can't accept a music argument, not even a closed one,
1999 * immediately before chord_body_elements, otherwise a function \fun
2000 * with a signature of two music arguments can't be sorted out
2001 * properly in a construct like
2002 * <\fun { c } \fun { c } c>
2003 * The second call could be interpreted either as a chord constituent
2004 * or a music expression.
2007 music_function_chord_body_arglist:
2008 function_arglist_bare
2009 | EXPECT_SCM music_function_chord_body_arglist embedded_scm_chord_body
2011 $$ = check_scheme_arg (PARSER, @3,
2016 embedded_scm_chord_body:
2017 embedded_scm_bare_arg
2018 | SCM_FUNCTION music_function_chord_body_arglist {
2019 $$ = MAKE_SYNTAX ("music-function", @$,
2025 | chord_body_element
2028 music_function_chord_body:
2029 MUSIC_FUNCTION music_function_chord_body_arglist {
2030 $$ = MAKE_SYNTAX ("music-function", @$,
2035 // Event functions may only take closed arglists, otherwise it would
2036 // not be clear whether a following postevent should be associated
2037 // with the last argument of the event function or with the expression
2038 // for which the function call acts itself as event.
2040 music_function_event:
2041 MUSIC_FUNCTION function_arglist_closed {
2042 $$ = MAKE_SYNTAX ("music-function", @$,
2047 event_function_event:
2048 EVENT_FUNCTION function_arglist_closed {
2049 $$ = MAKE_SYNTAX ("music-function", @$,
2059 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2060 m->set_property ("span-direction", scm_from_int (START));
2061 $$ = m->unprotect();
2064 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2065 m->set_property ("span-direction", scm_from_int (STOP));
2066 $$ = m->unprotect ();
2069 $$ = MAKE_SYNTAX ("voice-separator", @$);
2072 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
2074 Music *m = unsmob_music (pipe);
2079 $$ = m->unprotect ();
2082 $$ = MAKE_SYNTAX ("bar-check", @$);
2089 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2101 | post_events post_event {
2102 unsmob_music ($2)->set_spot (@2);
2103 $$ = scm_cons ($2, $$);
2107 post_event_nofinger:
2108 direction_less_event {
2111 | script_dir music_function_event {
2115 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2119 if (!PARSER->lexer_->is_lyric_state ())
2120 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2121 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2124 if (!PARSER->lexer_->is_lyric_state ())
2125 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2126 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2128 | script_dir direction_reqd_event {
2131 Music *m = unsmob_music ($2);
2132 m->set_property ("direction", scm_from_int ($1));
2136 | script_dir direction_less_event {
2139 Music *m = unsmob_music ($2);
2140 m->set_property ("direction", scm_from_int ($1));
2144 | string_number_event
2149 | script_dir fingering {
2152 Music *m = unsmob_music ($2);
2153 m->set_property ("direction", scm_from_int ($1));
2159 string_number_event:
2161 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2162 s->set_property ("string-number", scm_from_int ($1));
2163 $$ = s->unprotect ();
2167 direction_less_char:
2169 $$ = ly_symbol2scm ("bracketOpenSymbol");
2172 $$ = ly_symbol2scm ("bracketCloseSymbol");
2175 $$ = ly_symbol2scm ("tildeSymbol");
2178 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2181 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2184 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2187 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2190 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2193 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2196 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2200 direction_less_event:
2201 direction_less_char {
2202 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
2204 if (unsmob_music (predefd))
2206 m = unsmob_music (predefd)->clone ();
2211 m = MY_MAKE_MUSIC ("Music", @$);
2213 $$ = m->unprotect ();
2215 | EVENT_IDENTIFIER {
2219 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2220 a->set_property ("tremolo-type", scm_from_int ($1));
2221 $$ = a->unprotect ();
2223 | event_function_event
2226 direction_reqd_event:
2230 | script_abbreviation {
2231 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2232 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2233 if (scm_is_string (s))
2234 a->set_property ("articulation-type", s);
2235 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
2236 $$ = a->unprotect ();
2241 /**/ { $$ = SCM_EOL; }
2242 | '=' { $$ = scm_from_int (0); }
2243 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2244 | '=' sup_quotes { $$ = scm_from_int ($2); }
2269 | NOTENAME_PITCH sup_quotes {
2270 Pitch p = *unsmob_pitch ($1);
2271 p = p.transposed (Pitch ($2,0,0));
2272 $$ = p.smobbed_copy ();
2274 | NOTENAME_PITCH sub_quotes {
2275 Pitch p =* unsmob_pitch ($1);
2276 p = p.transposed (Pitch (-$2,0,0));
2277 $$ = p.smobbed_copy ();
2289 | TONICNAME_PITCH sup_quotes {
2290 Pitch p = *unsmob_pitch ($1);
2291 p = p.transposed (Pitch ($2,0,0));
2292 $$ = p.smobbed_copy ();
2294 | TONICNAME_PITCH sub_quotes {
2295 Pitch p = *unsmob_pitch ($1);
2297 p = p.transposed (Pitch (-$2,0,0));
2298 $$ = p.smobbed_copy ();
2309 pitch_also_in_chords:
2316 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2317 t->set_property ("text", $1);
2318 $$ = t->unprotect ();
2321 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2322 t->set_property ("text",
2323 make_simple_markup ($1));
2324 $$ = t->unprotect ();
2330 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2331 t->set_property ("digit", $1);
2332 $$ = t->unprotect ();
2336 script_abbreviation:
2338 $$ = scm_from_locale_string ("Hat");
2341 $$ = scm_from_locale_string ("Plus");
2344 $$ = scm_from_locale_string ("Dash");
2347 $$ = scm_from_locale_string ("Bar");
2350 $$ = scm_from_locale_string ("Larger");
2353 $$ = scm_from_locale_string ("Dot");
2356 $$ = scm_from_locale_string ("Underscore");
2363 | '-' { $$ = CENTER; }
2367 multiplied_duration {
2372 optional_notemode_duration:
2374 Duration dd = PARSER->default_duration_;
2375 $$ = dd.smobbed_copy ();
2377 | multiplied_duration {
2379 PARSER->default_duration_ = *unsmob_duration ($$);
2384 bare_unsigned dots {
2386 if (!is_duration ($1))
2387 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
2391 $$ = Duration (len, $2).smobbed_copy ();
2393 | DURATION_IDENTIFIER dots {
2394 Duration *d = unsmob_duration ($1);
2395 Duration k (d->duration_log (), d->dot_count () + $2);
2396 k = k.compressed (d->factor ());
2402 multiplied_duration:
2406 | multiplied_duration '*' bare_unsigned {
2407 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2409 | multiplied_duration '*' FRACTION {
2410 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2412 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2417 FRACTION { $$ = $1; }
2418 | UNSIGNED '/' UNSIGNED {
2419 $$ = scm_cons ($1, $3);
2436 | ':' bare_unsigned {
2437 if (!is_duration ($2))
2438 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2444 UNSIGNED { $$ = $1; }
2445 | STRING { $$ = $1; }
2446 | full_markup { $$ = $1; }
2449 figured_bass_alteration:
2450 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2451 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2452 | '!' { $$ = scm_from_int (0); }
2457 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2458 $$ = bfr->unprotect ();
2461 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2462 $$ = bfr->self_scm ();
2464 if (scm_is_number ($1))
2465 bfr->set_property ("figure", $1);
2466 else if (Text_interface::is_markup ($1))
2467 bfr->set_property ("text", $1);
2473 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2475 | bass_figure figured_bass_alteration {
2476 Music *m = unsmob_music ($1);
2477 if (scm_to_double ($2)) {
2478 SCM salter = m->get_property ("alteration");
2479 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2480 m->set_property ("alteration",
2481 scm_sum (alter, $2));
2483 m->set_property ("alteration", scm_from_int (0));
2486 | bass_figure figured_bass_modification {
2487 Music *m = unsmob_music ($1);
2488 if ($2 == ly_symbol2scm ("plus"))
2490 m->set_property ("augmented", SCM_BOOL_T);
2492 else if ($2 == ly_symbol2scm ("slash"))
2494 m->set_property ("diminished", SCM_BOOL_T);
2496 else if ($2 == ly_symbol2scm ("exclamation"))
2498 m->set_property ("no-continuation", SCM_BOOL_T);
2500 else if ($2 == ly_symbol2scm ("backslash"))
2502 m->set_property ("augmented-slash", SCM_BOOL_T);
2508 figured_bass_modification:
2510 $$ = ly_symbol2scm ("plus");
2513 $$ = ly_symbol2scm ("exclamation");
2516 $$ = ly_symbol2scm ("slash");
2519 $$ = ly_symbol2scm ("backslash");
2529 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2537 | figure_list br_bass_figure {
2538 $$ = scm_cons ($2, $1);
2543 FIGURE_OPEN figure_list FIGURE_CLOSE {
2544 $$ = scm_reverse_x ($2, SCM_EOL);
2555 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2556 if (!PARSER->lexer_->is_note_state ())
2557 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2561 n = MY_MAKE_MUSIC ("RestEvent", @$);
2563 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2565 n->set_property ("pitch", $1);
2566 n->set_property ("duration", $5);
2568 if (scm_is_number ($4))
2570 int q = scm_to_int ($4);
2571 n->set_property ("absolute-octave", scm_from_int (q-1));
2575 n->set_property ("cautionary", SCM_BOOL_T);
2576 if ($2 % 2 || $3 % 2)
2577 n->set_property ("force-accidental", SCM_BOOL_T);
2579 $$ = n->unprotect ();
2581 | DRUM_PITCH optional_notemode_duration {
2582 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2583 n->set_property ("duration", $2);
2584 n->set_property ("drum-type", $1);
2586 $$ = n->unprotect ();
2588 | RESTNAME optional_notemode_duration {
2590 if (ly_scm2string ($1) == "s") {
2592 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2595 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2598 ev->set_property ("duration", $2);
2599 $$ = ev->unprotect ();
2603 simple_chord_elements:
2605 $$ = scm_list_1 ($1);
2608 if (!PARSER->lexer_->is_chord_state ())
2609 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2612 | figure_spec optional_notemode_duration {
2613 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2615 unsmob_music (scm_car (s))->set_property ("duration", $2);
2633 | lyric_element multiplied_duration post_events {
2634 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2635 $$ = MAKE_SYNTAX ("event-chord", @$,
2636 scm_cons (lyric_event,
2637 scm_reverse_x ($3, SCM_EOL)));
2639 | lyric_element post_event post_events {
2641 MAKE_SYNTAX ("lyric-event", @$, $1,
2642 PARSER->default_duration_.smobbed_copy ());
2643 $$ = MAKE_SYNTAX ("event-chord", @$,
2644 scm_cons2 (lyric_event, $2,
2645 scm_reverse_x ($3, SCM_EOL)));
2648 | LYRIC_ELEMENT optional_notemode_duration post_events {
2649 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2650 $$ = MAKE_SYNTAX ("event-chord", @$,
2651 scm_cons (lyric_event,
2652 scm_reverse_x ($3, SCM_EOL)));
2657 lyric_element_music:
2658 lyric_element optional_notemode_duration post_events {
2659 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2660 $$ = MAKE_SYNTAX ("event-chord", @$,
2661 scm_cons (lyric_event,
2662 scm_reverse_x ($3, SCM_EOL)));
2667 steno_tonic_pitch optional_notemode_duration {
2668 $$ = make_chord_elements ($1, $2, SCM_EOL);
2670 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2671 SCM its = scm_reverse_x ($4, SCM_EOL);
2672 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2680 | chord_items chord_item {
2681 $$ = scm_cons ($2, $$);
2687 $$ = ly_symbol2scm ("chord-colon");
2690 $$ = ly_symbol2scm ("chord-caret");
2692 | CHORD_SLASH steno_tonic_pitch {
2693 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2695 | CHORD_BASS steno_tonic_pitch {
2696 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2705 $$ = scm_reverse_x ($1, SCM_EOL);
2713 step_number { $$ = scm_cons ($1, SCM_EOL); }
2714 | step_numbers '.' step_number {
2715 $$ = scm_cons ($3, $$);
2721 $$ = make_chord_step ($1, 0);
2723 | bare_unsigned '+' {
2724 $$ = make_chord_step ($1, SHARP_ALTERATION);
2726 | bare_unsigned CHORD_MINUS {
2727 $$ = make_chord_step ($1, FLAT_ALTERATION);
2733 $$ = scm_from_int ($1);
2735 | bare_unsigned '~' bare_unsigned {
2736 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2743 TODO: should deprecate in favor of Scheme?
2747 number_expression '+' number_term {
2748 $$ = scm_sum ($1, $3);
2750 | number_expression '-' number_term {
2751 $$ = scm_difference ($1, $3);
2760 | number_factor '*' number_factor {
2761 $$ = scm_product ($1, $3);
2763 | number_factor '/' number_factor {
2764 $$ = scm_divide ($1, $3);
2769 '-' number_factor { /* %prec UNARY_MINUS */
2770 $$ = scm_difference ($2, SCM_UNDEFINED);
2778 | UNSIGNED NUMBER_IDENTIFIER {
2779 $$ = scm_product ($1, $2)
2781 | REAL NUMBER_IDENTIFIER {
2782 $$ = scm_product ($1, $2)
2794 $$ = scm_to_int ($1);
2805 | exclamations '!' { $$ ++; }
2810 | questions '?' { $$ ++; }
2814 This should be done more dynamically if possible.
2818 LYRIC_MARKUP_IDENTIFIER {
2822 { PARSER->lexer_->push_markup_state (); }
2825 PARSER->lexer_->pop_state ();
2830 MARKUPLIST_IDENTIFIER {
2834 { PARSER->lexer_->push_markup_state (); }
2837 PARSER->lexer_->pop_state ();
2846 { PARSER->lexer_->push_markup_state (); }
2849 PARSER->lexer_->pop_state ();
2855 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2857 | markup_head_1_list simple_markup {
2858 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2866 MARKUPLIST_IDENTIFIER {
2869 | markup_composed_list {
2872 | markup_braced_list {
2875 | markup_command_list {
2876 $$ = scm_list_1 ($1);
2880 markup_composed_list:
2881 markup_head_1_list markup_braced_list {
2882 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2888 '{' markup_braced_list_body '}' {
2889 $$ = scm_reverse_x ($2, SCM_EOL);
2893 markup_braced_list_body:
2894 /* empty */ { $$ = SCM_EOL; }
2895 | markup_braced_list_body markup {
2896 $$ = scm_cons ($2, $1);
2898 | markup_braced_list_body markup_list {
2899 $$ = scm_reverse_x ($2, $1);
2903 markup_command_list:
2904 MARKUP_LIST_FUNCTION markup_command_list_arguments {
2905 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
2909 markup_command_basic_arguments:
2910 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
2911 $$ = scm_cons ($3, $2);
2913 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
2914 $$ = check_scheme_arg (PARSER, @3, $3, $2, $1);
2916 | EXPECT_NO_MORE_ARGS {
2921 markup_command_list_arguments:
2922 markup_command_basic_arguments { $$ = $1; }
2923 | EXPECT_MARKUP markup_command_list_arguments markup {
2924 $$ = scm_cons ($3, $2);
2929 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
2930 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
2935 markup_head_1_item {
2936 $$ = scm_list_1 ($1);
2938 | markup_head_1_list markup_head_1_item {
2939 $$ = scm_cons ($2, $1);
2945 $$ = make_simple_markup ($1);
2947 | MARKUP_IDENTIFIER {
2950 | LYRIC_MARKUP_IDENTIFIER {
2953 | STRING_IDENTIFIER {
2957 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2958 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2959 } '{' score_body '}' {
2961 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2963 PARSER->lexer_->pop_state ();
2965 | MARKUP_FUNCTION markup_command_basic_arguments {
2966 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
2971 markup_head_1_list simple_markup {
2972 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2973 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2983 Lily_parser::set_yydebug (bool x)
2989 Lily_parser::do_yyparse ()
2991 yyparse ((void*)this);
3000 It is a little strange to have this function in this file, but
3001 otherwise, we have to import music classes into the lexer.
3005 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3007 if (scm_is_string (sid)) {
3009 return STRING_IDENTIFIER;
3010 } else if (unsmob_book (sid)) {
3011 Book *book = unsmob_book (sid)->clone ();
3012 *destination = book->self_scm ();
3015 return BOOK_IDENTIFIER;
3016 } else if (scm_is_number (sid)) {
3018 return NUMBER_IDENTIFIER;
3019 } else if (unsmob_context_def (sid)) {
3020 Context_def *def= unsmob_context_def (sid)->clone ();
3022 *destination = def->self_scm ();
3025 return CONTEXT_DEF_IDENTIFIER;
3026 } else if (unsmob_context_mod (sid)) {
3027 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3029 return CONTEXT_MOD_IDENTIFIER;
3030 } else if (unsmob_score (sid)) {
3031 Score *score = new Score (*unsmob_score (sid));
3032 *destination = score->self_scm ();
3034 score->unprotect ();
3035 return SCORE_IDENTIFIER;
3036 } else if (Music *mus = unsmob_music (sid)) {
3037 mus = mus->clone ();
3038 *destination = mus->self_scm ();
3039 unsmob_music (*destination)->
3040 set_property ("origin", make_input (last_input_));
3042 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
3046 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3047 } else if (unsmob_pitch (sid)) {
3048 *destination = unsmob_pitch (sid)->smobbed_copy ();
3049 return PITCH_IDENTIFIER;
3050 } else if (unsmob_duration (sid)) {
3051 *destination = unsmob_duration (sid)->smobbed_copy ();
3052 return DURATION_IDENTIFIER;
3053 } else if (unsmob_output_def (sid)) {
3054 Output_def *p = unsmob_output_def (sid);
3057 *destination = p->self_scm ();
3059 return OUTPUT_DEF_IDENTIFIER;
3060 } else if (Text_interface::is_markup (sid)) {
3062 if (is_lyric_state ())
3063 return LYRIC_MARKUP_IDENTIFIER;
3064 return MARKUP_IDENTIFIER;
3065 } else if (Text_interface::is_markup_list (sid)) {
3067 return MARKUPLIST_IDENTIFIER;
3074 get_next_unique_context_id ()
3076 return scm_from_locale_string ("$uniqueContextId");
3081 get_next_unique_lyrics_context_id ()
3083 static int new_context_count;
3085 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3086 return scm_from_locale_string (s);
3089 SCM check_scheme_arg (Lily_parser *my_lily_parser, Input loc,
3090 SCM arg, SCM args, SCM pred)
3092 args = scm_cons (arg, args);
3093 if (scm_is_true (scm_call_1 (pred, arg)))
3095 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3096 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3097 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3101 SCM loc_on_music (Input loc, SCM arg)
3103 if (Music *m = unsmob_music (arg))
3107 return m->unprotect ();
3113 is_regular_identifier (SCM id)
3115 string str = ly_scm2string (id);
3116 char const *s = str.c_str ();
3125 v = v && isalnum (*s);
3132 make_music_with_input (SCM name, Input where)
3134 Music *m = make_music_by_name (name);
3135 m->set_spot (where);
3140 get_first_context_id (SCM type, Music *m)
3142 SCM id = m->get_property ("context-id");
3143 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
3144 && scm_is_string (m->get_property ("context-id"))
3145 && scm_c_string_length (id) > 0)
3153 make_simple_markup (SCM a)
3161 return t && t == 1 << intlog2 (t);
3165 set_music_properties (Music *p, SCM a)
3167 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3168 p->set_property (scm_caar (k), scm_cdar (k));
3173 make_chord_step (int step, Rational alter)
3176 alter += FLAT_ALTERATION;
3180 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3181 return m.smobbed_copy ();
3186 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
3188 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3189 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
3193 try_unpack_lyrics (SCM pred, SCM arg)
3195 if (Music *m = unsmob_music (arg))
3196 if (m->is_mus_type ("lyric-event")) {
3197 SCM text = m->get_property ("text");
3198 if (scm_is_true (scm_call_1 (pred, text)))
3201 return SCM_UNDEFINED;
3204 /* Todo: actually also use apply iso. call too ... */
3206 ly_input_procedure_p (SCM x)
3208 return ly_is_procedure (x)
3209 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
3213 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
3215 Lily_parser *pars = (Lily_parser*) v;
3216 Lily_lexer *lex = pars->lexer_;
3218 lex->lexval_ = (void*) s;
3220 lex->prepare_for_next_token ();
3221 return lex->yylex ();