]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
* lily/part-combine-music.cc: removed file and class.
[lilypond.git] / lily / parser.yy
1 %{ // -*-Fundamental-*-
2
3 /*
4   parser.yy -- Bison/C++ parser for lilypond
5
6   source file of the GNU LilyPond music typesetter
7
8   (c)  1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9            Jan Nieuwenhuizen <janneke@gnu.org>
10 */
11
12 /*
13   Two shift/reduce problems:
14     -
15     -
16  */
17
18 /*
19
20 the rules for who is protecting what are very shady. TODO: uniformise
21 this.
22
23
24 */
25
26 #include <iostream.h>
27 #include <ctype.h>
28
29 #include "translator-def.hh"
30 #include "lily-guile.hh"
31 #include "change-iterator.hh"
32 #include "misc.hh"
33 #include "my-lily-lexer.hh"
34 #include "paper-def.hh"
35 #include "midi-def.hh"
36 #include "main.hh"
37 #include "file-path.hh"
38 #include "warn.hh"
39 #include "dimensions.hh"
40
41 #include "request.hh"
42 #include "my-lily-parser.hh"
43 #include "score.hh"
44 #include "music-list.hh"
45 #include "output-property-music-iterator.hh"
46 #include "property-iterator.hh"
47 #include "input-file-results.hh"
48 #include "input.hh"
49 #include "relative-music.hh"
50 #include "lyric-combine-music.hh"
51 #include "transposed-music.hh"
52 #include "time-scaled-music.hh"
53 #include "repeated-music.hh"
54 #include "untransposable-music.hh"
55 #include "lilypond-input-version.hh"
56 #include "grace-music.hh"
57 #include "scm-hash.hh"
58 #include "auto-change-iterator.hh"
59 #include "un-relativable-music.hh"
60 #include "chord.hh"
61 #include "ly-modules.hh"
62
63 bool
64 regular_identifier_b (SCM id)
65 {
66   String str = ly_scm2string (id);
67   char const *s = str.to_str0 () ;
68
69   bool v = true;
70   while (*s && v)
71    {
72         v = v && isalpha (*s);
73         s++;
74    }
75   return v;
76 }
77
78
79 bool
80 is_duration_b (int t)
81 {
82   return t && t == 1 << intlog2 (t);
83 }
84
85 void
86 set_music_properties (Music *p, SCM a)
87 {
88   for (SCM k = a; gh_pair_p (k); k = ly_cdr (k))
89         {
90         p->internal_set_mus_property (ly_caar (k), ly_cdar (k));
91         }
92 }
93
94
95
96 #define MY_MAKE_MUSIC(x)  make_music_by_name (ly_symbol2scm (x))
97
98 Music* 
99 set_property_music (SCM sym, SCM value)
100 {
101         Music * p = MY_MAKE_MUSIC("PropertySet");
102         p->set_mus_property ("symbol", sym);
103         p->set_mus_property ("value", value);
104         return p;
105 }
106
107 Music*
108 make_span_req (SCM name)
109 {
110   static SCM proc;
111   if (!proc)
112     proc = scm_c_eval_string ("old-span-request->event");
113   SCM m = scm_call_1 (proc, name);
114   scm_gc_protect_object (m);
115   return unsmob_music (m);
116 }
117
118 // needed for bison.simple's malloc () and free ()
119
120 // #include <malloc.h>
121 #include <stdlib.h>
122
123
124
125 #define YYERROR_VERBOSE 1
126
127 #define YYPARSE_PARAM my_lily_parser
128 #define YYLEX_PARAM my_lily_parser
129 #define THIS\
130         ((My_lily_parser *) my_lily_parser)
131
132 #define yyerror THIS->parser_error
133
134 %}
135
136 /* We use SCMs to do strings, because it saves us the trouble of
137 deleting them.  Let's hope that a stack overflow doesnt trigger a move
138 of the parse stack onto the heap. */
139
140
141 %union {
142
143     Link_array<Music> *reqvec;
144
145     String *string; // needed by the lexer as temporary scratch area.
146     Music *music;
147     Score *score;
148     Scheme_hash_table *scmhash;
149     Music_output_def * outputdef;
150     SCM scm;
151     int i;
152 }
153 %{
154
155 int
156 yylex (YYSTYPE *s,  void * v)
157 {
158         My_lily_parser   *pars = (My_lily_parser*) v;
159         My_lily_lexer * lex = pars->lexer_;
160
161         lex->lexval = (void*) s;
162         return lex->yylex ();
163 }
164
165
166 %}
167
168 %pure_parser
169
170 /* tokens which are not keywords */
171 %token AUTOCHANGE
172 %token ALIAS
173 %token APPLY
174 %token ARPEGGIO
175 %token DYNAMICSCRIPT
176 %token ACCEPTS
177 %token ALTERNATIVE
178 %token BAR
179 %token BREATHE
180 %token CHORDMODIFIERS
181 %token CHORDS
182 %token CHAR_T
183 %token CLEF
184 %token CM_T
185 %token CONSISTS
186 %token DURATION
187 %token SEQUENTIAL
188 %token GROBDESCRIPTIONS
189 %token SIMULTANEOUS
190 %token CONSISTSEND
191 %token DENIES
192 %token DURATION
193 %token EXTENDER
194 %token FIGURES FIGURE_OPEN FIGURE_CLOSE
195 %token FIGURE_BRACKET_CLOSE FIGURE_BRACKET_OPEN
196 %token GLISSANDO
197 %token GRACE 
198 %token HEADER
199 %token HYPHEN
200 %token IN_T
201 %token INVALID
202 %token KEY
203 %token LYRICS
204 %token MARK
205 %token MULTI_MEASURE_REST
206 %token MIDI
207 %token MM_T
208 %token PITCH
209 %token DEFAULT
210 %token NAME
211 %token PITCHNAMES
212 %token NOTES
213 %token ONCE
214 %token PAPER
215 %token PARTIAL
216 %token PENALTY
217 %token PROPERTY
218 %token OVERRIDE SET REVERT 
219 %token PT_T
220 %token RELATIVE
221 %token REMOVE
222 %token REPEAT
223 %token ADDLYRICS
224 %token PARTCOMBINE
225 %token SCM_T
226 %token SCORE
227 %token SCRIPT
228 %token SKIP
229 %token SPANREQUEST
230 %token STYLESHEET
231 %token COMMANDSPANREQUEST
232 %token TEMPO
233 %token OUTPUTPROPERTY
234 %token TIME_T
235 %token TIMES
236 %token TRANSLATOR
237 %token TRANSPOSE
238 %token TYPE
239 %token UNSET
240 %token CONTEXT
241 %token REST
242
243 /* escaped */
244 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
245 %token E_LEFTSQUARE E_RIGHTSQUARE E_TILDE
246 %token E_BACKSLASH
247 %token <i> E_UNSIGNED
248 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET  CHORD_SLASH
249 %token FIGURE_SPACE
250
251 %type <i>       exclamations questions dots optional_rest
252 %type <i>       bass_number bass_mod
253 %type <scm>     br_bass_figure bass_figure figure_list figure_spec
254 %token <i>      DIGIT
255 %token <scm>    NOTENAME_PITCH
256 %token <scm>    TONICNAME_PITCH
257 %token <scm>    CHORDMODIFIER_PITCH
258 %token <scm>    DURATION_IDENTIFIER
259 %token <scm>    FRACTION
260 %token <id>     IDENTIFIER
261
262
263 %token <scm>    SCORE_IDENTIFIER
264 %token <scm>    MUSIC_OUTPUT_DEF_IDENTIFIER
265
266 %token <scm>    NUMBER_IDENTIFIER
267 %token <scm>    REQUEST_IDENTIFIER
268 %token <scm>    MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
269 %token <scm>    STRING_IDENTIFIER SCM_IDENTIFIER 
270 %token <scm>    RESTNAME
271 %token <scm>    STRING   
272 %token <scm>    SCM_T
273 %token <i>      UNSIGNED
274 %token <scm>   REAL
275
276 %type <outputdef> output_def
277 %type <scm>     lilypond_header lilypond_header_body
278 %type <music>   open_request_parens close_request_parens open_request close_request
279 %type <music> request_with_dir request_that_take_dir verbose_request
280 %type <i>       sub_quotes sup_quotes
281 %type <music>   simple_element  request_chord command_element Simple_music  Composite_music 
282 %type <music>   Repeated_music
283 %type <scm>     Alternative_music
284 %type <i>       tremolo_type
285 %type <i>       bare_int  bare_unsigned
286 %type <i>       script_dir
287 %type <scm>     identifier_init 
288
289 %type <scm> steno_duration optional_notemode_duration multiplied_duration
290 %type <scm>  verbose_duration
291         
292 %type <reqvec>  pre_requests post_requests
293 %type <music> gen_text_def
294 %type <scm>   steno_pitch pitch absolute_pitch
295 %type <scm>   explicit_pitch steno_tonic_pitch
296
297 %type <scm>     chord_additions chord_subtractions chord_notes chord_step
298 %type <music>   chord
299 %type <scm>     chord_note chord_inversion chord_bass
300 %type <scm>     duration_length fraction
301
302 %type <scm>  embedded_scm scalar
303 %type <music>   Music Sequential_music Simultaneous_music 
304 %type <music>   relative_music re_rhythmed_music part_combined_music
305 %type <music>   property_def translator_change  simple_property_def
306 %type <scm> Music_list
307 %type <outputdef>  music_output_def_body
308 %type <music> shorthand_command_req
309 %type <music>   post_request 
310 %type <music> command_req verbose_command_req
311 %type <music>   extender_req
312 %type <music> hyphen_req
313 %type <music> string_request
314 %type <scm>     string bare_number number_expression number_term number_factor 
315
316 %type <score>   score_block score_body
317
318 %type <scm>     translator_spec_block translator_spec_body
319 %type <music>   tempo_request
320 %type <scm> notenames_body notenames_block chordmodifiers_block
321 %type <scm>     script_abbreviation
322
323
324
325 %left '-' '+'
326
327 /* We don't assign precedence to / and *, because we might need varied
328 prec levels in different prods */
329
330 %left UNARY_MINUS
331
332 %%
333
334 lilypond:       /* empty */
335         | lilypond toplevel_expression {}
336         | lilypond assignment  { }
337         | lilypond error {
338                 THIS->error_level_  = 1;
339         }
340         | lilypond INVALID      {
341                 THIS->error_level_  = 1;
342         }
343         ;
344
345 toplevel_expression:
346         notenames_block                 {
347                 THIS->lexer_->pitchname_tab_ =  $1;
348         }
349         | chordmodifiers_block                  {
350                 THIS->lexer_->chordmodifier_tab_  = $1;
351         }
352         | lilypond_header {
353                 THIS->input_file_->header_ = $1;
354         }
355         | score_block {
356                 THIS->input_file_->scores_.push ($1);
357         }
358         | output_def {
359                 if (dynamic_cast<Paper_def*> ($1))
360                         THIS->lexer_->set_identifier (scm_makfrom0str ("$defaultpaper"), $1->self_scm ());
361                 else if (dynamic_cast<Midi_def*> ($1))
362                         THIS->lexer_->set_identifier (scm_makfrom0str ("$defaultmidi"), $1->self_scm ());
363         }
364         | embedded_scm {
365                 // junk value
366         }       
367         ;
368
369 embedded_scm:
370         SCM_T
371         | SCM_IDENTIFIER 
372         ;
373
374
375 chordmodifiers_block:
376         CHORDMODIFIERS notenames_body   {  $$ = $2; }
377         ;
378
379 notenames_block:
380         PITCHNAMES notenames_body   {  $$ = $2; }
381         ;
382
383 notenames_body:
384         embedded_scm    {
385           int i = scm_ilength ($1);
386
387           SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
388           for (SCM s = $1; gh_pair_p (s); s = ly_cdr (s)) {
389                 SCM pt = ly_cdar (s);
390                 if (!unsmob_pitch (pt))
391                         THIS->parser_error ("Need pitch object.");
392                 else
393                         scm_hashq_set_x (tab, ly_caar (s), pt);
394           }
395
396           $$ = tab;
397         }
398         ;
399
400 lilypond_header_body:
401         {
402                 $$ = ly_make_anonymous_module (); 
403                 THIS->lexer_->add_scope ($$);
404         }
405         | lilypond_header_body assignment  { 
406                 
407         }
408         ;
409
410 lilypond_header:
411         HEADER '{' lilypond_header_body '}'     {
412                 $$ = THIS->lexer_-> remove_scope();
413         }
414         ;
415
416
417 /*
418         DECLARATIONS
419 */
420 assignment:
421         STRING {
422                 THIS->push_spot ();
423         }
424         /* cont */ '=' identifier_init  {
425
426         /*
427                 Should find generic way of associating input with objects.
428         */
429                 Input ip = THIS->pop_spot ();
430
431                 if (! regular_identifier_b ($1))
432                 {
433                         ip.warning (_ ("Identifier should have alphabetic characters only"));
434                 }
435
436                 THIS->lexer_->set_identifier ($1, $4);
437
438 /*
439  TODO: devise standard for protection in parser.
440
441   The parser stack lives on the C-stack, which means that
442 all objects can be unprotected as soon as they're here.
443
444 */
445         }
446         ;
447
448
449
450 identifier_init:
451         score_block {
452                 $$ = $1->self_scm ();
453                 scm_gc_unprotect_object ($$);
454         }
455         | output_def {
456                 $$ = $1->self_scm ();
457                 scm_gc_unprotect_object ($$);
458         }
459         | translator_spec_block {
460                 $$ = $1;
461         }
462         | Music  {
463                 $$ = $1->self_scm ();
464                 scm_gc_unprotect_object ($$);
465         }
466         | post_request {
467                 $$ = $1->self_scm ();
468                 scm_gc_unprotect_object ($$);
469         }
470         | verbose_duration {
471                 $$ = $1;
472         }
473         | number_expression {
474                 $$ = $1;
475         }
476         | string {
477                 $$ = $1;
478         }
479         | embedded_scm  {
480                 $$ = $1;
481         }
482         ;
483
484 translator_spec_block:
485         TRANSLATOR '{' translator_spec_body '}'
486                 {
487                 $$ = $3;
488         }
489         ;
490
491 translator_spec_body:
492         TRANSLATOR_IDENTIFIER   {
493                 $$ = unsmob_translator_def ($1)->clone_scm ();
494                 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
495         }
496         | TYPE STRING   {
497                 $$ = Translator_def::make_scm ();
498                 Translator_def*td =  unsmob_translator_def ($$);
499                 td->translator_group_type_ = $2;
500                 td->set_spot (THIS->here_input ());
501         }
502         | translator_spec_body STRING '=' embedded_scm                  {
503                 unsmob_translator_def ($$)->add_property_assign ($2, $4);
504         }
505         | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
506                 unsmob_translator_def ($$)
507                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
508         }
509         | translator_spec_body STRING SET embedded_scm '=' embedded_scm {
510                 unsmob_translator_def ($$)
511                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
512         }
513         | translator_spec_body STRING REVERT embedded_scm  {
514           unsmob_translator_def ($$)->add_pop_property (
515                 scm_string_to_symbol ($2), $4);
516         }
517         | translator_spec_body NAME STRING  {
518                 unsmob_translator_def ($$)->type_name_ = $3;
519         }
520         | translator_spec_body CONSISTS STRING  {
521                 unsmob_translator_def ($$)->add_element ($3);
522         }
523         | translator_spec_body ALIAS STRING  {
524                 Translator_def*td = unsmob_translator_def ($$);
525                 td->type_aliases_ = scm_cons ($3, td->type_aliases_);
526         }
527         | translator_spec_body GROBDESCRIPTIONS embedded_scm {
528                 Translator_def*td = unsmob_translator_def($$);
529                 // td->add_property_assign (ly_symbol2scm ("allGrobDescriptions"), $3);
530                 for (SCM p = $3; gh_pair_p (p); p = ly_cdr (p))
531                         td->add_property_assign (scm_symbol_to_string (ly_caar (p)), ly_cdar (p));
532         }
533         | translator_spec_body CONSISTSEND STRING  {
534                 unsmob_translator_def ($$)->add_last_element ( $3);
535         }
536         | translator_spec_body ACCEPTS STRING  {
537                 unsmob_translator_def ($$)->set_acceptor ($3,true);
538         }
539         | translator_spec_body DENIES STRING  {
540                 unsmob_translator_def ($$)->set_acceptor ($3,false);
541         }
542         | translator_spec_body REMOVE STRING  {
543                 unsmob_translator_def ($$)->remove_element ($3);
544         }
545         ;
546
547 /*
548         SCORE
549 */
550 score_block:
551         SCORE { 
552                 THIS->push_spot ();
553         }
554         /*cont*/ '{' score_body '}'     {
555                 THIS->pop_spot ();
556                 $$ = $4;
557                 if (!$$->defs_.size ())
558                 {
559                   Music_output_def *id =
560                         unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
561                   $$->add_output (id ? id->clone () :  new Paper_def );
562                 }
563         }
564         ;
565
566 score_body:
567         Music   {
568                 $$ = new Score;
569         
570                 $$->set_spot (THIS->here_input ());
571                 SCM m = $1->self_scm ();
572                 scm_gc_unprotect_object (m);
573
574                 /*
575                         guh.
576                 */
577                 SCM check_funcs = scm_c_eval_string ("toplevel-music-functions");
578                 for (; gh_pair_p (check_funcs); check_funcs = gh_cdr (check_funcs))
579                         m = gh_call1 (gh_car (check_funcs), m);
580                 $$->music_ = m;
581
582         }
583         | SCORE_IDENTIFIER {
584                 $$ = new Score (*unsmob_score ($1));
585                 $$->set_spot (THIS->here_input ());
586         }
587         | score_body lilypond_header    {
588                 $$->header_ = $2;
589         }
590         | score_body output_def {
591                 $$->add_output ($2);
592         }
593         | score_body error {
594
595         }
596         ;
597
598
599 /*
600         MIDI
601 */
602 output_def:
603         music_output_def_body '}' {
604                 $$ = $1;
605                 THIS-> lexer_-> remove_scope ();
606         }
607         ;
608
609 music_output_def_body:
610         MIDI '{'    {
611                 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultmidi"));
612
613
614                 Midi_def* p =0;
615                 if (id)
616                         p = dynamic_cast<Midi_def*> (id->clone ());
617                 else
618                         p = new Midi_def;
619
620                 $$ = p;
621                 THIS->lexer_->add_scope (p->scope_);
622         }
623         | PAPER '{'     {
624                 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
625                   Paper_def *p = 0;
626                 if (id)
627                         p = dynamic_cast<Paper_def*> (id->clone ());
628                 else
629                         p = new Paper_def;
630                 THIS-> lexer_->add_scope (p->scope_);
631                 $$ = p;
632         }
633         | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER         {
634                 Music_output_def *p = unsmob_music_output_def ($3);
635                 p = p->clone ();
636                 THIS->lexer_->add_scope (p->scope_);
637                 $$ = p;
638         }
639         | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER  {
640                 Music_output_def *p = unsmob_music_output_def ($3);
641                 p = p->clone ();
642
643                 THIS->lexer_->add_scope (p->scope_);
644                 $$ = p;
645         }
646         | music_output_def_body assignment  {
647
648         }
649         | music_output_def_body translator_spec_block   {
650                 $$->assign_translator ($2);
651         }
652         | music_output_def_body STYLESHEET embedded_scm {
653                 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
654         }
655         | music_output_def_body tempo_request  {
656                 /*
657                         junk this ? there already is tempo stuff in
658                         music.
659                 */
660                 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
661                 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
662                 Midi_def * md = dynamic_cast<Midi_def*> ($$);
663                 if (md)
664                         md->set_tempo (d->length_mom (), m);
665         }
666         | music_output_def_body error {
667
668         }
669         ;
670
671 tempo_request:
672         TEMPO steno_duration '=' bare_unsigned  {
673                 $$ = MY_MAKE_MUSIC("TempoEvent");
674                 $$->set_mus_property ("duration", $2);
675                 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
676         }
677         ;
678
679 /*
680 The representation of a  list is the
681
682   (LIST . LAST-CONS)
683
684  to have  efficient append.
685 */
686 Music_list: /* empty */ {
687                 $$ = scm_cons (SCM_EOL, SCM_EOL);
688         }
689         | Music_list Music {
690                 SCM s = $$;
691                 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
692                 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
693                 if (gh_pair_p (ly_cdr (s)))
694                         gh_set_cdr_x (ly_cdr (s), c); /* append */
695                 else
696                         gh_set_car_x (s, c); /* set first cons */
697                 gh_set_cdr_x (s, c) ;  /* remember last cell */ 
698         }
699         | Music_list error {
700         }
701         ;
702
703
704 Music:
705         Simple_music
706         | Composite_music
707         ;
708
709 Alternative_music:
710         /* empty */ {
711                 $$ = SCM_EOL;
712         }
713         | ALTERNATIVE '{' Music_list '}' {
714                 $$ = $3;
715         }
716         ;
717
718 Repeated_music:
719         REPEAT string bare_unsigned Music Alternative_music
720         {
721                 Music *beg = $4;
722                 int times = $3;
723                 SCM alts = gh_pair_p ($5) ? gh_car ($5) : SCM_EOL;
724                 if (times < scm_ilength (alts)) {
725                   unsmob_music (gh_car (alts))
726                     ->origin ()->warning (
727                     _("More alternatives than repeats.  Junking excess alternatives."));
728                   alts = ly_truncate_list (times, alts);
729                 }
730
731
732                 static SCM proc;
733                 if (!proc)
734                         proc = scm_c_eval_string ("make-repeated-music");
735
736                 SCM mus = scm_call_1 (proc, $2);
737                 scm_gc_protect_object (mus); // UGH. 
738                 Music *r =unsmob_music (mus);
739                 if (beg)
740                         {
741                         r-> set_mus_property ("element", beg->self_scm ());
742                         scm_gc_unprotect_object (beg->self_scm ());
743                         }
744                 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
745
746                 r-> set_mus_property ("elements",alts);
747                 if (gh_equal_p ($2, scm_makfrom0str ("tremolo")))
748                 {
749                 /*
750                 we can not get durations and other stuff correct down the line, so we have to
751                 add to the duration log here.
752                 */
753                         SCM func = scm_primitive_eval (ly_symbol2scm ("shift-duration-log"));
754                         if (($3 % 3) == 0)
755                           gh_call3 (func, r->self_scm (), gh_int2scm(-intlog2 ($3*2/3)),gh_int2scm(1));
756                         else
757                           gh_call3 (func, r->self_scm (), gh_int2scm(-intlog2 ($3)), gh_int2scm(0));
758                 }
759                 r->set_spot (*$4->origin ());
760
761                 $$ = r;
762         }
763         ;
764
765 Sequential_music:
766         SEQUENTIAL '{' Music_list '}'           {
767                 $$ = MY_MAKE_MUSIC("SequentialMusic");
768                 $$->set_mus_property ("elements", ly_car ($3));
769                 $$->set_spot(THIS->here_input());
770         }
771         | '{' Music_list '}'            {
772                 $$ = MY_MAKE_MUSIC("SequentialMusic");
773                 $$->set_mus_property ("elements", ly_car ($2));
774                 $$->set_spot(THIS->here_input());
775         }
776         ;
777
778 Simultaneous_music:
779         SIMULTANEOUS '{' Music_list '}'{
780                 $$ = MY_MAKE_MUSIC("SimultaneousMusic");
781                 $$->set_mus_property ("elements", ly_car ($3));
782                 $$->set_spot(THIS->here_input());
783
784         }
785         | '<' Music_list '>'    {
786                 $$ = MY_MAKE_MUSIC("SimultaneousMusic");
787                 $$->set_mus_property ("elements", ly_car ($2));
788                 $$->set_spot(THIS->here_input());
789         }
790         ;
791
792 Simple_music:
793         request_chord           { $$ = $1; }
794         | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm     {
795                 SCM pred = $2;
796                 if (!gh_symbol_p ($3))
797                 {
798                         THIS->parser_error (_ ("Second argument must be a symbol")); 
799                 }
800                 /* Should check # args */
801                 if (!gh_procedure_p (pred))
802                 {
803                         THIS->parser_error (_ ("First argument must be a procedure taking one argument"));
804                 }
805
806         Music*m = MY_MAKE_MUSIC("OutputPropertySetMusic");
807                 m->set_mus_property ("predicate", pred);
808                 m->set_mus_property ("grob-property", $3);
809                 m->set_mus_property ("grob-value",  $5);
810
811                 $$ = m;
812         }
813         | MUSIC_IDENTIFIER {
814                 $$ = unsmob_music ($1)->clone ();
815
816                 $$->set_spot (THIS->here_input());
817         }
818         | property_def
819         | translator_change
820         ;
821
822
823 Composite_music:
824         CONTEXT STRING Music    {
825                 Music*csm =MY_MAKE_MUSIC("ContextSpeccedMusic");
826
827                 csm->set_mus_property ("element", $3->self_scm ());
828                 scm_gc_unprotect_object ($3->self_scm ());
829
830                 csm->set_mus_property ("context-type",$2);
831                 csm->set_mus_property ("context-id", scm_makfrom0str (""));
832
833                 $$ = csm;
834         }
835         | AUTOCHANGE STRING Music       {
836         Music*chm = MY_MAKE_MUSIC("AutoChangeMusic");
837                 chm->set_mus_property ("element", $3->self_scm ());
838
839                 scm_gc_unprotect_object ($3->self_scm ());
840                 chm->set_mus_property ("what", $2); 
841
842                 $$ = chm;
843                 chm->set_spot (*$3->origin ());
844         }
845         | GRACE Music {
846 #if 1
847         /*
848                 The other version is for easier debugging  of
849                 Sequential_music_iterator in combination with grace notes.
850         */
851
852                 SCM start = THIS->lexer_->lookup_identifier ("startGraceMusic");
853                 SCM stop = THIS->lexer_->lookup_identifier ("stopGraceMusic");
854                 Music *startm = unsmob_music (start);
855                 Music *stopm = unsmob_music (stop);
856
857                 SCM ms = SCM_EOL;
858                 if (stopm) {
859                         stopm = stopm->clone ();
860                         ms = scm_cons (stopm->self_scm (), ms);
861                         scm_gc_unprotect_object (stopm->self_scm ());
862                 }
863                 ms = scm_cons ($2->self_scm (), ms);
864                 scm_gc_unprotect_object ($2->self_scm());
865                 if (startm) {
866                         startm = startm->clone ();
867                         ms = scm_cons (startm->self_scm () , ms);
868                         scm_gc_unprotect_object (startm->self_scm ());
869                 }
870
871         
872                 Music* seq = MY_MAKE_MUSIC("SequentialMusic");
873                 seq->set_mus_property ("elements", ms);
874
875                 
876                 $$ = MY_MAKE_MUSIC("GraceMusic");
877                 $$->set_mus_property ("element", seq->self_scm ());
878                 scm_gc_unprotect_object (seq->self_scm ());
879 #else
880                 $$ = MY_MAKE_MUSIC("GraceMusic");
881                 $$->set_mus_property ("element", $2->self_scm ());
882                 scm_gc_unprotect_object ($2->self_scm ());
883 #endif
884         }
885         | CONTEXT string '=' string Music {
886                 Music * csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
887
888                 csm->set_mus_property ("element", $5->self_scm ());
889                 scm_gc_unprotect_object ($5->self_scm ());
890
891                 csm->set_mus_property ("context-type", $2);
892                 csm->set_mus_property ("context-id", $4);
893
894                 $$ = csm;
895         }
896         | TIMES {
897                 THIS->push_spot ();
898         }
899         /* CONTINUED */ 
900                 fraction Music  
901
902         {
903                 int n = gh_scm2int (ly_car ($3)); int d = gh_scm2int (ly_cdr ($3));
904                 Music *mp = $4;
905         $$= MY_MAKE_MUSIC("TimeScaledMusic");
906                 $$->set_spot (THIS->pop_spot ());
907
908
909                 $$->set_mus_property ("element", mp->self_scm ());
910                 scm_gc_unprotect_object (mp->self_scm ());
911                 $$->set_mus_property ("numerator", gh_int2scm (n));
912                 $$->set_mus_property ("denominator", gh_int2scm (d));
913                 $$->compress (Moment (Rational (n,d)));
914
915         }
916         | Repeated_music                { $$ = $1; }
917         | Simultaneous_music            { $$ = $1; }
918         | Sequential_music              { $$ = $1; }
919         | TRANSPOSE pitch Music {
920                 $$ = MY_MAKE_MUSIC("TransposedMusic");
921                 Music *p = $3;
922                 Pitch pit = *unsmob_pitch ($2);
923
924                 p->transpose (pit);
925                 $$->set_mus_property ("element", p->self_scm ());
926                 scm_gc_unprotect_object (p->self_scm ());
927         }
928         | TRANSPOSE steno_tonic_pitch Music {
929                 $$ = MY_MAKE_MUSIC("TransposedMusic");
930                 Music *p = $3;
931                 Pitch pit = *unsmob_pitch ($2);
932
933                 p->transpose (pit);
934                 $$->set_mus_property ("element", p->self_scm ());
935                 scm_gc_unprotect_object (p->self_scm ());
936         
937         }
938         | APPLY embedded_scm Music  {
939                 SCM ret = gh_call1 ($2, $3->self_scm ());
940                 Music *m = unsmob_music (ret);
941                 if (!m) {
942                         THIS->parser_error ("\\apply must return a Music");
943                         m = MY_MAKE_MUSIC("Music");
944                         }
945                 $$ = m;
946         }
947         | NOTES
948                 { THIS->lexer_->push_note_state (); }
949         Music
950                 { $$ = $3;
951                   THIS->lexer_->pop_state ();
952                 }
953         | FIGURES
954                 { THIS->lexer_->push_figuredbass_state (); }
955         Music
956                 {
957                   Music * chm = MY_MAKE_MUSIC("UntransposableMusic");
958                   chm->set_mus_property ("element", $3->self_scm ());
959                   $$ = chm;
960                   scm_gc_unprotect_object ($3->self_scm());
961
962                   THIS->lexer_->pop_state ();
963         }
964         | CHORDS
965                 { THIS->lexer_->push_chord_state (); }
966         Music
967                 {
968                   Music * chm = MY_MAKE_MUSIC("UnrelativableMusic");
969                   chm->set_mus_property ("element", $3->self_scm ());
970                   scm_gc_unprotect_object ($3->self_scm());
971                   $$ = chm;
972
973                   THIS->lexer_->pop_state ();
974         }
975         | LYRICS
976                 { THIS->lexer_->push_lyric_state (); }
977         Music
978                 {
979                   $$ = $3;
980                   THIS->lexer_->pop_state ();
981         }
982         | relative_music        { $$ = $1; }
983         | re_rhythmed_music     { $$ = $1; } 
984         | part_combined_music   { $$ = $1; } 
985         ;
986
987 relative_music:
988         RELATIVE absolute_pitch Music {
989                 Music * p = $3;
990                 Pitch pit = *unsmob_pitch ($2);
991                 $$ = MY_MAKE_MUSIC("RelativeOctaveMusic");
992
993                 $$->set_mus_property ("element", p->self_scm ());
994                 scm_gc_unprotect_object (p->self_scm ());
995
996                 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
997
998         }
999         ;
1000
1001 re_rhythmed_music:
1002         ADDLYRICS Music Music {
1003         Music*l =MY_MAKE_MUSIC("LyricCombineMusic");
1004           l->set_mus_property ("elements", gh_list ($2->self_scm (), $3->self_scm (), SCM_UNDEFINED));
1005           scm_gc_unprotect_object ($3->self_scm ());
1006           scm_gc_unprotect_object ($2->self_scm ());
1007           $$ = l;
1008         }
1009         ;
1010
1011 part_combined_music:
1012         PARTCOMBINE STRING Music Music {
1013         Music * p= MY_MAKE_MUSIC("PartCombineMusic");
1014                 p->set_mus_property ("what", $2);
1015                 p->set_mus_property ("elements", gh_list ($3->self_scm (),$4->self_scm (), SCM_UNDEFINED));  
1016
1017                 scm_gc_unprotect_object ($3->self_scm ());
1018                 scm_gc_unprotect_object ($4->self_scm ());  
1019
1020                 $$ = p;
1021         }
1022         ;
1023
1024 translator_change:
1025         TRANSLATOR STRING '=' STRING  {
1026                 Music*t= MY_MAKE_MUSIC("TranslatorChange");
1027                 t-> set_mus_property ("change-to-type", $2);
1028                 t-> set_mus_property ("change-to-id", $4);
1029
1030                 $$ = t;
1031                 $$->set_spot (THIS->here_input ());
1032         }
1033         ;
1034
1035 property_def:
1036         simple_property_def
1037         | ONCE simple_property_def {
1038                 $$ = $2;
1039                 SCM e = $2->get_mus_property ("element");
1040                 unsmob_music (e)->set_mus_property ("once", SCM_BOOL_T);
1041         }
1042         ;
1043
1044 simple_property_def:
1045         PROPERTY STRING '.' STRING '='  scalar {
1046                 Music *t = set_property_music (scm_string_to_symbol ($4), $6);
1047                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1048
1049                 csm->set_mus_property ("element", t->self_scm ());
1050                 scm_gc_unprotect_object (t->self_scm ());
1051
1052                 $$ = csm;
1053                 $$->set_spot (THIS->here_input ());
1054
1055                 csm-> set_mus_property ("context-type", $2);
1056         }
1057         | PROPERTY STRING '.' STRING UNSET {
1058                 
1059                 Music *t = MY_MAKE_MUSIC("PropertyUnset");
1060                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1061
1062                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1063                 csm->set_mus_property ("element", t->self_scm ());
1064                 scm_gc_unprotect_object (t->self_scm ());
1065
1066                 $$ = csm;
1067                 $$->set_spot (THIS->here_input ());
1068
1069                 csm-> set_mus_property ("context-type", $2);
1070         }
1071         | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
1072                 bool autobeam
1073                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1074                 bool itc = internal_type_checking_global_b;
1075                 Music *t = MY_MAKE_MUSIC("OverrideProperty");
1076
1077                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1078                 t->set_mus_property ("pop-first", SCM_BOOL_T);
1079                 if (autobeam)
1080                         internal_type_checking_global_b = false;
1081                 t->set_mus_property ("grob-property", $6);
1082                 if (autobeam)
1083                         internal_type_checking_global_b = itc;
1084                 t->set_mus_property ("grob-value", $8);
1085
1086                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1087                 csm->set_mus_property ("element", t->self_scm ());
1088                 scm_gc_unprotect_object (t->self_scm ());
1089                 $$ = csm;
1090                 $$->set_spot (THIS->here_input ());
1091
1092                 csm-> set_mus_property ("context-type", $2);
1093         }
1094         | PROPERTY STRING '.' STRING OVERRIDE
1095                 embedded_scm '=' embedded_scm
1096         {
1097                 /*
1098                         UGH UGH UGH UGH.
1099                 */
1100                 bool autobeam
1101                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1102                 bool itc = internal_type_checking_global_b;
1103
1104                 Music *t = MY_MAKE_MUSIC("OverrideProperty");
1105                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1106                 if (autobeam)
1107                         internal_type_checking_global_b = false;
1108                 t->set_mus_property ("grob-property", $6);
1109                 t->set_mus_property ("grob-value", $8);
1110                 if (autobeam)
1111                         internal_type_checking_global_b = itc;
1112
1113                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1114                 csm->set_mus_property ("element", t->self_scm ());
1115                 scm_gc_unprotect_object (t->self_scm ());
1116
1117                 $$ = csm;
1118                 $$->set_spot (THIS->here_input ());
1119
1120                 csm-> set_mus_property ("context-type", $2);
1121
1122         }
1123         | PROPERTY STRING '.' STRING REVERT embedded_scm {
1124                 Music *t = MY_MAKE_MUSIC("RevertProperty");
1125                 bool autobeam
1126                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1127                 bool itc = internal_type_checking_global_b;
1128
1129                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1130                 if (autobeam)
1131                         internal_type_checking_global_b = false;
1132                 t->set_mus_property ("grob-property", $6);
1133                 if (autobeam)
1134                         internal_type_checking_global_b = itc;
1135         
1136                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1137                 csm->set_mus_property ("element", t->self_scm ());
1138                 scm_gc_unprotect_object (t->self_scm ());
1139
1140                 $$ = csm;
1141                 $$->set_spot (THIS->here_input ());
1142
1143                 csm-> set_mus_property ("context-type", $2);
1144         }
1145         ;
1146
1147
1148 scalar:
1149         string          { $$ = $1; }
1150         | bare_int      { $$ = gh_int2scm ($1); }
1151         | embedded_scm  { $$ = $1; }
1152         ;
1153
1154
1155 request_chord:
1156         pre_requests {
1157                 THIS->push_spot ();
1158         } /*cont */ simple_element post_requests        {
1159                 Music_sequence *l = dynamic_cast<Music_sequence*> ($3);
1160                 
1161                 $1->concat (*$4);
1162                 for (int i=0; i < $1->size (); i++) {
1163                   Music * m = $1->elem (i);
1164                   l->append_music (m);
1165                 }
1166                 $$ = $3;
1167
1168                 delete $1;
1169                 delete $4;
1170         }
1171         | command_element
1172         ;
1173
1174 command_element:
1175         command_req {
1176                 $$ = MY_MAKE_MUSIC("RequestChord");
1177                 $$->set_mus_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1178           scm_gc_unprotect_object ($1->self_scm());
1179
1180                 $$-> set_spot (THIS->here_input ());
1181                 $1-> set_spot (THIS->here_input ());
1182         }
1183         | E_LEFTSQUARE {
1184                 Music *l = MY_MAKE_MUSIC("LigatureEvent");
1185                 l->set_mus_property ("span-direction", gh_int2scm (START));
1186                 l->set_spot (THIS->here_input ());
1187
1188                 $$ = MY_MAKE_MUSIC("RequestChord");
1189                 $$->set_mus_property ("elements", scm_cons (l->self_scm (), SCM_EOL));
1190           scm_gc_unprotect_object (l->self_scm());
1191                 $$->set_spot (THIS->here_input ());
1192         }
1193         | E_RIGHTSQUARE {
1194                 Music *l = MY_MAKE_MUSIC("LigatureEvent");
1195                 l->set_mus_property ("span-direction", gh_int2scm (STOP));
1196                 l->set_spot (THIS->here_input ());
1197
1198                 $$ = MY_MAKE_MUSIC("RequestChord");
1199                 $$->set_mus_property ("elements", scm_cons (l->self_scm (), SCM_EOL));
1200                 $$->set_spot (THIS->here_input ());
1201           scm_gc_unprotect_object (l->self_scm());
1202
1203         }
1204         | E_BACKSLASH {
1205                 $$ = MY_MAKE_MUSIC("VoiceSeparator");
1206                 $$->set_spot (THIS->here_input ());
1207         }
1208         | '|'      {
1209
1210                 $$ = MY_MAKE_MUSIC("BarCheck");
1211                 $$->set_spot (THIS->here_input ());
1212         }
1213         | BAR STRING                    {
1214                 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1215
1216                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1217                 csm->set_mus_property ("element", t->self_scm ());
1218                 scm_gc_unprotect_object (t->self_scm ());
1219
1220                 $$ = csm;
1221                 $$->set_spot (THIS->here_input ());
1222
1223                 csm->set_mus_property ("context-type", scm_makfrom0str ("Timing"));
1224         }
1225         | PARTIAL duration_length       {
1226                 Moment m = - unsmob_duration ($2)->length_mom ();
1227                 Music * p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1228
1229                 Music * sp = MY_MAKE_MUSIC("ContextSpeccedMusic");
1230                 sp->set_mus_property ("element", p->self_scm ());
1231                 scm_gc_unprotect_object (p->self_scm ());
1232
1233                 $$ =sp ;
1234                 sp-> set_mus_property ("context-type", scm_makfrom0str ("Timing"));
1235         }
1236         | CLEF STRING  {
1237                 SCM func = scm_primitive_eval (ly_symbol2scm ("clef-name-to-properties"));
1238                 SCM result = gh_call1 (func, $2);
1239
1240                 SCM l = SCM_EOL;
1241                 for (SCM s = result ; gh_pair_p (s); s = ly_cdr (s)) {
1242                         Music * p = MY_MAKE_MUSIC("Music");
1243                         set_music_properties (p, ly_car (s));
1244                         l = scm_cons (p->self_scm (), l);
1245                         scm_gc_unprotect_object (p->self_scm ());
1246                 }
1247                 Music * seq = MY_MAKE_MUSIC("SequentialMusic");
1248                 seq->set_mus_property ("elements", l);
1249
1250                 Music * sp = MY_MAKE_MUSIC("ContextSpeccedMusic");
1251                 sp->set_mus_property ("element", seq->self_scm ());
1252                 scm_gc_unprotect_object (seq->self_scm ());
1253
1254                 $$ =sp ;
1255                 sp-> set_mus_property ("context-type", scm_makfrom0str ("Staff"));
1256         }
1257         | TIME_T fraction  {
1258                 Music * p1 = set_property_music (ly_symbol2scm ( "timeSignatureFraction"), $2);
1259
1260                 int l = gh_scm2int (ly_car ($2));
1261                 int o = gh_scm2int (ly_cdr ($2));
1262
1263                 Moment one_beat = Moment (1)/Moment (o);
1264                 Moment len = Moment (l) * one_beat;
1265
1266
1267                 Music *p2 = set_property_music (ly_symbol2scm ("measureLength"), len.smobbed_copy ());
1268                 Music *p3 = set_property_music (ly_symbol2scm ("beatLength"), one_beat.smobbed_copy ());
1269
1270                 SCM list = scm_list_n (p1->self_scm (), p2->self_scm (), p3->self_scm(), SCM_UNDEFINED);
1271                 Music *seq = MY_MAKE_MUSIC("SequentialMusic");
1272                 seq->set_mus_property ("elements", list);
1273                 
1274
1275                 Music * sp = MY_MAKE_MUSIC("ContextSpeccedMusic");
1276                 sp->set_mus_property ("element", seq->self_scm ());
1277
1278                 scm_gc_unprotect_object (p3->self_scm ());
1279                 scm_gc_unprotect_object (p2->self_scm ());
1280                 scm_gc_unprotect_object (p1->self_scm ());
1281                 scm_gc_unprotect_object (seq->self_scm ());
1282
1283                 $$ = sp;
1284
1285                 sp-> set_mus_property ("context-type", scm_makfrom0str ( "Timing"));
1286         }
1287         ;
1288
1289 command_req:
1290         shorthand_command_req   { $$ = $1; }
1291         | verbose_command_req   { $$ = $1; }
1292         ;
1293
1294 shorthand_command_req:
1295         extender_req {
1296                 $$ = $1;
1297         }
1298         | hyphen_req {
1299                 $$ = $1;
1300         }
1301         | '~'   {
1302                 $$ = MY_MAKE_MUSIC("TieEvent");
1303         }
1304         | '['           {
1305                 Music *b= MY_MAKE_MUSIC("BeamEvent");
1306                 b->set_mus_property ("span-direction", gh_int2scm (START))
1307 ;
1308                 $$ =b;
1309
1310
1311                 THIS->last_beam_start_ = b->self_scm ();
1312         }
1313         | ']'           {
1314                 Music *b= MY_MAKE_MUSIC("BeamEvent");
1315                 b->set_mus_property ("span-direction", gh_int2scm (STOP));
1316                 $$ = b;
1317         }
1318         | BREATHE {
1319                 $$ = MY_MAKE_MUSIC("BreathingSignEvent");
1320         }
1321         | E_TILDE {
1322                 $$ = MY_MAKE_MUSIC("PorrectusEvent");
1323         }
1324         ;
1325
1326 verbose_command_req:
1327         COMMANDSPANREQUEST bare_int STRING {
1328                 Music *sp = make_span_req ($3);
1329                 sp->set_mus_property ("span-direction", gh_int2scm (Direction ($2)));
1330                 sp->set_spot (THIS->here_input ());
1331                 $$ = sp;
1332         }
1333         | MARK DEFAULT  {
1334                 Music * m = MY_MAKE_MUSIC("MarkEvent");
1335                 $$ = m;
1336         }
1337         | MARK scalar {
1338                 Music *m = MY_MAKE_MUSIC("MarkEvent");
1339                 m->set_mus_property ("label", $2);
1340                 $$ = m;
1341         }
1342         | PENALTY SCM_T         {
1343                 Music * b = MY_MAKE_MUSIC("BreakEvent");
1344                 SCM s = $2;
1345                 if (!gh_number_p (s))
1346                         s = gh_int2scm (0);
1347
1348                 b->set_mus_property ("penalty", s);
1349                 b->set_spot (THIS->here_input ());
1350                 $$ = b;
1351         }
1352         | SKIP duration_length {
1353                 Music * skip = MY_MAKE_MUSIC("SkipEvent");
1354                 skip->set_mus_property ("duration", $2);
1355
1356                 $$ = skip;
1357         }
1358         | tempo_request {
1359                 $$ = $1;
1360         }
1361         | KEY DEFAULT {
1362                 Music *key= MY_MAKE_MUSIC("KeyChangeEvent");
1363                 $$ = key;
1364         }
1365         | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
1366                 Music *key= MY_MAKE_MUSIC("KeyChangeEvent");
1367                 
1368                 key->set_mus_property ("pitch-alist", $3);
1369                 ((Music*)key)->transpose (* unsmob_pitch ($2));
1370                 $$ = key; 
1371         }
1372         ;
1373
1374 post_requests:
1375         {
1376                 $$ = new Link_array<Music>;
1377         }
1378         | post_requests post_request {
1379                 $2->set_spot (THIS->here_input ());
1380                 $$->push ($2);
1381         }
1382         ;
1383
1384 post_request:
1385         verbose_request
1386         | request_with_dir
1387         | close_request
1388         | string_request
1389         ;
1390
1391
1392 string_request:
1393         E_UNSIGNED {
1394                 Music * s = MY_MAKE_MUSIC("StringNumberEvent");
1395                 s->set_mus_property ("string-number",  gh_int2scm($1));
1396                 s->set_spot (THIS->here_input ());
1397                 $$ = s;
1398         }
1399         ;
1400
1401
1402 request_that_take_dir:
1403         gen_text_def
1404         | verbose_request
1405         | script_abbreviation {
1406                 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1407                 Music *a = MY_MAKE_MUSIC("ArticulationEvent");
1408                 if (gh_string_p (s))
1409                         a->set_mus_property ("articulation-type", s);
1410                 else THIS->parser_error (_ ("Expecting string as script definition"));
1411                 $$ = a;
1412         }
1413         ;
1414
1415 request_with_dir:
1416         script_dir request_that_take_dir        {
1417                 $2->set_mus_property ("direction", gh_int2scm ($1));
1418                 $$ = $2;
1419         }
1420         ;
1421         
1422 verbose_request:
1423         REQUEST_IDENTIFIER      {
1424                 $$ = unsmob_music ($1)->clone ();
1425                 $$->set_spot (THIS->here_input ());
1426         }
1427         | DYNAMICSCRIPT embedded_scm {
1428                 /*
1429                         TODO: junkme, use text-type == dynamic
1430                 */
1431                 Music *d = MY_MAKE_MUSIC("TextScriptEvent");
1432                 SCM dyn = ly_symbol2scm ("dynamic");
1433                 d->set_mus_property ("text-type" , dyn);
1434                 d->set_mus_property ("text", $2);
1435                 d->set_spot (THIS->here_input ());
1436                 $$ = d;
1437         }
1438         | SPANREQUEST bare_int STRING {
1439
1440                 Music * sp = make_span_req ($3);
1441                 sp->set_mus_property ("span-direction", gh_int2scm ( $2));
1442                 sp->set_spot (THIS->here_input ());
1443                 $$ = sp;
1444         }
1445         | tremolo_type  {
1446                Music * a = MY_MAKE_MUSIC("TremoloEvent");
1447                a->set_spot (THIS->here_input ());
1448                a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1449                $$ = a;
1450         }
1451         | SCRIPT STRING         { 
1452                 Music * a = MY_MAKE_MUSIC("ArticulationEvent");
1453                 a->set_mus_property ("articulation-type", $2);
1454                 a->set_spot (THIS->here_input ());
1455                 $$ = a;
1456         }
1457
1458         /*
1459                 duh, junk this syntax from the parser, if possible. 
1460         */
1461         | ARPEGGIO {
1462                 Music *a = MY_MAKE_MUSIC("ArpeggioEvent");
1463                 a->set_spot (THIS->here_input ());
1464                 $$ = a;
1465         }
1466         | GLISSANDO {
1467                 Music *g = MY_MAKE_MUSIC("GlissandoEvent");
1468                 g->set_spot /* No pun intended */ (THIS->here_input ());
1469                 $$ = g;
1470         }       
1471         ;
1472
1473 sup_quotes:
1474         '\'' {
1475                 $$ = 1;
1476         }
1477         | sup_quotes '\'' {
1478                 $$ ++;
1479         }
1480         ;
1481
1482 sub_quotes:
1483         ',' {
1484                 $$ = 1;
1485         }
1486         | sub_quotes ',' {
1487                 $$ ++ ;
1488         }
1489         ;
1490
1491 steno_pitch:
1492         NOTENAME_PITCH  {
1493                 $$ = $1;
1494         }
1495         | NOTENAME_PITCH sup_quotes     {
1496                 Pitch p = *unsmob_pitch ($1);
1497                 p.octave_ +=  $2;
1498                 $$ = p.smobbed_copy ();
1499         }
1500         | NOTENAME_PITCH sub_quotes      {
1501                 Pitch p =* unsmob_pitch ($1);
1502
1503                 p.octave_ +=  -$2;
1504                 $$ = p.smobbed_copy ();
1505
1506         }
1507         ;
1508
1509 /*
1510 ugh. duplication
1511 */
1512
1513 steno_tonic_pitch:
1514         TONICNAME_PITCH {
1515                 $$ = $1;
1516         }
1517         | TONICNAME_PITCH sup_quotes    {
1518                 Pitch p = *unsmob_pitch ($1);
1519                 p.octave_ +=  $2;
1520                 $$ = p.smobbed_copy ();
1521         }
1522         | TONICNAME_PITCH sub_quotes     {
1523                 Pitch p =* unsmob_pitch ($1);
1524
1525                 p.octave_ +=  -$2;
1526                 $$ = p.smobbed_copy ();
1527
1528         }
1529         ;
1530
1531 pitch:
1532         steno_pitch {
1533                 $$ = $1;
1534         }
1535         | explicit_pitch {
1536                 $$ = $1;
1537         }
1538         ;
1539
1540 explicit_pitch:
1541         PITCH embedded_scm {
1542                 $$ = $2;
1543                 if (!unsmob_pitch ($2)) {
1544                         THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1545                          $$ = Pitch ().smobbed_copy ();
1546                 }
1547         }
1548         ;
1549
1550 verbose_duration:
1551         DURATION embedded_scm   {
1552                 $$ = $2;
1553                 if (!unsmob_duration ($2))
1554                 {
1555                         THIS->parser_error (_ ("Must have duration object"));
1556                         $$ = Duration ().smobbed_copy ();
1557                 }
1558         }
1559         ;
1560
1561 extender_req:
1562         EXTENDER {
1563                 if (!THIS->lexer_->lyric_state_b ())
1564                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1565                 $$ = MY_MAKE_MUSIC("ExtenderEvent");
1566         }
1567         ;
1568
1569 hyphen_req:
1570         HYPHEN {
1571                 if (!THIS->lexer_->lyric_state_b ())
1572                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1573                 $$ = MY_MAKE_MUSIC("HyphenEvent");
1574         }
1575         ;
1576
1577 close_request:
1578         close_request_parens {
1579                 $$ = $1;
1580                 dynamic_cast<Music *> ($$)->set_mus_property ("span-direction", gh_int2scm (START))
1581 ;
1582         }
1583         ;
1584  
1585 close_request_parens:
1586         '('     {
1587                 Music * s= MY_MAKE_MUSIC("SlurEvent");
1588                 $$ = s;
1589                 s->set_spot (THIS->here_input());
1590         }
1591         | E_OPEN        {
1592                 Music * s= MY_MAKE_MUSIC("PhrasingSlurEvent");
1593                 $$ = s;
1594                 s->set_spot (THIS->here_input());
1595         }
1596         | E_SMALLER {
1597                 Music *s =MY_MAKE_MUSIC("CrescendoEvent");
1598                 $$ = s;
1599                 s->set_spot (THIS->here_input());
1600         }
1601         | E_BIGGER {
1602                 Music *s =MY_MAKE_MUSIC("DecrescendoEvent");
1603                 $$ = s;
1604                 s->set_spot (THIS->here_input());
1605         }
1606         ;
1607
1608
1609 open_request:
1610         open_request_parens {
1611                 $$ = $1;
1612                 dynamic_cast<Music *> ($$)->set_mus_property ("span-direction", gh_int2scm (STOP))
1613 ;
1614         }
1615         ;
1616
1617 open_request_parens:
1618         E_EXCLAMATION   {
1619                 Music *s =  MY_MAKE_MUSIC("CrescendoEvent");
1620                 s->set_spot (THIS->here_input());
1621
1622                 $$ = s;
1623         }
1624         | ')'   {
1625                 Music * s= MY_MAKE_MUSIC("SlurEvent");
1626                 $$ = s;
1627                 s->set_spot (THIS->here_input());
1628
1629         }
1630         | E_CLOSE       {
1631                 Music * s= MY_MAKE_MUSIC("PhrasingSlurEvent");
1632                 $$ = s;
1633                 s->set_mus_property ("span-type", scm_makfrom0str ( "phrasing-slur"));
1634                 s->set_spot (THIS->here_input());
1635         }
1636         ;
1637
1638 gen_text_def:
1639         embedded_scm {
1640                 Music *t = MY_MAKE_MUSIC("TextScriptEvent");
1641                 t->set_mus_property ("text", $1);
1642                 t->set_spot (THIS->here_input ());
1643                 $$ = t;
1644         }
1645         | string {
1646                 Music *t = MY_MAKE_MUSIC("TextScriptEvent");
1647                 t->set_mus_property ("text", $1);
1648                 t->set_spot (THIS->here_input ());
1649                 $$ = t;
1650         }
1651         | DIGIT {
1652                 String ds = to_string ($1);
1653                 Music * t = MY_MAKE_MUSIC("TextScriptEvent");
1654                 SCM finger = ly_symbol2scm ("finger");
1655                 t->set_mus_property ("text",  scm_makfrom0str (ds.to_str0 ()));
1656                 t->set_mus_property ("text-type" , finger);
1657                 t->set_spot (THIS->here_input ());
1658                 $$ = t;
1659         }
1660         ;
1661
1662 script_abbreviation:
1663         '^'             {
1664                 $$ = scm_makfrom0str ("Hat");
1665         }
1666         | '+'           {
1667                 $$ = scm_makfrom0str ("Plus");
1668         }
1669         | '-'           {
1670                 $$ = scm_makfrom0str ("Dash");
1671         }
1672         | '|'           {
1673                 $$ = scm_makfrom0str ("Bar");
1674         }
1675         | '>'           {
1676                 $$ = scm_makfrom0str ("Larger");
1677         }
1678         | '.'           {
1679                 $$ = scm_makfrom0str ("Dot");
1680         }
1681         | '_' {
1682                 $$ = scm_makfrom0str ("Underscore");
1683         }
1684         ;
1685
1686 script_dir:
1687         '_'     { $$ = DOWN; }
1688         | '^'   { $$ = UP; }
1689         | '-'   { $$ = CENTER; }
1690         ;
1691
1692 pre_requests:
1693         {
1694                 $$ = new Link_array<Music>;
1695         }
1696         | pre_requests open_request {
1697                 $$->push ($2);
1698         }
1699         ;
1700
1701 absolute_pitch:
1702         steno_pitch     {
1703                 $$ = $1;
1704         }
1705         ;
1706
1707 duration_length:
1708         multiplied_duration {
1709                 $$ = $1;
1710         }
1711         | verbose_duration {
1712                 $$ = $1;
1713         }       
1714         ;
1715
1716 optional_notemode_duration:
1717         {
1718                 Duration dd = THIS->default_duration_;
1719                 $$ = dd.smobbed_copy ();
1720
1721                 THIS->beam_check ($$);
1722         }
1723         | multiplied_duration   {
1724                 $$ = $1;
1725                 THIS->default_duration_ = *unsmob_duration ($$);
1726
1727                 THIS->beam_check ($$);
1728         }
1729         | verbose_duration {
1730                 $$ = $1;
1731                 THIS->default_duration_ = *unsmob_duration ($$);
1732         }       
1733         ;
1734
1735 steno_duration:
1736         bare_unsigned dots              {
1737                 int l = 0;
1738                 if (!is_duration_b ($1))
1739                         THIS->parser_error (_f ("not a duration: %d", $1));
1740                 else
1741                         l =  intlog2 ($1);
1742
1743                 $$ = Duration (l, $2).smobbed_copy ();
1744         }
1745         | DURATION_IDENTIFIER dots      {
1746                 Duration *d =unsmob_duration ($1);
1747                 Duration k (d->duration_log (),d->dot_count () + $2);
1748                 $$ = k.smobbed_copy ();
1749         }
1750         ;
1751
1752
1753
1754
1755 multiplied_duration:
1756         steno_duration {
1757                 $$ = $1;
1758         }
1759         | multiplied_duration '*' bare_unsigned {
1760                 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1761         }
1762         | multiplied_duration '*' FRACTION {
1763                 Rational  m (gh_scm2int (ly_car ($3)), gh_scm2int (ly_cdr ($3)));
1764
1765                 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1766         }
1767         ;
1768
1769 fraction:
1770         FRACTION { $$ = $1; }
1771         | UNSIGNED '/' UNSIGNED {
1772                 $$ = scm_cons (gh_int2scm ($1), gh_int2scm ($3));
1773         }
1774         ;
1775
1776 dots:
1777         /* empty */     {
1778                 $$ = 0;
1779         }
1780         | dots '.' {
1781                 $$ ++;
1782         }
1783         ;
1784
1785
1786 tremolo_type: 
1787         ':'     {
1788                 $$ =0;
1789         }
1790         | ':' bare_unsigned {
1791                 if (!is_duration_b ($2))
1792                         THIS->parser_error (_f ("not a duration: %d", $2));
1793                 $$ = $2;
1794         }
1795         ;
1796
1797
1798 bass_number:
1799         DIGIT
1800         | UNSIGNED 
1801         ;
1802
1803 bass_mod:
1804         '-'     { $$ = -1; }
1805         | '+'   { $$ = 1; } 
1806         | '!'   { $$ = 0; }
1807         ;
1808
1809 bass_figure:
1810         FIGURE_SPACE {
1811                 Music *bfr = MY_MAKE_MUSIC("BassFigureEvent");
1812                 $$ = bfr->self_scm();
1813                 scm_gc_unprotect_object ($$);
1814         }
1815         | bass_number  {
1816                 Music *bfr = MY_MAKE_MUSIC("BassFigureEvent");
1817                 $$ = bfr->self_scm();
1818
1819                 bfr->set_mus_property ("figure", gh_int2scm ($1));
1820
1821                 scm_gc_unprotect_object ($$);
1822         }
1823         | bass_figure bass_mod {
1824                 Music *m = unsmob_music ($1);
1825                 if ($2) {
1826                         SCM salter =m->get_mus_property ("alteration");
1827                         int alter = gh_number_p ( salter) ? gh_scm2int (salter) : 0;
1828                         m->set_mus_property ("alteration",
1829                                 gh_int2scm (alter + $2));
1830                 } else {
1831                         m->set_mus_property ("alteration", gh_int2scm (0));
1832                 }
1833         }
1834         ;
1835
1836 br_bass_figure:
1837         '[' bass_figure {
1838                 $$ = $2;
1839                 unsmob_music ($$)->set_mus_property ("bracket-start", SCM_BOOL_T);
1840         }
1841         | bass_figure   {
1842                 $$ = $1;
1843         }
1844         | br_bass_figure ']' {
1845                 $$ = $1;
1846                 unsmob_music ($1)->set_mus_property ("bracket-stop", SCM_BOOL_T);
1847         }
1848         ;
1849
1850 figure_list:
1851         /**/            {
1852                 $$ = SCM_EOL;
1853         }
1854         | figure_list br_bass_figure {
1855                 $$ = scm_cons ($2, $1); 
1856         }
1857         ;
1858
1859 figure_spec:
1860         FIGURE_OPEN figure_list FIGURE_CLOSE {
1861                 Music * m = MY_MAKE_MUSIC("RequestChord");
1862                 $2 = scm_reverse_x ($2, SCM_EOL);
1863                 m->set_mus_property ("elements",  $2);
1864                 $$ = m->self_scm ();
1865         }
1866         ;
1867
1868
1869 optional_rest:
1870         /**/   { $$ = 0; }
1871         | REST { $$ = 1; }
1872         ;
1873
1874 simple_element:
1875         pitch exclamations questions optional_notemode_duration optional_rest {
1876
1877                 Input i = THIS->pop_spot ();
1878                 if (!THIS->lexer_->note_state_b ())
1879                         THIS->parser_error (_ ("Have to be in Note mode for notes"));
1880
1881                 Music *n = 0;
1882                 if ($5)
1883                         n =  MY_MAKE_MUSIC("RestEvent");
1884                 else
1885                         n =  MY_MAKE_MUSIC("NoteEvent");
1886                 
1887                 n->set_mus_property ("pitch", $1);
1888                 n->set_mus_property ("duration", $4);
1889
1890
1891                 if ($3 % 2)
1892                         n->set_mus_property ("cautionary", SCM_BOOL_T);
1893                 if ($2 % 2 || $3 % 2)
1894                         n->set_mus_property ("force-accidental", SCM_BOOL_T);
1895
1896                 Music *v = MY_MAKE_MUSIC("RequestChord");
1897                 v->set_mus_property ("elements", scm_list_n (n->self_scm (), SCM_UNDEFINED));
1898                 scm_gc_unprotect_object (n->self_scm());
1899
1900                 v->set_spot (i);
1901                 n->set_spot (i);
1902                 $$ = v;
1903         }
1904         | figure_spec optional_notemode_duration {
1905                 Music * m = unsmob_music ($1);
1906                 Input i = THIS->pop_spot (); 
1907                 m->set_spot (i);
1908                 for (SCM s = m->get_mus_property ("elements"); gh_pair_p (s); s = ly_cdr (s))
1909                         {
1910                                 unsmob_music (ly_car (s))->set_mus_property ("duration", $2);
1911                         }
1912                 $$ = m;
1913         }       
1914         | RESTNAME optional_notemode_duration           {
1915
1916                 Input i = THIS->pop_spot ();
1917                 SCM e = SCM_UNDEFINED;
1918                 if (ly_scm2string ($1) =="s") {
1919                         /* Space */
1920                         Music * skip = MY_MAKE_MUSIC("SkipEvent");
1921                         skip->set_mus_property ("duration" ,$2);
1922                         skip->set_spot (i);
1923                         e = skip->self_scm ();
1924                   }
1925                   else {
1926                         Music * rest_req = MY_MAKE_MUSIC("RestEvent");
1927                         rest_req->set_mus_property ("duration", $2);
1928                         rest_req->set_spot (i);
1929                         e = rest_req->self_scm ();
1930                     }
1931                 Music * velt = MY_MAKE_MUSIC("RequestChord");
1932                 velt-> set_mus_property ("elements", scm_list_n (e,SCM_UNDEFINED));
1933                 velt->set_spot (i);
1934
1935                 $$ = velt;
1936         }
1937         | MULTI_MEASURE_REST optional_notemode_duration         {
1938                 THIS->pop_spot ();
1939
1940                 Music * sk = MY_MAKE_MUSIC("SkipEvent");
1941                 sk->set_mus_property ("duration", $2);
1942                 Music *sp1 = MY_MAKE_MUSIC("MultiMeasureRestEvent");
1943                 Music *sp2 = MY_MAKE_MUSIC("MultiMeasureRestEvent");
1944                 sp1-> set_mus_property ("span-direction", gh_int2scm (START))
1945 ;
1946                 sp2-> set_mus_property ("span-direction", gh_int2scm (STOP))
1947 ;
1948                 Music *rqc1 = MY_MAKE_MUSIC("RequestChord");
1949                 rqc1->set_mus_property ("elements", scm_list_n (sp1->self_scm (), SCM_UNDEFINED));
1950                 Music *rqc2 = MY_MAKE_MUSIC("RequestChord");
1951                 rqc2->set_mus_property ("elements", scm_list_n (sk->self_scm (), SCM_UNDEFINED));;
1952                 Music *rqc3 = MY_MAKE_MUSIC("RequestChord");
1953                 rqc3->set_mus_property ("elements", scm_list_n (sp2->self_scm (), SCM_UNDEFINED));;
1954
1955                 SCM ms = scm_list_n (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1956
1957                 $$ = MY_MAKE_MUSIC("SequentialMusic");
1958                 $$->set_mus_property ("elements", ms);
1959         }
1960         | STRING optional_notemode_duration     {
1961                 Input i = THIS->pop_spot ();
1962
1963                 Music * lreq = MY_MAKE_MUSIC("LyricEvent");
1964                 lreq->set_mus_property ("text", $1);
1965                 lreq->set_mus_property ("duration",$2);
1966                 lreq->set_spot (i);
1967                 Music * velt = MY_MAKE_MUSIC("RequestChord");
1968                 velt->set_mus_property ("elements", scm_list_n (lreq->self_scm (), SCM_UNDEFINED));
1969
1970                 $$= velt;
1971         }
1972         | chord {
1973                 THIS->pop_spot ();
1974
1975                 if (!THIS->lexer_->chord_state_b ())
1976                         THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1977                 $$ = $1;
1978         }
1979         ;
1980
1981
1982 chord:
1983         steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1984                 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1985                 $$->set_spot (THIS->here_input ());
1986         };
1987
1988 chord_additions: 
1989         {
1990                 $$ = SCM_EOL;
1991         } 
1992         | CHORD_COLON chord_notes {
1993                 $$ = $2;
1994         }
1995         ;
1996
1997 chord_notes:
1998         chord_step {
1999                 $$ = $1;
2000         }
2001         | chord_notes '.' chord_step {
2002                 $$ = gh_append2 ($$, $3);
2003         }
2004         ;
2005
2006 chord_subtractions: 
2007         {
2008                 $$ = SCM_EOL;
2009         } 
2010         | CHORD_CARET chord_notes {
2011                 $$ = $2;
2012         }
2013         ;
2014
2015
2016 chord_inversion:
2017         {
2018                 $$ = SCM_EOL;
2019         }
2020         | CHORD_SLASH steno_tonic_pitch {
2021                 $$ = $2;
2022         }
2023         ;
2024
2025 chord_bass:
2026         {
2027                 $$ = SCM_EOL;
2028         }
2029         | CHORD_BASS steno_tonic_pitch {
2030                 $$ = $2;
2031         }
2032         ;
2033
2034 chord_step:
2035         chord_note {
2036                 $$ = scm_cons ($1, SCM_EOL);
2037         }
2038         | CHORDMODIFIER_PITCH {
2039                 $$ = scm_cons (unsmob_pitch ($1)->smobbed_copy (), SCM_EOL);
2040         }
2041         | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
2042                 $$ = scm_list_n (unsmob_pitch ($1)->smobbed_copy (),
2043                         $2, SCM_UNDEFINED);
2044         }
2045         ;
2046
2047 chord_note:
2048         bare_unsigned {
2049                  Pitch m;
2050                 m.notename_ = ($1 - 1) % 7;
2051                 m.octave_ = $1 > 7 ? 1 : 0;
2052                 m.alteration_ = 0;
2053
2054                 $$ = m.smobbed_copy ();
2055         } 
2056         | bare_unsigned '+' {
2057                 Pitch m;
2058                 m.notename_ = ($1 - 1) % 7;
2059                 m.octave_ = $1 > 7 ? 1 : 0;
2060                 m.alteration_ = 1;
2061
2062
2063                 $$ = m.smobbed_copy ();
2064         }
2065         | bare_unsigned CHORD_MINUS {
2066                 Pitch m;
2067                 m.notename_ = ($1 - 1) % 7;
2068                 m.octave_ = $1 > 7 ? 1 : 0;
2069                 m.alteration_ = -1;
2070
2071                 $$ = m.smobbed_copy ();
2072         }
2073         ;
2074
2075 /*
2076         UTILITIES
2077  */
2078 number_expression:
2079         number_expression '+' number_term {
2080                 $$ = scm_sum ($1, $3);
2081         }
2082         | number_expression '-' number_term {
2083                 $$ = scm_difference ($1, $3);
2084         }
2085         | number_term 
2086         ;
2087
2088 number_term:
2089         number_factor {
2090                 $$ = $1;
2091         }
2092         | number_factor '*' number_factor {
2093                 $$ = scm_product ($1, $3);
2094         }
2095         | number_factor '/' number_factor {
2096                 $$ = scm_divide ($1, $3);
2097         }
2098         ;
2099
2100 number_factor:
2101         '(' number_expression ')'       {
2102                 $$ = $2;
2103         }
2104         | '-'  number_factor { /* %prec UNARY_MINUS */
2105                 $$ = scm_difference ($2, SCM_UNDEFINED);
2106         }
2107         | bare_number
2108         ;
2109
2110
2111 bare_number:
2112         UNSIGNED        {
2113                 $$ = gh_int2scm ($1);
2114         }
2115         | REAL          {
2116                 $$ = $1;
2117         }
2118         | NUMBER_IDENTIFIER             {
2119                 $$ = $1;
2120         }
2121         | REAL CM_T     {
2122                 $$ = gh_double2scm (gh_scm2double ($1) CM );
2123         }
2124         | REAL PT_T     {
2125                 $$ = gh_double2scm (gh_scm2double ($1) PT);
2126         }
2127         | REAL IN_T     {
2128                 $$ = gh_double2scm (gh_scm2double ($1) INCH);
2129         }
2130         | REAL MM_T     {
2131                 $$ = gh_double2scm (gh_scm2double ($1) MM);
2132         }
2133         | REAL CHAR_T   {
2134                 $$ = gh_double2scm (gh_scm2double ($1) CHAR);
2135         }
2136         ;
2137
2138
2139 bare_unsigned:
2140         UNSIGNED {
2141                         $$ = $1;
2142         }
2143         | DIGIT {
2144                 $$ = $1;
2145         }
2146         ;
2147
2148 bare_int:
2149         bare_number {
2150                 if (scm_integer_p ($1) == SCM_BOOL_T)
2151                 {
2152                         int k = gh_scm2int ($1);
2153                         $$ = k;
2154                 } else
2155                 {
2156                         THIS->parser_error (_ ("need integer number arg"));
2157                         $$ = 0;
2158                 }
2159         }
2160         | '-' bare_int {
2161                 $$ = -$2;
2162         }
2163         ;
2164
2165
2166 string:
2167         STRING          {
2168                 $$ = $1;
2169         }
2170         | STRING_IDENTIFIER     {
2171                 $$ = $1;
2172         }
2173         | string '+' string {
2174                 $$ = scm_string_append (scm_list_n ($1, $3, SCM_UNDEFINED));
2175         }
2176         ;
2177
2178
2179 exclamations:
2180                 { $$ = 0; }
2181         | exclamations '!'      { $$ ++; }
2182         ;
2183
2184 questions:
2185                 { $$ = 0; }
2186         | questions '?' { $$ ++; }
2187         ;
2188
2189
2190 %%
2191
2192 void
2193 My_lily_parser::set_yydebug (bool )
2194 {
2195 #if 0
2196         yydebug = b;
2197 #endif
2198 }
2199
2200 extern My_lily_parser * current_parser;
2201
2202 void
2203 My_lily_parser::do_yyparse ()
2204 {
2205
2206         current_parser = this;;
2207         yyparse ((void*)this);
2208 }
2209
2210
2211 /*
2212 Should make this optional?    It will also complain when you do
2213
2214         [s4]
2215
2216 which is entirely legitimate.
2217
2218 Or we can scrap it. Barchecks should detect wrong durations, and
2219 skipTypesetting speeds it up a lot.
2220 */
2221 void
2222 My_lily_parser::beam_check (SCM dur)
2223 {
2224   Duration *d = unsmob_duration (dur);
2225   if (unsmob_music (last_beam_start_) && d->duration_log () <= 2)
2226     {
2227       Music * m = unsmob_music (last_beam_start_);
2228       m->origin ()->warning (_("Suspect duration found following this beam"));
2229     }
2230   last_beam_start_ = SCM_EOL;
2231 }