]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
Implement define-event-function
[lilypond.git] / lily / parser.yy
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5                  Jan Nieuwenhuizen <janneke@gnu.org>
6
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.
11
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.
16
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/>.
19 */
20
21 %{
22
23 #define YYDEBUG 1
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)
28
29 #define yyerror PARSER->parser_error
30
31 /* We use custom location type: Input objects */
32 #define YYLTYPE Input
33 #define YYLLOC_DEFAULT(Current,Rhs,N) \
34         ((Current).set_location ((Rhs)[1], (Rhs)[N]))
35
36
37 %}
38
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. */
42
43 %left PREC_BOT
44 %nonassoc REPEAT
45 %nonassoc ALTERNATIVE
46 %left ADDLYRICS
47 %left PREC_TOP
48
49
50 /* The above precedences tackle the shift/reduce problem
51
52 1.  \repeat
53         \repeat .. \alternative
54
55     \repeat { \repeat .. \alternative }
56
57 or
58
59     \repeat { \repeat } \alternative
60 */
61
62
63 %pure_parser
64 %locations
65
66
67
68 %{ // -*-Fundamental-*-
69
70 /*
71 FIXME:
72
73    * The rules for who is protecting what are very shady.  Uniformise
74      this.
75
76    * There are too many lexical modes?
77 */
78
79 #include "config.hh"
80
81 #include <cctype>
82 #include <cstdlib>
83 #include <cstdio>
84 using namespace std;
85
86 #include "book.hh"
87 #include "context-def.hh"
88 #include "context-mod.hh"
89 #include "dimensions.hh"
90 #include "file-path.hh"
91 #include "input.hh"
92 #include "international.hh"
93 #include "lily-guile.hh"
94 #include "lily-lexer.hh"
95 #include "lily-parser.hh"
96 #include "main.hh"
97 #include "misc.hh"
98 #include "music.hh"
99 #include "music.hh"
100 #include "output-def.hh"
101 #include "paper-book.hh"
102 #include "program-option.hh"
103 #include "scm-hash.hh"
104 #include "score.hh"
105 #include "text-interface.hh"
106 #include "warn.hh"
107
108 %}
109
110
111 %union {
112         Book *book;
113         Output_def *outputdef;
114         SCM scm;
115         std::string *string;
116         Music *music;
117         Score *score;
118         int i;
119 }
120
121 %{
122
123 #define MY_MAKE_MUSIC(x, spot)  make_music_with_input (ly_symbol2scm (x), spot)
124
125 /* ES TODO:
126 - Don't use lily module, create a new module instead.
127 - delay application of the function
128 */
129 #define LOWLEVEL_MAKE_SYNTAX(proc, args)        \
130   scm_apply_0 (proc, args)
131 /* Syntactic Sugar. */
132 #define MAKE_SYNTAX(name, location, ...)        \
133   LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location), __VA_ARGS__, SCM_UNDEFINED));
134
135 SCM get_next_unique_context_id ();
136 SCM get_next_unique_lyrics_context_id ();
137
138 #undef _
139 #if !HAVE_GETTEXT
140 #define _(x) x
141 #else
142 #include <libintl.h>
143 #define _(x) gettext (x)
144 #endif
145
146
147 static Music *make_music_with_input (SCM name, Input where);
148 SCM make_music_relative (Pitch start, SCM music, Input loc);
149 SCM run_music_function (Lily_parser *parser, Input loc, SCM func, SCM args);
150 SCM get_first_context_id (SCM type, Music *m);
151 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
152 SCM make_chord_step (int step, Rational alter);
153 SCM make_simple_markup (SCM a);
154 bool is_duration (int t);
155 bool is_regular_identifier (SCM id);
156 bool ly_input_procedure_p (SCM x);
157 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
158 void set_music_properties (Music *p, SCM a);
159
160 %}
161
162 /* The third option is an alias that will be used to display the
163    syntax error.  Bison CVS now correctly handles backslash escapes.
164
165    FIXME: Bison needs to translate some of these, eg, STRING.
166
167 */
168
169 /* Keyword tokens with plain escaped name.  */
170 %token ACCEPTS "\\accepts"
171 %token ADDLYRICS "\\addlyrics"
172 %token ALIAS "\\alias"
173 %token ALTERNATIVE "\\alternative"
174 %token BOOK "\\book"
175 %token BOOKPART "\\bookpart"
176 %token CHANGE "\\change"
177 %token CHORDMODE "\\chordmode"
178 %token CHORDS "\\chords"
179 %token CONSISTS "\\consists"
180 %token CONTEXT "\\context"
181 %token DEFAULT "\\default"
182 %token DEFAULTCHILD "\\defaultchild"
183 %token DENIES "\\denies"
184 %token DESCRIPTION "\\description"
185 %token DRUMMODE "\\drummode"
186 %token DRUMS "\\drums"
187 %token FIGUREMODE "\\figuremode"
188 %token FIGURES "\\figures"
189 %token GROBDESCRIPTIONS "\\grobdescriptions"
190 %token HEADER "\\header"
191 %token INVALID "\\version-error"
192 %token KEY "\\key"
193 %token LAYOUT "\\layout"
194 %token LYRICMODE "\\lyricmode"
195 %token LYRICS "\\lyrics"
196 %token LYRICSTO "\\lyricsto"
197 %token MARK "\\mark"
198 %token MARKUP "\\markup"
199 %token MARKUPLINES "\\markuplines"
200 %token MIDI "\\midi"
201 %token NAME "\\name"
202 %token NOTEMODE "\\notemode"
203 %token ONCE "\\once"
204 %token OVERRIDE "\\override"
205 %token PAPER "\\paper"
206 %token RELATIVE "\\relative"
207 %token REMOVE "\\remove"
208 %token REPEAT "\\repeat"
209 %token REST "\\rest"
210 %token REVERT "\\revert"
211 %token SCORE "\\score"
212 %token SEQUENTIAL "\\sequential"
213 %token SET "\\set"
214 %token SIMULTANEOUS "\\simultaneous"
215 %token TEMPO "\\tempo"
216 %token TIMES "\\times"
217 %token TYPE "\\type"
218 %token UNSET "\\unset"
219 %token WITH "\\with"
220
221 /* Keyword token exceptions.  */
222 %token TIME_T "\\time"
223 %token NEWCONTEXT "\\new"
224
225
226 /* Other string tokens.  */
227
228 %token CHORD_BASS "/+"
229 %token CHORD_CARET "^"
230 %token CHORD_COLON ":"
231 %token CHORD_MINUS "-"
232 %token CHORD_SLASH "/"
233 %token ANGLE_OPEN "<"
234 %token ANGLE_CLOSE ">"
235 %token DOUBLE_ANGLE_OPEN "<<"
236 %token DOUBLE_ANGLE_CLOSE ">>"
237 %token E_BACKSLASH "\\"
238 %token E_ANGLE_CLOSE "\\>"
239 %token E_CHAR "\\C[haracter]"
240 %token E_CLOSE "\\)"
241 %token E_EXCLAMATION "\\!"
242 %token E_BRACKET_OPEN "\\["
243 %token E_OPEN "\\("
244 %token E_BRACKET_CLOSE "\\]"
245 %token E_ANGLE_OPEN "\\<"
246 %token E_PLUS "\\+"
247 %token E_TILDE "\\~"
248 %token EXTENDER "__"
249
250 /*
251 If we give names, Bison complains.
252 */
253 %token FIGURE_CLOSE /* "\\>" */
254 %token FIGURE_OPEN /* "\\<" */
255 %token FIGURE_SPACE "_"
256 %token HYPHEN "--"
257
258 %token CHORDMODIFIERS
259 %token LYRIC_MARKUP
260 %token MULTI_MEASURE_REST
261
262
263 %token <i> E_UNSIGNED
264 %token <i> UNSIGNED
265
266 /* Artificial tokens, for more generic function syntax */
267 %token <i> EXPECT_MARKUP "markup?"
268 %token <i> EXPECT_MUSIC "ly:music?"
269 %token <i> EXPECT_PITCH "ly:pitch?"
270 %token <i> EXPECT_DURATION "ly:duration?"
271 %token <i> EXPECT_SCM "scheme?"
272 %token <i> EXPECT_MARKUP_LIST "markup-list?"
273 /* After the last argument. */
274 %token <i> EXPECT_NO_MORE_ARGS;
275
276 /* An artificial token for parsing embedded Lilypond */
277 %token <i> EMBEDDED_LILY "#{"
278
279 %token <scm> BOOK_IDENTIFIER
280 %token <scm> CHORDMODIFIER_PITCH
281 %token <scm> CHORD_MODIFIER
282 %token <scm> CHORD_REPETITION
283 %token <scm> CONTEXT_DEF_IDENTIFIER
284 %token <scm> CONTEXT_MOD_IDENTIFIER
285 %token <scm> DRUM_PITCH
286 %token <scm> PITCH_IDENTIFIER
287 %token <scm> DURATION_IDENTIFIER
288 %token <scm> EVENT_IDENTIFIER
289 %token <scm> EVENT_FUNCTION
290 %token <scm> FRACTION
291 %token <scm> LYRICS_STRING
292 %token <scm> LYRIC_MARKUP_IDENTIFIER
293 %token <scm> MARKUP_FUNCTION
294 %token <scm> MARKUP_LIST_FUNCTION
295 %token <scm> MARKUP_IDENTIFIER
296 %token <scm> MARKUPLINES_IDENTIFIER
297 %token <scm> MUSIC_FUNCTION
298 %token <scm> MUSIC_IDENTIFIER
299 %token <scm> NOTENAME_PITCH
300 %token <scm> NUMBER_IDENTIFIER
301 %token <scm> OUTPUT_DEF_IDENTIFIER
302 %token <scm> REAL
303 %token <scm> RESTNAME
304 %token <scm> SCM_FUNCTION
305 %token <scm> SCM_IDENTIFIER
306 %token <scm> SCM_TOKEN
307 %token <scm> SCORE_IDENTIFIER
308 %token <scm> STRING
309 %token <scm> STRING_IDENTIFIER
310 %token <scm> TONICNAME_PITCH
311
312
313 %type <book> book_block
314 %type <book> book_body
315 %type <book> bookpart_block
316 %type <book> bookpart_body
317
318 %type <i> bare_unsigned
319 %type <scm> figured_bass_alteration
320 %type <i> dots
321 %type <i> exclamations
322 %type <i> optional_rest
323 %type <i> questions
324 %type <i> script_dir
325 %type <i> sub_quotes
326 %type <i> sup_quotes
327 %type <i> tremolo_type
328
329 /* Music */
330 %type <scm> composite_music
331 %type <scm> grouped_music_list
332 %type <scm> braced_music_list
333 %type <scm> closed_music
334 %type <scm> music
335 %type <scm> prefix_composite_music
336 %type <scm> repeated_music
337 %type <scm> sequential_music
338 %type <scm> simple_music
339 %type <scm> simultaneous_music
340 %type <scm> chord_body
341 %type <scm> chord_body_element
342 %type <scm> command_element
343 %type <scm> command_event
344 %type <scm> context_modification
345 %type <scm> context_change
346 %type <scm> direction_less_event
347 %type <scm> direction_reqd_event
348 %type <scm> embedded_lilypond
349 %type <scm> event_chord
350 %type <scm> fingering
351 %type <scm> gen_text_def
352 %type <scm> music_property_def
353 %type <scm> note_chord_element
354 %type <scm> post_event
355 %type <scm> post_event_nofinger
356 %type <scm> re_rhythmed_music
357 %type <scm> relative_music
358 %type <scm> simple_element
359 %type <scm> simple_music_property_def
360 %type <scm> start_symbol
361 %type <scm> string_number_event
362 %type <scm> tempo_event
363
364 %type <outputdef> output_def_body
365 %type <outputdef> output_def_head
366 %type <outputdef> output_def_head_with_mode_switch
367 %type <outputdef> output_def
368 %type <outputdef> paper_block
369
370 %type <scm> generic_prefix_music_scm
371 %type <scm> music_list
372 %type <scm> absolute_pitch
373 %type <scm> assignment_id
374 %type <scm> bare_number
375 %type <scm> unsigned_number
376 %type <scm> bass_figure
377 %type <scm> figured_bass_modification
378 %type <scm> br_bass_figure
379 %type <scm> bass_number
380 %type <scm> chord_body_elements
381 %type <scm> chord_item
382 %type <scm> chord_items
383 %type <scm> chord_separator
384 %type <scm> context_def_mod
385 %type <scm> context_def_spec_block
386 %type <scm> context_def_spec_body
387 %type <scm> context_mod
388 %type <scm> context_mod_list
389 %type <scm> context_prop_spec
390 %type <scm> direction_less_char
391 %type <scm> duration_length
392 %type <scm> embedded_scm
393 %type <scm> embedded_scm_bare
394 %type <scm> embedded_scm_closed
395 %type <scm> embedded_scm_chord_body
396 %type <scm> embedded_scm_event
397 %type <scm> event_function_event
398 %type <scm> figure_list
399 %type <scm> figure_spec
400 %type <scm> fraction
401 %type <scm> full_markup
402 %type <scm> full_markup_list
403 %type <scm> function_arglist
404 %type <scm> function_arglist_bare
405 %type <scm> function_arglist_closed
406 %type <scm> identifier_init
407 %type <scm> lilypond
408 %type <scm> lilypond_header
409 %type <scm> lilypond_header_body
410 %type <scm> lyric_element
411 %type <scm> lyric_markup
412 %type <scm> markup
413 %type <scm> markup_braced_list
414 %type <scm> markup_braced_list_body
415 %type <scm> markup_composed_list
416 %type <scm> markup_command_list
417 %type <scm> markup_command_list_arguments
418 %type <scm> markup_command_basic_arguments
419 %type <scm> markup_head_1_item
420 %type <scm> markup_head_1_list
421 %type <scm> markup_list
422 %type <scm> markup_top
423 %type <scm> mode_changing_head
424 %type <scm> mode_changing_head_with_context
425 %type <scm> multiplied_duration
426 %type <scm> music_function_event
427 %type <scm> music_function_event_arglist
428 %type <scm> music_function_chord_body
429 %type <scm> music_function_chord_body_arglist
430 %type <scm> new_chord
431 %type <scm> new_lyrics
432 %type <scm> number_expression
433 %type <scm> number_factor
434 %type <scm> number_term
435 %type <scm> octave_check
436 %type <scm> optional_context_mod
437 %type <scm> optional_id
438 %type <scm> optional_notemode_duration
439 %type <scm> pitch
440 %type <scm> pitch_also_in_chords
441 %type <scm> post_events
442 %type <scm> property_operation
443 %type <scm> property_path property_path_revved
444 %type <scm> scalar
445 %type <scm> scalar_bare
446 %type <scm> scalar_closed
447 %type <scm> scm_function_call
448 %type <scm> scm_function_call_closed
449 %type <scm> script_abbreviation
450 %type <scm> simple_chord_elements
451 %type <scm> simple_markup
452 %type <scm> simple_string
453 %type <scm> steno_duration
454 %type <scm> steno_pitch
455 %type <scm> steno_tonic_pitch
456 %type <scm> step_number
457 %type <scm> step_numbers
458 %type <scm> string
459 %type <scm> tempo_range
460
461 %type <score> score_block
462 %type <score> score_body
463
464
465 %left '-' '+'
466
467 /* We don't assign precedence to / and *, because we might need varied
468 prec levels in different prods */
469
470 %left UNARY_MINUS
471
472 %%
473
474 start_symbol:
475         lilypond
476         | EMBEDDED_LILY {
477                 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
478                 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
479         } embedded_lilypond {
480                 PARSER->lexer_->pop_state ();
481                 PARSER->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
482         }
483         ;
484
485 lilypond:       /* empty */ { }
486         | lilypond toplevel_expression {
487         }
488         | lilypond assignment {
489         }
490         | lilypond error {
491                 PARSER->error_level_ = 1;
492         }
493         | lilypond INVALID      {
494                 PARSER->error_level_ = 1;
495         }
496         ;
497
498
499 toplevel_expression:
500         lilypond_header {
501                 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
502         }
503         | book_block {
504                 Book *book = $1;
505                 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
506                 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
507                 book->unprotect ();
508         }
509         | bookpart_block {
510                 Book *bookpart = $1;
511                 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
512                 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
513                 bookpart->unprotect ();
514         }
515         | score_block {
516                 Score *score = $1;
517
518                 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
519                 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
520                 score->unprotect ();
521         }
522         | composite_music {
523                 Music *music = unsmob_music ($1);
524                 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
525                 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
526         }
527         | full_markup {
528                 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
529                 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
530         }
531         | full_markup_list {
532                 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
533                 scm_call_2 (proc, PARSER->self_scm (), $1);
534         }
535         | output_def {
536                 SCM id = SCM_EOL;
537                 Output_def * od = $1;
538
539                 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
540                         id = ly_symbol2scm ("$defaultpaper");
541                 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
542                         id = ly_symbol2scm ("$defaultmidi");
543                 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
544                         id = ly_symbol2scm ("$defaultlayout");
545
546                 PARSER->lexer_->set_identifier (id, od->self_scm ());
547                 od->unprotect();
548         }
549         ;
550
551 embedded_scm_bare:
552         SCM_TOKEN
553         | SCM_IDENTIFIER
554         ;
555
556 /* The generic version may end in music, or not */
557
558 embedded_scm:
559         embedded_scm_bare
560         | scm_function_call
561         ;
562
563 scm_function_call:
564         SCM_FUNCTION function_arglist {
565                 $$ = run_music_function (PARSER, @$,
566                                          $1, $2);
567         }
568         ;
569
570 embedded_lilypond:
571         { $$ = MAKE_SYNTAX ("void-music", @$, SCM_UNDEFINED); }
572         | identifier_init
573         | music music music_list {
574                 $$ = MAKE_SYNTAX ("sequential-music", @$,       
575                                   scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
576         }
577         | error {
578                 PARSER->error_level_ = 1;
579         }
580         | INVALID embedded_lilypond {
581                 PARSER->error_level_ = 1;
582         }
583         ;
584
585
586 lilypond_header_body:
587         {
588                 $$ = get_header (PARSER);
589                 PARSER->lexer_->add_scope ($$);
590         }
591         | lilypond_header_body assignment  {
592
593         }
594         ;
595
596 lilypond_header:
597         HEADER '{' lilypond_header_body '}'     {
598                 $$ = PARSER->lexer_->remove_scope ();
599         }
600         ;
601
602 /*
603         DECLARATIONS
604 */
605 assignment_id:
606         STRING          { $$ = $1; }
607         | LYRICS_STRING { $$ = $1; }
608         ;
609
610 assignment:
611         assignment_id '=' identifier_init  {
612                 PARSER->lexer_->set_identifier ($1, $3);
613         }
614         | assignment_id property_path '=' identifier_init {
615                 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
616                 PARSER->lexer_->set_identifier (path, $4);
617         ;
618 /*
619  TODO: devise standard for protection in parser.
620
621   The parser stack lives on the C-stack, which means that
622 all objects can be unprotected as soon as they're here.
623
624 */
625         }
626         | embedded_scm { }
627         ;
628
629
630 identifier_init:
631         score_block {
632                 $$ = $1->self_scm ();
633                 $1->unprotect ();
634         }
635         | book_block {
636                 $$ = $1->self_scm ();
637                 $1->unprotect ();
638         }
639         | bookpart_block {
640                 $$ = $1->self_scm ();
641                 $1->unprotect ();
642         }
643         | output_def {
644                 $$ = $1->self_scm ();
645                 $1->unprotect ();
646         }
647         | context_def_spec_block {
648                 $$ = $1;
649         }
650         | music  {
651                 /* Hack: Create event-chord around standalone events.
652                    Prevents the identifier from being interpreted as a post-event. */
653                 Music *mus = unsmob_music ($1);
654                 bool is_event = mus &&
655                         (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
656                                 != SCM_BOOL_F);
657                 if (!is_event)
658                         $$ = $1;
659                 else
660                         $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
661         }
662         | post_event_nofinger {
663                 $$ = $1;
664         }
665         | number_expression {
666                 $$ = $1;
667         }
668         | string {
669                 $$ = $1;
670         }
671         | embedded_scm {
672                 $$ = $1;
673         }
674         | full_markup {
675                 $$ = $1;
676         }
677         | full_markup_list {
678                 $$ = $1;
679         }
680         | context_modification {
681                 $$ = $1;
682         }
683         ;
684
685 context_def_spec_block:
686         CONTEXT '{' context_def_spec_body '}'
687                 {
688                 $$ = $3;
689         }
690         ;
691
692 context_def_spec_body:
693         /**/ {
694                 $$ = Context_def::make_scm ();
695                 unsmob_context_def ($$)->origin ()->set_spot (@$);
696         }
697         | CONTEXT_DEF_IDENTIFIER {
698                 $$ = $1;
699                 unsmob_context_def ($$)->origin ()->set_spot (@$);
700         }
701         | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
702                 Context_def*td = unsmob_context_def ($$);
703
704                 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
705                         SCM tag = scm_caar (p);
706
707                         /* TODO: should make new tag "grob-definition" ? */
708                         td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
709                                                         tag, scm_cons (scm_cdar (p), SCM_EOL)));
710                 }
711         }
712         | context_def_spec_body context_mod {
713                 unsmob_context_def ($$)->add_context_mod ($2);
714         }
715         | context_def_spec_body context_modification {
716                 Context_def *td = unsmob_context_def ($$);
717                 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
718                 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
719                     td->add_context_mod (scm_car (m));
720                 }
721         }
722         ;
723
724
725
726 book_block:
727         BOOK '{' book_body '}'  {
728                 $$ = $3;
729                 pop_paper (PARSER);
730                 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
731         }
732         ;
733
734 /* FIXME:
735    * Use 'handlers' like for toplevel-* stuff?
736    * grok \layout and \midi?  */
737 book_body:
738         {
739                 $$ = new Book;
740                 init_papers (PARSER);
741                 $$->origin ()->set_spot (@$);
742                 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
743                 $$->paper_->unprotect ();
744                 push_paper (PARSER, $$->paper_);
745                 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
746                 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
747                 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
748                 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
749         }
750         | BOOK_IDENTIFIER {
751                 $$ = unsmob_book ($1);
752                 $$->protect ();
753                 $$->origin ()->set_spot (@$);
754                 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
755         }
756         | book_body paper_block {
757                 $$->paper_ = $2;
758                 $2->unprotect ();
759                 set_paper (PARSER, $2);
760         }
761         | book_body bookpart_block {
762                 Book *bookpart = $2;
763                 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
764                 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
765                 bookpart->unprotect ();
766         }
767         | book_body score_block {
768                 Score *score = $2;
769                 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
770                 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
771                 score->unprotect ();
772         }
773         | book_body composite_music {
774                 Music *music = unsmob_music ($2);
775                 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
776                 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
777         }
778         | book_body full_markup {
779                 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
780                 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
781         }
782         | book_body full_markup_list {
783                 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
784                 scm_call_2 (proc, $$->self_scm (), $2);
785         }
786         | book_body lilypond_header {
787                 $$->header_ = $2;
788         }
789         | book_body embedded_scm { }
790         | book_body error {
791                 $$->paper_ = 0;
792                 $$->scores_ = SCM_EOL;
793                 $$->bookparts_ = SCM_EOL;
794         }
795         ;
796
797 bookpart_block:
798         BOOKPART '{' bookpart_body '}' {
799                 $$ = $3;
800                 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
801         }
802         ;
803
804 bookpart_body:
805         {
806                 $$ = new Book;
807                 $$->origin ()->set_spot (@$);
808                 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
809         }
810         | BOOK_IDENTIFIER {
811                 $$ = unsmob_book ($1);
812                 $$->protect ();
813                 $$->origin ()->set_spot (@$);
814                 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
815         }
816         | bookpart_body paper_block {
817                 $$->paper_ = $2;
818                 $2->unprotect ();
819         }
820         | bookpart_body score_block {
821                 Score *score = $2;
822                 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
823                 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
824                 score->unprotect ();
825         }
826         | bookpart_body composite_music {
827                 Music *music = unsmob_music ($2);
828                 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
829                 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
830         }
831         | bookpart_body full_markup {
832                 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
833                 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
834         }
835         | bookpart_body full_markup_list {
836                 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
837                 scm_call_2 (proc, $$->self_scm (), $2);
838         }
839         | bookpart_body lilypond_header {
840                 $$->header_ = $2;
841         }
842         | bookpart_body embedded_scm { }
843         | bookpart_body error {
844                 $$->paper_ = 0;
845                 $$->scores_ = SCM_EOL;
846         }
847         ;
848
849 score_block:
850         SCORE '{' score_body '}'        {
851                 $$ = $3;
852         }
853         ;
854
855 score_body:
856         music {
857                 SCM m = $1;
858                 SCM scorify = ly_lily_module_constant ("scorify-music");
859                 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
860
861                 // pass ownernship to C++ again.
862                 $$ = unsmob_score (score);
863                 $$->protect ();
864                 $$->origin ()->set_spot (@$);
865         }
866         | SCORE_IDENTIFIER {
867                 $$ = unsmob_score ($1);
868                 $$->protect ();
869                 $$->origin ()->set_spot (@$);
870         }
871         | score_body lilypond_header    {
872                 $$->set_header ($2);
873         }
874         | score_body output_def {
875                 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
876                 {
877                         PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
878
879                 }
880                 else
881                 {
882                         $$->add_output_def ($2);
883                 }
884                 $2->unprotect ();
885         }
886         | score_body error {
887                 $$->error_found_ = true;
888         }
889         ;
890
891
892 /*
893         OUTPUT DEF
894 */
895
896 paper_block:
897         output_def {
898                 $$ = $1;
899                 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
900                 {
901                         PARSER->parser_error (@1, _ ("need \\paper for paper block"));
902                         $1->unprotect ();
903                         $$ = get_paper (PARSER);
904                 }
905         }
906         ;
907
908
909 output_def:
910         output_def_body '}' {
911                 $$ = $1;
912
913                 PARSER->lexer_->remove_scope ();
914                 PARSER->lexer_->pop_state ();
915         }
916         ;
917
918 output_def_head:
919         PAPER {
920                 $$ = get_paper (PARSER);
921                 $$->input_origin_ = @$;
922                 PARSER->lexer_->add_scope ($$->scope_);
923         }
924         | MIDI    {
925                 Output_def *p = get_midi (PARSER);
926                 $$ = p;
927                 PARSER->lexer_->add_scope (p->scope_);
928         }
929         | LAYOUT        {
930                 Output_def *p = get_layout (PARSER);
931
932                 PARSER->lexer_->add_scope (p->scope_);
933                 $$ = p;
934         }
935         ;
936
937 output_def_head_with_mode_switch:
938         output_def_head {
939                 PARSER->lexer_->push_initial_state ();
940                 $$ = $1;
941         }
942         ;
943
944 output_def_body:
945         output_def_head_with_mode_switch '{' {
946                 $$ = $1;
947                 $$->input_origin_.set_spot (@$);
948         }
949         | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER    {
950                 $1->unprotect ();
951
952                 Output_def *o = unsmob_output_def ($3);
953                 o->input_origin_.set_spot (@$);
954                 $$ = o;
955                 $$->protect ();
956                 PARSER->lexer_->remove_scope ();
957                 PARSER->lexer_->add_scope (o->scope_);
958         }
959         | output_def_body assignment  {
960
961         }
962         | output_def_body context_def_spec_block        {
963                 assign_context_def ($$, $2);
964         }
965         | output_def_body error {
966
967         }
968         ;
969
970 tempo_event:
971         TEMPO steno_duration '=' tempo_range    {
972                 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
973         }
974         | TEMPO scalar_closed steno_duration '=' tempo_range    {
975                 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
976         }
977         | TEMPO scalar {
978                 $$ = MAKE_SYNTAX ("tempo", @$, $2);
979         }
980         ;
981
982 /*
983 The representation of a  list is reversed to have efficient append.  */
984
985 music_list:
986         /* empty */ {
987                 $$ = SCM_EOL;
988         }
989         | music_list music {
990                 $$ = scm_cons ($2, $1);
991         }
992         | music_list embedded_scm {
993
994         }
995         | music_list error {
996                 Music *m = MY_MAKE_MUSIC("Music", @$);
997                 // ugh. code dup
998                 m->set_property ("error-found", SCM_BOOL_T);
999                 $$ = scm_cons (m->self_scm (), $1);
1000                 m->unprotect (); /* UGH */
1001         }
1002         ;
1003
1004 braced_music_list:
1005         '{' music_list '}'
1006         {
1007                 $$ = scm_reverse_x ($2, SCM_EOL);
1008         }
1009         ;
1010
1011 music:
1012         simple_music
1013         | composite_music
1014         | MUSIC_IDENTIFIER
1015         ;
1016
1017
1018 repeated_music:
1019         REPEAT simple_string unsigned_number music
1020         {
1021                 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1022         }
1023         | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1024         {
1025                 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1026         }
1027         ;
1028
1029 sequential_music:
1030         SEQUENTIAL braced_music_list {
1031                 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1032         }
1033         | braced_music_list {
1034                 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1035         }
1036         ;
1037
1038 simultaneous_music:
1039         SIMULTANEOUS braced_music_list {
1040                 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1041         }
1042         | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE       {
1043                 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1044         }
1045         ;
1046
1047 simple_music:
1048         event_chord
1049         | music_property_def
1050         | context_change
1051         ;
1052
1053 context_modification:
1054         WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1055         {
1056                 PARSER->lexer_->pop_state ();
1057                 $$ = $4;
1058         }
1059         | WITH CONTEXT_MOD_IDENTIFIER
1060         {
1061                 $$ = $2;
1062         }
1063         | CONTEXT_MOD_IDENTIFIER
1064         {
1065                 $$ = $1;
1066         }
1067         ;
1068
1069 optional_context_mod:
1070         /**/ {
1071             $$ = SCM_EOL;
1072         }
1073         | context_modification
1074         {
1075               $$ = $1;
1076         }
1077         ;
1078
1079 context_mod_list:
1080         /**/ {
1081             $$ = Context_mod ().smobbed_copy ();
1082         }
1083         | context_mod_list context_mod  {
1084                  unsmob_context_mod ($1)->add_context_mod ($2);
1085         }
1086         | context_mod_list CONTEXT_MOD_IDENTIFIER {
1087                  Context_mod *md = unsmob_context_mod ($2);
1088                  if (md)
1089                      unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1090         }
1091         ;
1092
1093 composite_music:
1094         prefix_composite_music { $$ = $1; }
1095         | grouped_music_list { $$ = $1; }
1096         ;
1097
1098 /* Music that can't be followed by additional events or durations */
1099 closed_music:
1100         MUSIC_IDENTIFIER
1101         | grouped_music_list
1102         ;
1103
1104 grouped_music_list:
1105         simultaneous_music              { $$ = $1; }
1106         | sequential_music              { $$ = $1; }
1107         ;
1108
1109 /* An argument list. If a function \foo expects scm scm music, then the lexer expands \foo into the token sequence:
1110  MUSIC_FUNCTION EXPECT_MUSIC EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1111 and this rule returns the reversed list of arguments. */
1112
1113
1114 function_arglist:
1115         function_arglist_bare
1116         | EXPECT_MUSIC function_arglist music {
1117                 $$ = scm_cons ($3, $2);
1118         }
1119         | EXPECT_SCM function_arglist embedded_scm {
1120                 $$ = scm_cons ($3, $2);
1121         }
1122         ;
1123
1124 function_arglist_closed:
1125         function_arglist_bare
1126         | EXPECT_MUSIC function_arglist closed_music {
1127                 $$ = scm_cons ($3, $2);
1128         }
1129         | EXPECT_SCM function_arglist embedded_scm_closed {
1130                 $$ = scm_cons ($3, $2);
1131         }
1132         ;
1133
1134 embedded_scm_closed:
1135         embedded_scm_bare
1136         | scm_function_call_closed
1137         ;
1138
1139 scm_function_call_closed:
1140         SCM_FUNCTION function_arglist_closed {
1141                 $$ = run_music_function (PARSER, @$,
1142                                          $1, $2);
1143         }
1144         ;
1145
1146 function_arglist_bare:
1147         EXPECT_NO_MORE_ARGS {
1148                 /* This is for 0-ary functions, so they don't need to
1149                    read a lookahead token */
1150                 $$ = SCM_EOL;
1151         }
1152         | EXPECT_MARKUP function_arglist full_markup {
1153                 $$ = scm_cons ($3, $2);
1154         }
1155         | EXPECT_MARKUP function_arglist simple_string {
1156                 $$ = scm_cons ($3, $2);
1157         }
1158         | EXPECT_PITCH function_arglist pitch_also_in_chords {
1159                 $$ = scm_cons ($3, $2);
1160         }
1161         | EXPECT_DURATION function_arglist_closed duration_length {
1162                 $$ = scm_cons ($3, $2);
1163         }
1164         | EXPECT_SCM function_arglist simple_string {
1165                 $$ = scm_cons ($3, $2);
1166         }
1167         ;
1168
1169 generic_prefix_music_scm:
1170         MUSIC_FUNCTION function_arglist {
1171                 $$ = run_music_function (PARSER, @$,
1172                                          $1, $2);
1173         }
1174         ;
1175
1176
1177 optional_id:
1178         /**/ { $$ = SCM_EOL; }
1179         | '=' simple_string {
1180                 $$ = $2;
1181         }
1182         ;
1183
1184
1185 prefix_composite_music:
1186         generic_prefix_music_scm
1187         | CONTEXT simple_string optional_id optional_context_mod music {
1188                 Context_mod *ctxmod = unsmob_context_mod ($4);
1189                 SCM mods = SCM_EOL;
1190                 if (ctxmod)
1191                         mods = ctxmod->get_mods ();
1192                 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, mods, SCM_BOOL_F);
1193         }
1194         | NEWCONTEXT simple_string optional_id optional_context_mod music {
1195                 Context_mod *ctxmod = unsmob_context_mod ($4);
1196                 SCM mods = SCM_EOL;
1197                 if (ctxmod)
1198                         mods = ctxmod->get_mods ();
1199                 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, mods, SCM_BOOL_T);
1200         }
1201
1202         | TIMES fraction music {
1203                 $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3);
1204         }
1205         | repeated_music                { $$ = $1; }
1206         | mode_changing_head grouped_music_list {
1207                 if ($1 == ly_symbol2scm ("chords"))
1208                 {
1209                   $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1210                 }
1211                 else
1212                 {
1213                   $$ = $2;
1214                 }
1215                 PARSER->lexer_->pop_state ();
1216         }
1217         | mode_changing_head_with_context optional_context_mod grouped_music_list {
1218                 Context_mod *ctxmod = unsmob_context_mod ($2);
1219                 SCM mods = SCM_EOL;
1220                 if (ctxmod)
1221                         mods = ctxmod->get_mods ();
1222                 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, $3, mods, SCM_BOOL_T);
1223                 if ($1 == ly_symbol2scm ("ChordNames"))
1224                 {
1225                   $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1226                 }
1227                 PARSER->lexer_->pop_state ();
1228         }
1229         | relative_music        { $$ = $1; }
1230         | re_rhythmed_music     { $$ = $1; }
1231         ;
1232
1233 mode_changing_head:
1234         NOTEMODE {
1235                 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1236                 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1237
1238                 $$ = ly_symbol2scm ("notes");
1239         }
1240         | DRUMMODE
1241                 {
1242                 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1243                 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1244
1245                 $$ = ly_symbol2scm ("drums");
1246         }
1247         | FIGUREMODE {
1248                 PARSER->lexer_->push_figuredbass_state ();
1249
1250                 $$ = ly_symbol2scm ("figures");
1251         }
1252         | CHORDMODE {
1253                 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1254                 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1255                 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1256                 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1257                 $$ = ly_symbol2scm ("chords");
1258
1259         }
1260         | LYRICMODE
1261                 { PARSER->lexer_->push_lyric_state ();
1262                 $$ = ly_symbol2scm ("lyrics");
1263         }
1264         ;
1265
1266 mode_changing_head_with_context:
1267         DRUMS {
1268                 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1269                 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1270
1271                 $$ = ly_symbol2scm ("DrumStaff");
1272         }
1273         | FIGURES {
1274                 PARSER->lexer_->push_figuredbass_state ();
1275
1276                 $$ = ly_symbol2scm ("FiguredBass");
1277         }
1278         | CHORDS {
1279                 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1280                 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1281                 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1282                 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1283                 $$ = ly_symbol2scm ("ChordNames");
1284         }
1285         | LYRICS
1286                 { PARSER->lexer_->push_lyric_state ();
1287                 $$ = ly_symbol2scm ("Lyrics");
1288         }
1289         ;
1290
1291
1292 relative_music:
1293         RELATIVE absolute_pitch music {
1294                 Pitch start = *unsmob_pitch ($2);
1295                 $$ = make_music_relative (start, $3, @$);
1296         }
1297         | RELATIVE composite_music {
1298                 Pitch middle_c (0, 0, 0);
1299                 $$ = make_music_relative (middle_c, $2, @$);
1300         }
1301         ;
1302
1303 new_lyrics:
1304         ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1305         /*cont */
1306         closed_music {
1307         /* Can also use music at the expensive of two S/Rs similar to
1308            \repeat \alternative */
1309                 PARSER->lexer_->pop_state ();
1310
1311                 $$ = scm_cons ($3, SCM_EOL);
1312         }
1313         | new_lyrics ADDLYRICS {
1314                 PARSER->lexer_->push_lyric_state ();
1315         } closed_music {
1316                 PARSER->lexer_->pop_state ();
1317                 $$ = scm_cons ($4, $1);
1318         }
1319         ;
1320
1321 re_rhythmed_music:
1322         closed_music new_lyrics {
1323                 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1324         }
1325         | LYRICSTO simple_string {
1326                 PARSER->lexer_->push_lyric_state ();
1327         } music {
1328                 PARSER->lexer_->pop_state ();
1329                 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1330         }
1331         ;
1332
1333 context_change:
1334         CHANGE STRING '=' STRING  {
1335                 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1336         }
1337         ;
1338
1339
1340 property_path_revved:
1341         embedded_scm_closed {
1342                 $$ = scm_cons ($1, SCM_EOL);
1343         }
1344         | property_path_revved embedded_scm_closed {
1345                 $$ = scm_cons ($2, $1);
1346         }
1347         ;
1348
1349 property_path:
1350         property_path_revved  {
1351                 $$ = scm_reverse_x ($1, SCM_EOL);
1352         }
1353         ;
1354
1355 property_operation:
1356         STRING '=' scalar {
1357                 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1358                         scm_string_to_symbol ($1), $3);
1359         }
1360         | UNSET simple_string {
1361                 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1362                         scm_string_to_symbol ($2));
1363         }
1364         | OVERRIDE simple_string property_path '=' scalar {
1365                 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1366                                                         scm_string_to_symbol ($2), $5),
1367                                              $3));
1368         }
1369         | REVERT simple_string embedded_scm {
1370                 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1371                         scm_string_to_symbol ($2), $3);
1372         }
1373         ;
1374
1375 context_def_mod:
1376         CONSISTS { $$ = ly_symbol2scm ("consists"); }
1377         | REMOVE { $$ = ly_symbol2scm ("remove"); }
1378
1379         | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1380         | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1381         | DENIES { $$ = ly_symbol2scm ("denies"); }
1382
1383         | ALIAS { $$ = ly_symbol2scm ("alias"); }
1384         | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1385         | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1386         | NAME { $$ = ly_symbol2scm ("context-name"); }
1387         ;
1388
1389 context_mod:
1390         property_operation { $$ = $1; }
1391         | context_def_mod STRING {
1392                 $$ = scm_list_2 ($1, $2);
1393         }
1394         | context_def_mod embedded_scm {
1395            if (ly_symbol2scm ("consists") != $1)
1396            {
1397              $$ = SCM_EOL;
1398              PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1399            }
1400            else
1401            {
1402              $$ = scm_list_2 ($1, $2);
1403            }
1404         }
1405         ;
1406
1407 context_prop_spec:
1408         simple_string {
1409                 if (!is_regular_identifier ($1))
1410                 {
1411                         @$.error (_("Grob name should be alphanumeric"));
1412                 }
1413
1414                 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1415                         scm_string_to_symbol ($1));
1416         }
1417         | simple_string '.' simple_string {
1418                 $$ = scm_list_2 (scm_string_to_symbol ($1),
1419                         scm_string_to_symbol ($3));
1420         }
1421         ;
1422
1423 simple_music_property_def:
1424         OVERRIDE context_prop_spec property_path '=' scalar {
1425                 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1426                                 ly_symbol2scm ("OverrideProperty"),
1427                                 scm_cadr ($2),
1428                                 $5, SCM_UNDEFINED),
1429                                 $3));
1430         }
1431         | REVERT context_prop_spec embedded_scm {
1432                 $$ = scm_list_4 (scm_car ($2),
1433                         ly_symbol2scm ("RevertProperty"),
1434                         scm_cadr ($2),
1435                         $3);
1436         }
1437         | SET context_prop_spec '=' scalar {
1438                 $$ = scm_list_4 (scm_car ($2),
1439                         ly_symbol2scm ("PropertySet"),
1440                         scm_cadr ($2),
1441                         $4);
1442         }
1443         | UNSET context_prop_spec {
1444                 $$ = scm_list_3 (scm_car ($2),
1445                         ly_symbol2scm ("PropertyUnset"),
1446                         scm_cadr ($2));
1447         }
1448         ;
1449
1450 music_property_def:
1451         simple_music_property_def {
1452                 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1453         }
1454         | ONCE simple_music_property_def {
1455                 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1456         }
1457         ;
1458
1459 string:
1460         STRING {
1461                 $$ = $1;
1462         }
1463         | STRING_IDENTIFIER {
1464                 $$ = $1;
1465         }
1466         | string '+' string {
1467                 $$ = scm_string_append (scm_list_2 ($1, $3));
1468         }
1469         ;
1470
1471 simple_string: STRING {
1472                 $$ = $1;
1473         }
1474         | LYRICS_STRING {
1475                 $$ = $1;
1476         }
1477         | STRING_IDENTIFIER {
1478                 $$ = $1;
1479         }
1480         ;
1481
1482 scalar_bare:
1483         string {
1484                 $$ = $1;
1485         }
1486         | lyric_element {
1487                 $$ = $1;
1488         }
1489         | bare_number {
1490                 $$ = $1;
1491         }
1492         | embedded_scm_bare {
1493                 $$ = $1;
1494         }
1495         | full_markup {
1496                 $$ = $1;
1497         }
1498         ;
1499
1500 scalar:
1501         scalar_bare |
1502         scm_function_call
1503         ;
1504
1505 scalar_closed:
1506         scalar_bare |
1507         scm_function_call_closed
1508         ;
1509
1510
1511 event_chord:
1512         /* TODO: Create a special case that avoids the creation of
1513            EventChords around simple_elements that have no post_events?
1514          */
1515         simple_chord_elements post_events       {
1516                 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1517
1518                 Input i;
1519                 /* why is this giving wrong start location? -ns
1520                  * i = @$; */
1521                 i.set_location (@1, @2);
1522                 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1523         }
1524         | CHORD_REPETITION optional_notemode_duration post_events {
1525                 Input i;
1526                 i.set_location (@1, @3);
1527                 $$ = MAKE_SYNTAX ("repetition-chord", i,
1528                                   PARSER->lexer_->chord_repetition_.last_chord_,
1529                                   PARSER->lexer_->chord_repetition_.repetition_function_,
1530                                   $2, scm_reverse_x ($3, SCM_EOL));
1531         }
1532         | MULTI_MEASURE_REST optional_notemode_duration post_events {
1533                 Input i;
1534                 i.set_location (@1, @3);
1535                 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1536                                   scm_reverse_x ($3, SCM_EOL));
1537         }
1538         | command_element
1539         /* note chord elements are memorized into
1540            PARSER->lexer_->chord_repetition_ so that the chord repetition
1541            mechanism copy them when a chord repetition symbol is found
1542         */
1543         | note_chord_element    {
1544                 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
1545         }
1546         ;
1547
1548
1549 note_chord_element:
1550         chord_body optional_notemode_duration post_events
1551         {
1552                 Music *m = unsmob_music ($1);
1553                 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1554                 SCM es = m->get_property ("elements");
1555                 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1556
1557                 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1558                   unsmob_music (scm_car (s))->set_property ("duration", dur);
1559                 es = ly_append2 (es, postevs);
1560
1561                 m-> set_property ("elements", es);
1562                 m->set_spot (@$);
1563                 $$ = m->self_scm ();
1564         }
1565         ;
1566
1567 chord_body:
1568         ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1569         {
1570                 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1571         }
1572         ;
1573
1574 chord_body_elements:
1575         /* empty */             { $$ = SCM_EOL; }
1576         | chord_body_elements chord_body_element {
1577                 $$ = scm_cons ($2, $1);
1578         }
1579         ;
1580
1581 chord_body_element:
1582         pitch exclamations questions octave_check post_events
1583         {
1584                 int q = $3;
1585                 int ex = $2;
1586                 SCM check = $4;
1587                 SCM post = $5;
1588
1589                 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1590                 n->set_property ("pitch", $1);
1591                 if (q % 2)
1592                         n->set_property ("cautionary", SCM_BOOL_T);
1593                 if (ex % 2 || q % 2)
1594                         n->set_property ("force-accidental", SCM_BOOL_T);
1595
1596                 if (scm_is_pair (post)) {
1597                         SCM arts = scm_reverse_x (post, SCM_EOL);
1598                         n->set_property ("articulations", arts);
1599                 }
1600                 if (scm_is_number (check))
1601                 {
1602                         int q = scm_to_int (check);
1603                         n->set_property ("absolute-octave", scm_from_int (q-1));
1604                 }
1605
1606                 $$ = n->unprotect ();
1607         }
1608         | DRUM_PITCH post_events {
1609                 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1610                 n->set_property ("drum-type", $1);
1611
1612                 if (scm_is_pair ($2)) {
1613                         SCM arts = scm_reverse_x ($2, SCM_EOL);
1614                         n->set_property ("articulations", arts);
1615                 }
1616                 $$ = n->unprotect ();
1617         }
1618         | music_function_chord_body
1619         ;
1620
1621 /* We can't accept a music argument, not even a closed one,
1622  * immediately before chord_body_elements, otherwise a function \fun
1623  * with a signature of two music arguments can't be sorted out
1624  * properly in a construct like
1625  * <\fun { c } \fun { c } c>
1626  * The second call could be interpreted either as a chord constituent
1627  * or a music expression.
1628  */
1629
1630 music_function_chord_body_arglist:
1631         function_arglist_bare
1632         | EXPECT_MUSIC music_function_chord_body_arglist chord_body_element {
1633                 $$ = scm_cons ($3, $2);
1634         }
1635         | EXPECT_SCM function_arglist embedded_scm_chord_body {
1636                 $$ = scm_cons ($3, $2);
1637         }
1638         ;
1639
1640 embedded_scm_chord_body:
1641         embedded_scm_bare
1642         | SCM_FUNCTION music_function_chord_body_arglist {
1643                 $$ = run_music_function (PARSER, @$,
1644                                          $1, $2);
1645         }
1646         ;
1647
1648 music_function_chord_body:
1649         MUSIC_FUNCTION music_function_chord_body_arglist {
1650                 $$ = run_music_function (PARSER, @$,
1651                                          $1, $2);
1652         }
1653         ;
1654
1655 /* We could accept a closed music argument before the post events
1656  * indicated by a trailing argument list.  For symmetry with chord
1657  * bodies and in order to avoid too tricky and complex behavior, we
1658  * refrain from doing so.
1659  */
1660 music_function_event_arglist:
1661         function_arglist_bare
1662         | EXPECT_MUSIC music_function_event_arglist post_event {
1663                 $$ = scm_cons ($3, $2);
1664         }
1665         | EXPECT_SCM function_arglist embedded_scm_event {
1666                 $$ = scm_cons ($3, $2);
1667         }
1668         ;
1669
1670 embedded_scm_event:
1671         embedded_scm_bare
1672         | SCM_FUNCTION music_function_event_arglist {
1673                 $$ = run_music_function (PARSER, @$,
1674                                          $1, $2);
1675         }
1676         ;
1677
1678 music_function_event:
1679         MUSIC_FUNCTION music_function_event_arglist {
1680                 $$ = run_music_function (PARSER, @$,
1681                                          $1, $2);
1682         }
1683         ;
1684
1685 event_function_event:
1686         EVENT_FUNCTION music_function_event_arglist {
1687                 $$ = run_music_function (PARSER, @$,
1688                                          $1, $2);
1689         }
1690         ;
1691
1692 command_element:
1693         command_event {
1694                 $$ = $1;
1695         }
1696         | E_BRACKET_OPEN {
1697                 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1698                 m->set_property ("span-direction", scm_from_int (START));
1699                 $$ = m->unprotect();
1700         }
1701         | E_BRACKET_CLOSE {
1702                 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1703                 m->set_property ("span-direction", scm_from_int (STOP));
1704                 $$ = m->unprotect ();
1705         }
1706         | E_BACKSLASH {
1707                 $$ = MAKE_SYNTAX ("voice-separator", @$, SCM_UNDEFINED);
1708         }
1709         | '|'      {
1710                 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1711
1712                 Music *m = unsmob_music (pipe);
1713                 if (m)
1714                 {
1715                         m = m->clone ();
1716                         m->set_spot (@$);
1717                         $$ = m->unprotect ();
1718                 }
1719                 else
1720                         $$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
1721
1722         }
1723         | TIME_T fraction  {
1724                 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1725
1726                 $$ = scm_apply_2   (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1727         }
1728         | MARK scalar {
1729                 $$ = MAKE_SYNTAX ("make-mark-set", @$, $2);
1730         }
1731         ;
1732
1733 command_event:
1734         E_TILDE {
1735                 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
1736         }
1737         | MARK DEFAULT  {
1738                 Music *m = MY_MAKE_MUSIC ("MarkEvent", @$);
1739                 $$ = m->unprotect ();
1740         }
1741         | tempo_event {
1742                 $$ = $1;
1743         }
1744         | KEY DEFAULT {
1745                 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1746                 $$ = key->unprotect ();
1747         }
1748         | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
1749
1750                 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1751                 if (scm_ilength ($3) > 0)
1752                 {
1753                         key->set_property ("pitch-alist", $3);
1754                         key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1755                         key->transpose (* unsmob_pitch ($2));
1756                 } else {
1757                         PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1758                 }
1759
1760                 $$ = key->unprotect ();
1761         }
1762         ;
1763
1764
1765 post_events:
1766         /* empty */ {
1767                 $$ = SCM_EOL;
1768         }
1769         | post_events post_event {
1770                 unsmob_music ($2)->set_spot (@2);
1771                 $$ = scm_cons ($2, $$);
1772         }
1773         ;
1774
1775 post_event_nofinger:
1776         direction_less_event {
1777                 $$ = $1;
1778         }
1779         | script_dir music_function_event {
1780                 $$ = $2;
1781                 if ($1)
1782                 {
1783                         unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
1784                 }
1785         }
1786         | HYPHEN {
1787                 if (!PARSER->lexer_->is_lyric_state ())
1788                         PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1789                 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
1790         }
1791         | EXTENDER {
1792                 if (!PARSER->lexer_->is_lyric_state ())
1793                         PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1794                 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
1795         }
1796         | script_dir direction_reqd_event {
1797                 if ($1)
1798                 {
1799                         Music *m = unsmob_music ($2);
1800                         m->set_property ("direction", scm_from_int ($1));
1801                 }
1802                 $$ = $2;
1803         }
1804         | script_dir direction_less_event {
1805                 if ($1)
1806                 {
1807                         Music *m = unsmob_music ($2);
1808                         m->set_property ("direction", scm_from_int ($1));
1809                 }
1810                 $$ = $2;
1811         }
1812         | string_number_event
1813         ;
1814
1815 post_event:
1816         post_event_nofinger
1817         | script_dir fingering {
1818                 if ($1)
1819                 {
1820                         Music *m = unsmob_music ($2);
1821                         m->set_property ("direction", scm_from_int ($1));
1822                 }
1823                 $$ = $2;
1824         }
1825         ;
1826
1827 string_number_event:
1828         E_UNSIGNED {
1829                 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
1830                 s->set_property ("string-number", scm_from_int ($1));
1831                 $$ = s->unprotect ();
1832         }
1833         ;
1834
1835 direction_less_char:
1836         '['  {
1837                 $$ = ly_symbol2scm ("bracketOpenSymbol");
1838         }
1839         | ']'  {
1840                 $$ = ly_symbol2scm ("bracketCloseSymbol");
1841         }
1842         | '~'  {
1843                 $$ = ly_symbol2scm ("tildeSymbol");
1844         }
1845         | '('  {
1846                 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1847         }
1848         | ')'  {
1849                 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1850         }
1851         | E_EXCLAMATION  {
1852                 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1853         }
1854         | E_OPEN  {
1855                 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1856         }
1857         | E_CLOSE  {
1858                 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1859         }
1860         | E_ANGLE_CLOSE  {
1861                 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1862         }
1863         | E_ANGLE_OPEN  {
1864                 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1865         }
1866         ;
1867
1868 direction_less_event:
1869         direction_less_char {
1870                 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
1871                 Music *m = 0;
1872                 if (unsmob_music (predefd))
1873                 {
1874                         m = unsmob_music (predefd)->clone ();
1875                         m->set_spot (@$);
1876                 }
1877                 else
1878                 {
1879                         m = MY_MAKE_MUSIC ("Music", @$);
1880                 }
1881                 $$ = m->unprotect ();
1882         }
1883         | EVENT_IDENTIFIER      {
1884                 $$ = $1;
1885         }
1886         | tremolo_type  {
1887                Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
1888                a->set_property ("tremolo-type", scm_from_int ($1));
1889                $$ = a->unprotect ();
1890         }
1891         | event_function_event  
1892         ;
1893
1894 direction_reqd_event:
1895         gen_text_def {
1896                 $$ = $1;
1897         }
1898         | script_abbreviation {
1899                 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1900                 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
1901                 if (scm_is_string (s))
1902                         a->set_property ("articulation-type", s);
1903                 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
1904                 $$ = a->unprotect ();
1905         }
1906         ;
1907
1908 octave_check:
1909         /**/ { $$ = SCM_EOL; }
1910         | '='  { $$ = scm_from_int (0); }
1911         | '=' sub_quotes { $$ = scm_from_int (-$2); }
1912         | '=' sup_quotes { $$ = scm_from_int ($2); }
1913         ;
1914
1915 sup_quotes:
1916         '\'' {
1917                 $$ = 1;
1918         }
1919         | sup_quotes '\'' {
1920                 $$ ++;
1921         }
1922         ;
1923
1924 sub_quotes:
1925         ',' {
1926                 $$ = 1;
1927         }
1928         | sub_quotes ',' {
1929                 $$++;
1930         }
1931         ;
1932
1933 steno_pitch:
1934         NOTENAME_PITCH  {
1935                 $$ = $1;
1936         }
1937         | NOTENAME_PITCH sup_quotes     {
1938                 Pitch p = *unsmob_pitch ($1);
1939                 p = p.transposed (Pitch ($2,0,0));
1940                 $$ = p.smobbed_copy ();
1941         }
1942         | NOTENAME_PITCH sub_quotes      {
1943                 Pitch p =* unsmob_pitch ($1);
1944                 p = p.transposed (Pitch (-$2,0,0));
1945                 $$ = p.smobbed_copy ();
1946         }
1947         ;
1948
1949 /*
1950 ugh. duplication
1951 */
1952
1953 steno_tonic_pitch:
1954         TONICNAME_PITCH {
1955                 $$ = $1;
1956         }
1957         | TONICNAME_PITCH sup_quotes    {
1958                 Pitch p = *unsmob_pitch ($1);
1959                 p = p.transposed (Pitch ($2,0,0));
1960                 $$ = p.smobbed_copy ();
1961         }
1962         | TONICNAME_PITCH sub_quotes     {
1963                 Pitch p = *unsmob_pitch ($1);
1964
1965                 p = p.transposed (Pitch (-$2,0,0));
1966                 $$ = p.smobbed_copy ();
1967         }
1968         ;
1969
1970 pitch:
1971         steno_pitch {
1972                 $$ = $1;
1973         }
1974         | PITCH_IDENTIFIER
1975         ;
1976
1977 pitch_also_in_chords:
1978         pitch
1979         | steno_tonic_pitch
1980         ;
1981
1982 gen_text_def:
1983         full_markup {
1984                 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1985                 t->set_property ("text", $1);
1986                 $$ = t->unprotect ();
1987         }
1988         | string {
1989                 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1990                 t->set_property ("text",
1991                         make_simple_markup ($1));
1992                 $$ = t->unprotect ();
1993         }
1994         ;
1995
1996 fingering:
1997         UNSIGNED {
1998                 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
1999                 t->set_property ("digit", scm_from_int ($1));
2000                 $$ = t->unprotect ();
2001         }
2002         ;
2003
2004 script_abbreviation:
2005         '^'             {
2006                 $$ = scm_from_locale_string ("Hat");
2007         }
2008         | '+'           {
2009                 $$ = scm_from_locale_string ("Plus");
2010         }
2011         | '-'           {
2012                 $$ = scm_from_locale_string ("Dash");
2013         }
2014         | '|'           {
2015                 $$ = scm_from_locale_string ("Bar");
2016         }
2017         | ANGLE_CLOSE   {
2018                 $$ = scm_from_locale_string ("Larger");
2019         }
2020         | '.'           {
2021                 $$ = scm_from_locale_string ("Dot");
2022         }
2023         | '_' {
2024                 $$ = scm_from_locale_string ("Underscore");
2025         }
2026         ;
2027
2028 script_dir:
2029         '_'     { $$ = DOWN; }
2030         | '^'   { $$ = UP; }
2031         | '-'   { $$ = CENTER; }
2032         ;
2033
2034
2035 absolute_pitch:
2036         pitch   {
2037                 $$ = $1;
2038         }
2039         ;
2040
2041 duration_length:
2042         multiplied_duration {
2043                 $$ = $1;
2044         }
2045         ;
2046
2047 optional_notemode_duration:
2048         {
2049                 Duration dd = PARSER->default_duration_;
2050                 $$ = dd.smobbed_copy ();
2051         }
2052         | multiplied_duration   {
2053                 $$ = $1;
2054                 PARSER->default_duration_ = *unsmob_duration ($$);
2055         }
2056         ;
2057
2058 steno_duration:
2059         bare_unsigned dots              {
2060                 int len = 0;
2061                 if (!is_duration ($1))
2062                         PARSER->parser_error (@1, _f ("not a duration: %d", $1));
2063                 else
2064                         len = intlog2 ($1);
2065
2066                 $$ = Duration (len, $2).smobbed_copy ();
2067         }
2068         | DURATION_IDENTIFIER dots      {
2069                 Duration *d = unsmob_duration ($1);
2070                 Duration k (d->duration_log (), d->dot_count () + $2);
2071                 k = k.compressed (d->factor ());
2072                 *d = k;
2073                 $$ = $1;
2074         }
2075         ;
2076
2077 multiplied_duration:
2078         steno_duration {
2079                 $$ = $1;
2080         }
2081         | multiplied_duration '*' bare_unsigned {
2082                 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2083         }
2084         | multiplied_duration '*' FRACTION {
2085                 Rational  m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2086
2087                 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2088         }
2089         ;
2090
2091 fraction:
2092         FRACTION { $$ = $1; }
2093         | UNSIGNED '/' UNSIGNED {
2094                 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2095         }
2096         ;
2097
2098 dots:
2099         /* empty */     {
2100                 $$ = 0;
2101         }
2102         | dots '.' {
2103                 $$ ++;
2104         }
2105         ;
2106
2107 tremolo_type:
2108         ':'     {
2109                 $$ = 0;
2110         }
2111         | ':' bare_unsigned {
2112                 if (!is_duration ($2))
2113                         PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2114                 $$ = $2;
2115         }
2116         ;
2117
2118 bass_number:
2119         UNSIGNED {
2120                 $$ = scm_from_int ($1);
2121         }
2122         | STRING { $$ = $1; }
2123         | full_markup { $$ = $1; }
2124         ;
2125
2126 figured_bass_alteration:
2127         '-'     { $$ = ly_rational2scm (FLAT_ALTERATION); }
2128         | '+'   { $$ = ly_rational2scm (SHARP_ALTERATION); }
2129         | '!'   { $$ = scm_from_int (0); }
2130         ;
2131
2132 bass_figure:
2133         FIGURE_SPACE {
2134                 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2135                 $$ = bfr->unprotect ();
2136         }
2137         | bass_number  {
2138                 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2139                 $$ = bfr->self_scm ();
2140
2141                 if (scm_is_number ($1))
2142                         bfr->set_property ("figure", $1);
2143                 else if (Text_interface::is_markup ($1))
2144                         bfr->set_property ("text", $1);
2145
2146                 bfr->unprotect ();
2147         }
2148         | bass_figure ']' {
2149                 $$ = $1;
2150                 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2151         }
2152         | bass_figure figured_bass_alteration {
2153                 Music *m = unsmob_music ($1);
2154                 if (scm_to_double ($2)) {
2155                         SCM salter = m->get_property ("alteration");
2156                         SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2157                         m->set_property ("alteration",
2158                                          scm_sum (alter, $2));
2159                 } else {
2160                         m->set_property ("alteration", scm_from_int (0));
2161                 }
2162         }
2163         | bass_figure figured_bass_modification  {
2164                 Music *m = unsmob_music ($1);
2165                 if ($2 == ly_symbol2scm ("plus"))
2166                         {
2167                         m->set_property ("augmented", SCM_BOOL_T);
2168                         }
2169                 else if ($2 == ly_symbol2scm ("slash"))
2170                         {
2171                         m->set_property ("diminished", SCM_BOOL_T);
2172                         }
2173                 else if ($2 == ly_symbol2scm ("exclamation"))
2174                         {
2175                         m->set_property ("no-continuation", SCM_BOOL_T);
2176                         }
2177                 else if ($2 == ly_symbol2scm ("backslash"))
2178                         {
2179                         m->set_property ("augmented-slash", SCM_BOOL_T);
2180                         }
2181         }
2182         ;
2183
2184
2185 figured_bass_modification:
2186         E_PLUS          {
2187                 $$ = ly_symbol2scm ("plus");
2188         }
2189         | E_EXCLAMATION {
2190                 $$ = ly_symbol2scm ("exclamation");
2191         }
2192         | '/'           {
2193                 $$ = ly_symbol2scm ("slash");
2194         }
2195         | E_BACKSLASH {
2196                 $$ = ly_symbol2scm ("backslash");
2197         }
2198         ;
2199
2200 br_bass_figure:
2201         bass_figure {
2202                 $$ = $1;
2203         }
2204         | '[' bass_figure {
2205                 $$ = $2;
2206                 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2207         }
2208         ;
2209
2210 figure_list:
2211         /**/            {
2212                 $$ = SCM_EOL;
2213         }
2214         | figure_list br_bass_figure {
2215                 $$ = scm_cons ($2, $1);
2216         }
2217         ;
2218
2219 figure_spec:
2220         FIGURE_OPEN figure_list FIGURE_CLOSE {
2221                 $$ = scm_reverse_x ($2, SCM_EOL);
2222         }
2223         ;
2224
2225
2226 optional_rest:
2227         /**/   { $$ = 0; }
2228         | REST { $$ = 1; }
2229         ;
2230
2231 simple_element:
2232         pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2233                 if (!PARSER->lexer_->is_note_state ())
2234                         PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2235
2236                 Music *n = 0;
2237                 if ($6)
2238                         n = MY_MAKE_MUSIC ("RestEvent", @$);
2239                 else
2240                         n = MY_MAKE_MUSIC ("NoteEvent", @$);
2241
2242                 n->set_property ("pitch", $1);
2243                 n->set_property ("duration", $5);
2244
2245                 if (scm_is_number ($4))
2246                 {
2247                         int q = scm_to_int ($4);
2248                         n->set_property ("absolute-octave", scm_from_int (q-1));
2249                 }
2250
2251                 if ($3 % 2)
2252                         n->set_property ("cautionary", SCM_BOOL_T);
2253                 if ($2 % 2 || $3 % 2)
2254                         n->set_property ("force-accidental", SCM_BOOL_T);
2255
2256                 $$ = n->unprotect ();
2257         }
2258         | DRUM_PITCH optional_notemode_duration {
2259                 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2260                 n->set_property ("duration", $2);
2261                 n->set_property ("drum-type", $1);
2262
2263                 $$ = n->unprotect ();
2264         }
2265         | RESTNAME optional_notemode_duration           {
2266                 Music *ev = 0;
2267                 if (ly_scm2string ($1) == "s") {
2268                         /* Space */
2269                         ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2270                   }
2271                 else {
2272                         ev = MY_MAKE_MUSIC ("RestEvent", @$);
2273
2274                     }
2275                 ev->set_property ("duration", $2);
2276                 $$ = ev->unprotect ();
2277         }
2278         | lyric_element optional_notemode_duration      {
2279                 if (!PARSER->lexer_->is_lyric_state ())
2280                         PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2281
2282                 Music *levent = MY_MAKE_MUSIC ("LyricEvent", @$);
2283                 levent->set_property ("text", $1);
2284                 levent->set_property ("duration",$2);
2285                 $$= levent->unprotect ();
2286         }
2287         ;
2288
2289 simple_chord_elements:
2290         simple_element  {
2291                 $$ = scm_list_1 ($1);
2292         }
2293         | new_chord {
2294                 if (!PARSER->lexer_->is_chord_state ())
2295                         PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2296                 $$ = $1;
2297         }
2298         | figure_spec optional_notemode_duration {
2299                 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2300                 {
2301                         unsmob_music (scm_car (s))->set_property ("duration", $2);
2302                 }
2303                 $$ = $1;
2304         }
2305         ;
2306
2307 lyric_element:
2308         lyric_markup {
2309                 $$ = $1;
2310         }
2311         | LYRICS_STRING {
2312                 $$ = $1;
2313         }
2314         ;
2315
2316 new_chord:
2317         steno_tonic_pitch optional_notemode_duration   {
2318                 $$ = make_chord_elements ($1, $2, SCM_EOL);
2319         }
2320         | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2321                 SCM its = scm_reverse_x ($4, SCM_EOL);
2322                 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2323         }
2324         ;
2325
2326 chord_items:
2327         /**/ {
2328                 $$ = SCM_EOL;
2329         }
2330         | chord_items chord_item {
2331                 $$ = scm_cons ($2, $$);
2332         }
2333         ;
2334
2335 chord_separator:
2336         CHORD_COLON {
2337                 $$ = ly_symbol2scm ("chord-colon");
2338         }
2339         | CHORD_CARET {
2340                 $$ = ly_symbol2scm ("chord-caret");
2341         }
2342         | CHORD_SLASH steno_tonic_pitch {
2343                 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2344         }
2345         | CHORD_BASS steno_tonic_pitch {
2346                 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2347         }
2348         ;
2349
2350 chord_item:
2351         chord_separator {
2352                 $$ = $1;
2353         }
2354         | step_numbers {
2355                 $$ = scm_reverse_x ($1, SCM_EOL);
2356         }
2357         | CHORD_MODIFIER  {
2358                 $$ = $1;
2359         }
2360         ;
2361
2362 step_numbers:
2363         step_number { $$ = scm_cons ($1, SCM_EOL); }
2364         | step_numbers '.' step_number {
2365                 $$ = scm_cons ($3, $$);
2366         }
2367         ;
2368
2369 step_number:
2370         bare_unsigned {
2371                 $$ = make_chord_step ($1, 0);
2372         }
2373         | bare_unsigned '+' {
2374                 $$ = make_chord_step ($1, SHARP_ALTERATION);
2375         }
2376         | bare_unsigned CHORD_MINUS {
2377                 $$ = make_chord_step ($1, FLAT_ALTERATION);
2378         }
2379         ;
2380
2381 tempo_range:
2382         bare_unsigned {
2383                 $$ = scm_from_int ($1);
2384         }
2385         | bare_unsigned '~' bare_unsigned {
2386                 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2387         }
2388         ;
2389
2390 /*
2391         UTILITIES
2392
2393 TODO: should deprecate in favor of Scheme?
2394
2395  */
2396 number_expression:
2397         number_expression '+' number_term {
2398                 $$ = scm_sum ($1, $3);
2399         }
2400         | number_expression '-' number_term {
2401                 $$ = scm_difference ($1, $3);
2402         }
2403         | number_term
2404         ;
2405
2406 number_term:
2407         number_factor {
2408                 $$ = $1;
2409         }
2410         | number_factor '*' number_factor {
2411                 $$ = scm_product ($1, $3);
2412         }
2413         | number_factor '/' number_factor {
2414                 $$ = scm_divide ($1, $3);
2415         }
2416         ;
2417
2418 number_factor:
2419         '-'  number_factor { /* %prec UNARY_MINUS */
2420                 $$ = scm_difference ($2, SCM_UNDEFINED);
2421         }
2422         | bare_number
2423         ;
2424
2425
2426 bare_number:
2427         UNSIGNED        {
2428                 $$ = scm_from_int ($1);
2429         }
2430         | REAL          {
2431                 $$ = $1;
2432         }
2433         | NUMBER_IDENTIFIER             {
2434                 $$ = $1;
2435         }
2436         | REAL NUMBER_IDENTIFIER        {
2437                 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2438         }
2439         | UNSIGNED NUMBER_IDENTIFIER    {
2440                 $$ = scm_from_double ($1 *scm_to_double ($2));
2441         }
2442         ;
2443
2444
2445 bare_unsigned:
2446         UNSIGNED {
2447                         $$ = $1;
2448         }
2449         ;
2450
2451 unsigned_number:
2452         bare_unsigned  { $$ = scm_from_int ($1); }
2453         | NUMBER_IDENTIFIER {
2454                 $$ = $1;
2455         }
2456         ;
2457
2458 exclamations:
2459                 { $$ = 0; }
2460         | exclamations '!'      { $$ ++; }
2461         ;
2462
2463 questions:
2464                 { $$ = 0; }
2465         | questions '?' { $$ ++; }
2466         ;
2467
2468 /*
2469 This should be done more dynamically if possible.
2470 */
2471
2472 lyric_markup:
2473         LYRIC_MARKUP_IDENTIFIER {
2474                 $$ = $1;
2475         }
2476         | LYRIC_MARKUP
2477                 { PARSER->lexer_->push_markup_state (); }
2478         markup_top {
2479                 $$ = $3;
2480                 PARSER->lexer_->pop_state ();
2481         }
2482         ;
2483
2484 full_markup_list:
2485         MARKUPLINES_IDENTIFIER {
2486                 $$ = $1;
2487         }
2488         | MARKUPLINES
2489                 { PARSER->lexer_->push_markup_state (); }
2490         markup_list {
2491                 $$ = $3;
2492                 PARSER->lexer_->pop_state ();
2493         }
2494         ;
2495
2496 full_markup:
2497         MARKUP_IDENTIFIER {
2498                 $$ = $1;
2499         }
2500         | MARKUP
2501                 { PARSER->lexer_->push_markup_state (); }
2502         markup_top {
2503                 $$ = $3;
2504                 PARSER->lexer_->pop_state ();
2505         }
2506         ;
2507
2508 markup_top:
2509         markup_list {
2510                 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"),  $1);
2511         }
2512         | markup_head_1_list simple_markup      {
2513                 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2514         }
2515         | simple_markup {
2516                 $$ = $1;
2517         }
2518         ;
2519
2520 markup_list:
2521         MARKUPLINES_IDENTIFIER {
2522                 $$ = $1;
2523         }
2524         | markup_composed_list {
2525                 $$ = $1;
2526         }
2527         | markup_braced_list {
2528                 $$ = $1;
2529         }
2530         | markup_command_list {
2531                 $$ = scm_list_1 ($1);
2532         }
2533         ;
2534
2535 markup_composed_list:
2536         markup_head_1_list markup_braced_list {
2537                 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2538
2539         }
2540         ;
2541
2542 markup_braced_list:
2543         '{' markup_braced_list_body '}' {
2544                 $$ = scm_reverse_x ($2, SCM_EOL);
2545         }
2546         ;
2547
2548 markup_braced_list_body:
2549         /* empty */     {  $$ = SCM_EOL; }
2550         | markup_braced_list_body markup {
2551                 $$ = scm_cons ($2, $1);
2552         }
2553         | markup_braced_list_body markup_list {
2554                 $$ = scm_reverse_x ($2, $1);
2555         }
2556         ;
2557
2558 markup_command_list:
2559         MARKUP_LIST_FUNCTION markup_command_list_arguments {
2560           $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
2561         }
2562         ;
2563
2564 markup_command_basic_arguments:
2565         EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
2566           $$ = scm_cons ($3, $2);
2567         }
2568         | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
2569           $$ = scm_cons ($3, $2);
2570         }
2571         | EXPECT_NO_MORE_ARGS {
2572           $$ = SCM_EOL;
2573         }
2574         ;
2575
2576 markup_command_list_arguments:
2577         markup_command_basic_arguments { $$ = $1; }
2578         | EXPECT_MARKUP markup_command_list_arguments markup {
2579           $$ = scm_cons ($3, $2);
2580         }
2581         ;
2582
2583 markup_head_1_item:
2584         MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
2585           $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
2586         }
2587         ;
2588
2589 markup_head_1_list:
2590         markup_head_1_item      {
2591                 $$ = scm_list_1 ($1);
2592         }
2593         | markup_head_1_list markup_head_1_item {
2594                 $$ = scm_cons ($2, $1);
2595         }
2596         ;
2597
2598 simple_markup:
2599         STRING {
2600                 $$ = make_simple_markup ($1);
2601         }
2602         | MARKUP_IDENTIFIER {
2603                 $$ = $1;
2604         }
2605         | LYRIC_MARKUP_IDENTIFIER {
2606                 $$ = $1;
2607         }
2608         | STRING_IDENTIFIER {
2609                 $$ = $1;
2610         }
2611         | SCORE {
2612                 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2613                 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2614         } '{' score_body '}' {
2615                 Score * sc = $4;
2616                 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2617                 sc->unprotect ();
2618                 PARSER->lexer_->pop_state ();
2619         }
2620         | MARKUP_FUNCTION markup_command_basic_arguments {
2621                 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
2622         }
2623         ;
2624
2625 markup:
2626         markup_head_1_list simple_markup        {
2627                 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2628                 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2629         }
2630         | simple_markup {
2631                 $$ = $1;
2632         }
2633         ;
2634
2635 %%
2636
2637 void
2638 Lily_parser::set_yydebug (bool x)
2639 {
2640         yydebug = x;
2641 }
2642
2643 void
2644 Lily_parser::do_yyparse ()
2645 {
2646         yyparse ((void*)this);
2647 }
2648
2649
2650
2651
2652
2653 /*
2654
2655 It is a little strange to have this function in this file, but
2656 otherwise, we have to import music classes into the lexer.
2657
2658 */
2659 int
2660 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2661 {
2662         if (scm_is_string (sid)) {
2663                 *destination = sid;
2664                 return STRING_IDENTIFIER;
2665         } else if (unsmob_book (sid)) {
2666                 Book *book =  unsmob_book (sid)->clone ();
2667                 *destination = book->self_scm ();
2668                 book->unprotect ();
2669
2670                 return BOOK_IDENTIFIER;
2671         } else if (scm_is_number (sid)) {
2672                 *destination = sid;
2673                 return NUMBER_IDENTIFIER;
2674         } else if (unsmob_context_def (sid)) {
2675                 Context_def *def= unsmob_context_def (sid)->clone ();
2676
2677                 *destination = def->self_scm ();
2678                 def->unprotect ();
2679
2680                 return CONTEXT_DEF_IDENTIFIER;
2681         } else if (unsmob_context_mod (sid)) {
2682                 *destination = unsmob_context_mod (sid)->smobbed_copy ();
2683
2684                 return CONTEXT_MOD_IDENTIFIER;
2685         } else if (unsmob_score (sid)) {
2686                 Score *score = new Score (*unsmob_score (sid));
2687                 *destination = score->self_scm ();
2688
2689                 score->unprotect ();
2690                 return SCORE_IDENTIFIER;
2691         } else if (Music *mus = unsmob_music (sid)) {
2692                 mus = mus->clone ();
2693                 *destination = mus->self_scm ();
2694                 unsmob_music (*destination)->
2695                         set_property ("origin", make_input (last_input_));
2696
2697                 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2698                         != SCM_BOOL_F;
2699
2700                 mus->unprotect ();
2701                 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2702         } else if (unsmob_pitch (sid)) {
2703                 *destination = unsmob_pitch (sid)->smobbed_copy ();
2704                 return PITCH_IDENTIFIER;
2705         } else if (unsmob_duration (sid)) {
2706                 *destination = unsmob_duration (sid)->smobbed_copy ();
2707                 return DURATION_IDENTIFIER;
2708         } else if (unsmob_output_def (sid)) {
2709                 Output_def *p = unsmob_output_def (sid);
2710                 p = p->clone ();
2711
2712                 *destination = p->self_scm ();
2713                 p->unprotect ();
2714                 return OUTPUT_DEF_IDENTIFIER;
2715         } else if (Text_interface::is_markup (sid)) {
2716                 *destination = sid;
2717                 if (is_lyric_state ())
2718                         return LYRIC_MARKUP_IDENTIFIER;
2719                 return MARKUP_IDENTIFIER;
2720         } else if (Text_interface::is_markup_list (sid)) {
2721                 *destination = sid;
2722                 return MARKUPLINES_IDENTIFIER;
2723         }
2724
2725         return -1;
2726 }
2727
2728 SCM
2729 get_next_unique_context_id ()
2730 {
2731         return scm_from_locale_string ("$uniqueContextId");
2732 }
2733
2734
2735 SCM
2736 get_next_unique_lyrics_context_id ()
2737 {
2738         static int new_context_count;
2739         char s[128];
2740         snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2741         return scm_from_locale_string (s);
2742 }
2743
2744
2745 SCM
2746 run_music_function (Lily_parser *parser, Input loc, SCM func, SCM args)
2747 {
2748         SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2749
2750         SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2751
2752         args = scm_reverse_x (args, SCM_EOL);
2753
2754         SCM fallback = SCM_BOOL_F;
2755         SCM pred = scm_car (sig);
2756
2757         if (scm_is_pair (pred))
2758         {
2759                 fallback = scm_cdr (pred);
2760                 if (Music *m = unsmob_music (fallback)) {
2761                         m = m->clone ();
2762                         m->set_spot (loc);
2763                         fallback = m->unprotect ();
2764                 }
2765                 pred = scm_car (pred);
2766         }
2767
2768         if (!to_boolean (scm_call_3  (type_check_proc, make_input (loc), scm_cdr (sig), args)))
2769         {
2770                 parser->error_level_ = 1;
2771                 return fallback;
2772         }
2773
2774         SCM syntax_args = scm_list_n (parser->self_scm (), make_input (loc), pred, fallback, func, args, SCM_UNDEFINED);
2775         return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
2776 }
2777
2778 bool
2779 is_regular_identifier (SCM id)
2780 {
2781   string str = ly_scm2string (id);
2782   char const *s = str.c_str ();
2783
2784   bool v = true;
2785 #if 0
2786   isalpha (*s);
2787   s++;
2788 #endif
2789   while (*s && v)
2790    {
2791         v = v && isalnum (*s);
2792         s++;
2793    }
2794   return v;
2795 }
2796
2797 Music *
2798 make_music_with_input (SCM name, Input where)
2799 {
2800        Music *m = make_music_by_name (name);
2801        m->set_spot (where);
2802        return m;
2803 }
2804
2805 SCM
2806 get_first_context_id (SCM type, Music *m)
2807 {
2808         SCM id = m->get_property ("context-id");
2809         if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2810             && scm_is_string (m->get_property ("context-id"))
2811             && scm_c_string_length (id) > 0)
2812         {
2813                 return id;
2814         }
2815         return SCM_EOL;
2816 }
2817
2818 SCM
2819 make_simple_markup (SCM a)
2820 {
2821         return a;
2822 }
2823
2824 bool
2825 is_duration (int t)
2826 {
2827   return t && t == 1 << intlog2 (t);
2828 }
2829
2830 void
2831 set_music_properties (Music *p, SCM a)
2832 {
2833   for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2834         p->set_property (scm_caar (k), scm_cdar (k));
2835 }
2836
2837
2838 SCM
2839 make_chord_step (int step, Rational alter)
2840 {
2841         if (step == 7)
2842                 alter += FLAT_ALTERATION;
2843
2844         while (step < 0)
2845                 step += 7;
2846         Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2847         return m.smobbed_copy ();
2848 }
2849
2850
2851 SCM
2852 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
2853 {
2854         SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
2855         return scm_call_3 (chord_ctor, pitch, dur, modification_list);
2856 }
2857
2858
2859 /* Todo: actually also use apply iso. call too ...  */
2860 bool
2861 ly_input_procedure_p (SCM x)
2862 {
2863         return ly_is_procedure (x)
2864                 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2865 }
2866
2867 SCM
2868 make_music_relative (Pitch start, SCM music, Input loc)
2869 {
2870         Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic", loc);
2871         relative->set_property ("element", music);
2872
2873         Music *m = unsmob_music (music);
2874         Pitch last = m->to_relative_octave (start);
2875         if (lily_1_8_relative)
2876                 m->set_property ("last-pitch", last.smobbed_copy ());
2877         return relative->unprotect ();
2878 }
2879
2880 int
2881 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2882 {
2883         Lily_parser *pars = (Lily_parser*) v;
2884         Lily_lexer *lex = pars->lexer_;
2885
2886         lex->lexval_ = (void*) s;
2887         lex->lexloc_ = loc;
2888         lex->prepare_for_next_token ();
2889         return lex->yylex ();
2890 }