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