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