]> git.donarmstrong.com Git - lilypond.git/blob - lily/lexer.ll
b8a502edc127113667e558202797cd6ebd2ab10a
[lilypond.git] / lily / lexer.ll
1 %{ // -*-Fundamental-*-
2 /*
3   lexer.ll -- implement the Flex lexer
4
5   source file of the LilyPond music typesetter
6
7   (c) 1996--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8            Jan Nieuwenhuizen <janneke@gnu.org>
9 */
10
11
12 /*
13   backup rules
14
15   after making a change to the lexer rules, run 
16       flex -b <this lexer file>
17   and make sure that 
18       lex.backup
19   contains no backup states, but only the reminder
20       Compressed tables always back up.
21  (don-t forget to rm lex.yy.cc :-)
22  */
23
24
25 #include <stdio.h>
26 #include <ctype.h>
27 #include <errno.h>
28
29 /* Flex >= 2.5.29 fix; FlexLexer.h's multiple include bracing breaks
30    when building the actual lexer.  */
31 #define LEXER_CC
32
33 #include <iostream>
34 using namespace std;
35 #include "music-function.hh"
36 #include "source-file.hh"
37 #include "parse-scm.hh"
38 #include "lily-guile.hh"
39 #include "string.hh"
40 #include "string-convert.hh"
41 #include "my-lily-lexer.hh"
42 #include "interval.hh"
43 #include "lily-guile.hh"
44 #include "parser.hh"
45 #include "warn.hh"
46 #include "main.hh"
47 #include "version.hh"
48 #include "lilypond-input-version.hh"
49 #include "context-def.hh"
50 #include "identifier-smob.hh"
51
52 /*
53 RH 7 fix (?)
54 */
55 #define isatty HORRIBLEKLUDGE
56
57 void strip_trailing_white (String&);
58 void strip_leading_white (String&);
59 String lyric_fudge (String s);
60 int music_function_type (SCM);
61 SCM lookup_markup_command (String s);
62 bool is_valid_version (String s);
63
64
65 #define start_quote()   \
66         yy_push_state (quote);\
67         yylval.string = new String
68
69 #define start_lyric_quote()     \
70         yy_push_state (lyric_quote);\
71         yylval.string = new String
72
73 #define yylval \
74         (*(YYSTYPE*)lexval)
75
76 #define YY_USER_ACTION  add_lexed_char (YYLeng ());
77 /*
78
79 LYRICS          ({AA}|{TEX})[^0-9 \t\n\f]*
80
81 */
82
83
84 SCM scan_fraction (String);
85 SCM (* scm_parse_error_handler) (void *);
86
87
88
89 %}
90
91 %option c++
92 %option noyywrap
93 %option nodefault
94 %option debug
95 %option yyclass="My_lily_lexer"
96 %option stack
97 %option never-interactive 
98 %option warn
99
100 %x chords
101 %x encoding
102 %x figures
103 %x incl
104 %x lyrics
105 %x lyric_quote
106 %x longcomment
107 %x markup 
108 %x notes
109 %x quote
110 %x renameinput
111 %x version
112
113 A               [a-zA-Z]
114 AA              {A}|_
115 N               [0-9]
116 AN              {AA}|{N}
117 PUNCT           [?!:'`]
118 ACCENT          \\[`'"^]
119 NATIONAL        [\001-\006\021-\027\031\036\200-\377]
120 TEX             {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL}
121 WORD            {A}{AN}*
122 ALPHAWORD       {A}+
123 DIGIT           {N}
124 UNSIGNED        {N}+
125 E_UNSIGNED      \\{N}+
126 FRACTION        {N}+\/{N}+
127 INT             -?{UNSIGNED}
128 REAL            ({INT}\.{N}*)|(-?\.{N}+)
129 KEYWORD         \\{WORD}
130 WHITE           [ \n\t\f\r]
131 HORIZONTALWHITE         [ \t]
132 BLACK           [^ \n\t\f\r]
133 RESTNAME        [rs]
134 NOTECOMMAND     \\{A}+
135 MARKUPCOMMAND   \\({A}|[-_])+
136 LYRICS          ({AA}|{TEX})[^0-9 \t\n\r\f]*
137 ESCAPED         [nt\\'"]
138 EXTENDER        __
139 HYPHEN          --
140 %%
141
142
143 <*>\r           {
144         // windows-suck-suck-suck
145 }
146
147 <INITIAL,chords,incl,markup,lyrics,notes,figures>{
148   "%{"  {
149         yy_push_state (longcomment);
150   }
151   %[^{\n\r].*[\n\r]     {
152   }
153   %[^{\n\r]     { // backup rule
154   }
155   %[\n\r]       {
156   }
157   %[^{\n\r].*   {
158   }
159   {WHITE}+      {
160
161   }
162 }
163
164 <INITIAL,notes>\\encoding{WHITE}* {
165         yy_push_state (encoding);
166 }
167 <INITIAL,chords,lyrics,notes,figures>\\version{WHITE}*  {
168         yy_push_state (version);
169 }
170 <INITIAL,chords,lyrics,notes,figures>\\renameinput{WHITE}*      {
171         yy_push_state (renameinput);
172 }
173 <encoding>\"[^"]*\"     {
174         String s (YYText () + 1);
175         s = s.left_string (s.index_last ('\"'));
176         set_encoding (s);
177         yy_pop_state ();
178 }
179 <version>\"[^"]*\"     { /* got the version number */
180         String s (YYText () + 1);
181         s = s.left_string (s.index_last ('\"'));
182
183         yy_pop_state ();
184         if (!is_valid_version (s))
185                 return INVALID;
186 }
187 <renameinput>\"[^"]*\"     {
188         String s (YYText ()+1);
189         s = s.left_string (s.index_last ('\"'));
190
191         yy_pop_state();
192         this->here_input().source_file_->name_ = s;
193         progress_indication ("\n");
194         progress_indication (_f ("input renamed to: `%s'", s.to_str0 ()));
195         progress_indication ("\n");
196         scm_module_define (ly_car (scopes_),
197                      ly_symbol2scm ("input-file-name"),
198                      scm_makfrom0str (s.to_str0()));
199
200 }
201 <encoding>.     {
202         LexerError (_ ("No quoted string found after \\encoding").to_str0 ());
203         yy_pop_state ();
204 }
205 <version>.      {
206         LexerError (_ ("No quoted string found after \\version").to_str0 ());
207         yy_pop_state ();
208 }
209 <renameinput>.  {
210         LexerError (_ ("No quoted string found after \\renameinput").to_str0 ());
211         yy_pop_state ();
212 }
213 <longcomment>{
214         [^\%]*          {
215         }
216         \%*[^}%]*               {
217
218         }
219         "%"+"}"         {
220                 yy_pop_state ();
221         }
222         <<EOF>>         {
223                 LexerError (_ ("EOF found inside a comment").to_str0 ());
224                 main_input_b_ = false;
225                 if (! close_input ()) 
226                   yyterminate (); // can't move this, since it actually rets a YY_NULL
227         }
228 }
229
230
231 <INITIAL,chords,lyrics,notes,figures>\\maininput           {
232         if (!main_input_b_)
233         {
234                 start_main_input ();
235                 main_input_b_ = true;
236                 SCM nn = lookup_identifier ("pitchnames");
237                 push_note_state (alist_to_hashq (nn));
238         }
239         else
240                 error (_ ("\\maininput not allowed outside init files"));
241 }
242
243 <INITIAL,chords,lyrics,figures,notes>\\include           {
244         yy_push_state (incl);
245 }
246 <incl>\"[^"]*\";?   { /* got the include file name */
247 /* FIXME: semicolon? */
248         String s (YYText ()+1);
249         s = s.left_string (s.index_last ('"'));
250
251         new_input (s, sources_);
252         yy_pop_state ();
253 }
254 <incl>\\{BLACK}*;?{WHITE} { /* got the include identifier */
255 /* FIXME: semicolon? */
256         String s = YYText () + 1;
257         strip_trailing_white (s);
258         if (s.length () && (s[s.length () - 1] == ';'))
259           s = s.left_string (s.length () - 1);
260
261         SCM sid = lookup_identifier (s);
262         if (ly_c_string_p (sid)) {
263                 new_input (ly_scm2string (sid), sources_);
264                 yy_pop_state ();
265         } else { 
266             String msg (_f ("wrong or undefined identifier: `%s'", s ));
267
268             LexerError (msg.to_str0 ());
269             SCM err = scm_current_error_port ();
270             scm_puts ("This value was found in the table: ", err);
271             scm_display (sid, err);
272           }
273 }
274 <incl>\"[^"]*   { // backup rule
275         error (_ ("Missing end quote"));
276         exit (1);
277 }
278 <chords,notes,figures>{RESTNAME}        {
279         const char *s = YYText ();
280         yylval.scm = scm_makfrom0str (s);
281         return RESTNAME;
282 }
283 <chords,notes,figures>R         {
284         return MULTI_MEASURE_REST;
285 }
286 <INITIAL,markup,chords,lyrics,notes,figures>#   { //embedded scm
287         //char const* s = YYText () + 1;
288         char const* s = here_str0 ();
289         int n = 0;
290         SCM sval = ly_parse_scm (s, &n, here_input (),
291                 safe_global_b && main_input_b_);
292
293         if (sval == SCM_UNDEFINED)
294         {
295                 sval = SCM_UNSPECIFIED;
296                 error_level_ = 1;
297         }
298
299         for (int i=0; i < n; i++)
300         {
301                 yyinput ();
302         }
303         char_count_stack_.top () += n;
304
305         if (unpack_identifier (sval) != SCM_UNDEFINED)
306         {
307                 yylval.scm = unpack_identifier(sval);
308                 return identifier_type (yylval.scm);
309         }
310                 
311         yylval.scm = sval;
312         return SCM_T;
313 }
314 <INITIAL,notes,lyrics>{ 
315         \<\<   {
316                 return DOUBLE_ANGLE_OPEN;
317         }
318         \>\>   {
319                 return DOUBLE_ANGLE_CLOSE;
320         }
321 }
322 <figures>{
323         _       {
324                 return FIGURE_SPACE;
325         }
326         \>              {
327                 return FIGURE_CLOSE;
328         }
329         \<      {
330                 return FIGURE_OPEN;
331         }
332 }
333
334 <notes,figures>{
335         {ALPHAWORD}     {
336                 return scan_bare_word (YYText ());
337         }
338
339         {NOTECOMMAND}   {
340                 return scan_escaped_word (YYText () + 1); 
341         }
342         {FRACTION}      {
343                 yylval.scm =  scan_fraction (YYText ());
344                 return FRACTION;
345         }
346
347         {DIGIT}         {
348                 yylval.i = String_convert::dec2int (String (YYText ()));
349                 return DIGIT;
350         }
351         {UNSIGNED}              {
352                 yylval.i = String_convert::dec2int (String (YYText ()));
353                 return UNSIGNED;
354         }
355         {E_UNSIGNED}    {
356                 yylval.i = String_convert::dec2int (String (YYText () +1));
357                 return E_UNSIGNED;
358         }
359
360         \" {
361                 start_quote ();
362         }
363 }
364
365 \"              {
366         start_quote ();
367 }
368 <quote>{
369         \\{ESCAPED}     {
370                 *yylval.string += to_string (escaped_char (YYText ()[1]));
371         }
372         [^\\"]+ {
373                 *yylval.string += YYText ();
374         }
375         \"      {
376
377                 yy_pop_state ();
378
379                 /* yylval is union. Must remember STRING before setting SCM*/
380                 String *sp = yylval.string;
381                 yylval.scm = scm_makfrom0str (sp->to_str0 ());
382                 delete sp;
383                 return STRING;
384         }
385         .       {
386                 *yylval.string += YYText ();
387         }
388 }
389 <lyric_quote>{
390         \\{ESCAPED}     {
391                 *yylval.string += to_string (escaped_char (YYText ()[1]));
392         }
393         [^\\"]+ {
394                 *yylval.string += YYText ();
395         }
396         \"      {
397
398                 yy_pop_state ();
399
400                 /* yylval is union. Must remember STRING before setting SCM*/
401                 String *sp = yylval.string;
402                 yylval.scm = scm_makfrom0str (sp->to_str0 ());
403                 delete sp;
404                 return LYRICS_STRING;
405         }
406         .       {
407                 *yylval.string += YYText ();
408         }
409 }
410
411 <lyrics>{
412         \" {
413                 start_lyric_quote ();
414         }
415         {FRACTION}      {
416                 yylval.scm =  scan_fraction (YYText ());
417                 return FRACTION;
418         }
419         {UNSIGNED}              {
420                 yylval.i = String_convert::dec2int (String (YYText ()));
421                 return UNSIGNED;
422         }
423         {NOTECOMMAND}   {
424                 return scan_escaped_word (YYText () + 1);
425         }
426         {LYRICS} {
427                 /* ugr. This sux. */
428                 String s (YYText ()); 
429                 if (s == "__")
430                         return yylval.i = EXTENDER;
431                 if (s == "--")
432                         return yylval.i = HYPHEN;
433                 s = lyric_fudge (s);
434
435                 char c = s[s.length () - 1];
436                 if (c == '{' ||  c == '}') // brace open is for not confusing dumb tools.
437                         here_input ().warning (
438                                 _ ("Brace found at end of lyric.  Did you forget a space?"));
439                 yylval.scm = scm_makfrom0str (s.to_str0 ());
440
441
442                 return LYRICS_STRING;
443         }
444         . {
445                 return YYText ()[0];
446         }
447 }
448 <chords>{
449         {ALPHAWORD}     {
450                 return scan_bare_word (YYText ());
451         }
452         {NOTECOMMAND}   {
453                 return scan_escaped_word (YYText () + 1);
454         }
455         {FRACTION}      {
456                 yylval.scm =  scan_fraction (YYText ());
457                 return FRACTION;
458         }
459         {UNSIGNED}              {
460                 yylval.i = String_convert::dec2int (String (YYText ()));
461                 return UNSIGNED;
462         }
463         \" {
464                 start_quote ();
465         }
466         -  {
467                 return CHORD_MINUS;
468         }
469         :  {
470                 return CHORD_COLON;
471         }
472         \/\+ {
473                 return CHORD_BASS;
474         }
475         \/  {
476                 return CHORD_SLASH;
477         }
478         \^  {
479                 return CHORD_CARET;
480         }
481         . {
482                 return YYText ()[0];
483         }
484 }
485
486
487 <markup>{
488         \" {
489                 start_quote ();
490         }
491         \< {
492                 return '<';
493         }
494         \> {
495                 return '>';
496         }
497         {MARKUPCOMMAND} {
498                 String str (YYText () + 1);
499                 SCM s = lookup_markup_command (str);
500
501                 if (ly_c_pair_p (s) && ly_c_symbol_p (ly_cdr (s)) ) {
502                         yylval.scm = ly_car(s);
503                         SCM tag = ly_cdr(s);
504                         if (tag == ly_symbol2scm("markup0"))
505                                 return MARKUP_HEAD_MARKUP0;
506                         if (tag == ly_symbol2scm("empty"))
507                                 return MARKUP_HEAD_EMPTY;
508                         else if (tag == ly_symbol2scm ("markup0-markup1"))
509                                 return MARKUP_HEAD_MARKUP0_MARKUP1;
510                         else if (tag == ly_symbol2scm ("markup-list0"))
511                                 return MARKUP_HEAD_LIST0;
512                         else if (tag == ly_symbol2scm ("scheme0"))
513                                 return MARKUP_HEAD_SCM0;
514                         else if (tag == ly_symbol2scm ("scheme0-scheme1"))
515                                 return MARKUP_HEAD_SCM0_SCM1;
516                         else if (tag == ly_symbol2scm ("scheme0-markup1"))
517                                 return MARKUP_HEAD_SCM0_MARKUP1;
518                         else if (tag == ly_symbol2scm ("scheme0-scheme1-markup2"))
519                                 return MARKUP_HEAD_SCM0_SCM1_MARKUP2;
520                         else if (tag == ly_symbol2scm ("scheme0-scheme1-scheme2"))
521                                 return MARKUP_HEAD_SCM0_SCM1_SCM2;
522                         else {
523                                 programming_error ("No parser tag defined for this signature. Abort"); 
524                                 ly_display_scm (s);
525                                 assert(false);
526                         }
527                 } else
528                         return scan_escaped_word (str);
529         }
530         [{}]    {
531                 return YYText ()[0];
532         }
533         [^#{}"\\ \t\n\r\f]+ {
534                 String s (YYText ()); 
535
536                 char c = s[s.length () - 1];
537                 /* brace open is for not confusing dumb tools.  */
538                 if (c == '{' ||  c == '}')
539                         here_input ().warning (
540                                 _ ("Brace found at end of markup.  Did you forget a space?"));
541                 yylval.scm = scm_makfrom0str (s.to_str0 ());
542
543
544                 return STRING;
545         }
546         .  {
547                 return YYText()[0];
548         }
549 }
550
551 <<EOF>> {
552         if (main_input_b_)
553         {
554                 main_input_b_ = false;
555                 if (!close_input ())
556                 /* Returns YY_NULL */
557                         yyterminate ();
558         }
559         else if (!close_input ())
560                 /* Returns YY_NULL */
561                 yyterminate ();
562 }
563
564
565 {WORD}  {
566         return scan_bare_word (YYText ());
567 }
568 {KEYWORD}       {
569         return scan_escaped_word (YYText () + 1);
570 }
571 {REAL}          {
572         Real r;
573         int cnv=sscanf (YYText (), "%lf", &r);
574         assert (cnv == 1);
575
576         yylval.scm = scm_make_real (r);
577         return REAL;
578 }
579
580 {UNSIGNED}      {
581         yylval.i = String_convert::dec2int (String (YYText ()));
582         return UNSIGNED;
583 }
584
585
586 [{}]    {
587
588         return YYText ()[0];
589 }
590 [*:=]           {
591         char c = YYText ()[0];
592
593         return c;
594 }
595
596 <INITIAL,notes,figures>.        {
597         return YYText ()[0];
598 }
599
600 <INITIAL,lyrics,notes,figures>\\. {
601     char c= YYText ()[1];
602
603     switch (c) {
604     case '>':
605         return E_BIGGER;
606     case '<':
607         return E_SMALLER;
608     case '!':
609         return E_EXCLAMATION;
610     case '(':
611         return E_OPEN;
612     case ')':
613         return E_CLOSE;
614     case '[':
615         return E_LEFTSQUARE;
616     case ']':
617         return E_RIGHTSQUARE;
618     case '~':
619         return E_TILDE;
620     case '\\':
621         return E_BACKSLASH;
622
623     default:
624         return E_CHAR;
625     }
626 }
627
628 <*>.            {
629         String msg = _f ("invalid character: `%c'", YYText ()[0]);
630         LexerError (msg.to_str0 ());
631         return YYText ()[0];
632 }
633
634 %%
635
636 void
637 My_lily_lexer::push_chord_state (SCM tab)
638 {
639         pitchname_tab_stack_ = scm_cons (tab, pitchname_tab_stack_);
640         yy_push_state (chords);
641 }
642
643 void
644 My_lily_lexer::push_figuredbass_state ()
645 {
646         yy_push_state (figures);
647 }
648
649 void
650 My_lily_lexer::push_initial_state ()
651 {
652         yy_push_state (INITIAL);
653 }
654
655 void
656 My_lily_lexer::push_lyric_state ()
657 {
658         yy_push_state (lyrics);
659 }
660
661 void
662 My_lily_lexer::push_markup_state ()
663 {
664         yy_push_state (markup);
665 }
666
667 void
668 My_lily_lexer::push_note_state (SCM tab)
669 {
670         pitchname_tab_stack_ = scm_cons (tab, pitchname_tab_stack_);
671         yy_push_state (notes);
672 }
673
674 void
675 My_lily_lexer::pop_state ()
676 {
677         if (YYSTATE == notes || YYSTATE == chords)
678                 pitchname_tab_stack_ = ly_cdr (pitchname_tab_stack_);
679         yy_pop_state ();
680 }
681
682 int
683 My_lily_lexer::identifier_type (SCM sid)
684 {
685         int k = try_special_identifiers (&yylval.scm , sid);
686         return k >= 0  ? k : SCM_IDENTIFIER;
687 }
688
689
690 int
691 My_lily_lexer::scan_escaped_word (String str)
692 {
693         // use more SCM for this.
694
695 //      SCM sym = ly_symbol2scm (str.to_str0 ());
696
697         int l = lookup_keyword (str);
698         if (l != -1) {
699                 return l;
700         }
701         SCM sid = lookup_identifier (str);
702         if (is_music_function (sid))
703         {
704                 yylval.scm = get_music_function_transform (sid);
705                 
706                 return music_function_type (yylval.scm);
707         }
708
709         if (sid != SCM_UNDEFINED)
710         {
711                 yylval.scm = sid;
712                 return identifier_type (sid);
713         }
714
715         String msg (_f ("unknown escaped string: `\\%s'", str));        
716         LexerError (msg.to_str0 ());
717
718         yylval.scm = scm_makfrom0str (str.to_str0 ());
719
720         return STRING;
721 }
722
723 int
724 My_lily_lexer::scan_bare_word (String str)
725 {
726         SCM sym = ly_symbol2scm (str.to_str0 ());
727         if ((YYSTATE == notes) || (YYSTATE == chords)) {
728                 SCM handle = SCM_BOOL_F;
729                 if (ly_c_pair_p (pitchname_tab_stack_))
730                         handle = scm_hashq_get_handle (ly_car (pitchname_tab_stack_), sym);
731                 
732                 if (ly_c_pair_p (handle)) {
733                         yylval.scm = ly_cdr (handle);
734                         if (unsmob_pitch (yylval.scm)) 
735                             return (YYSTATE == notes) ? NOTENAME_PITCH : TONICNAME_PITCH;
736                         else if (ly_c_symbol_p (yylval.scm))
737                             return DRUM_PITCH;
738                 }
739                 else if ((handle = scm_hashq_get_handle (chordmodifier_tab_, sym))!= SCM_BOOL_F)
740                 {
741                     yylval.scm = ly_cdr (handle);
742                     return CHORD_MODIFIER;
743                 }
744         }
745
746         yylval.scm = scm_makfrom0str (str.to_str0 ());
747         return STRING;
748 }
749
750 bool
751 My_lily_lexer::is_note_state () const
752 {
753         return YY_START == notes;
754 }
755
756 bool
757 My_lily_lexer::is_chord_state () const
758 {
759         return YY_START == chords;
760 }
761
762 bool
763 My_lily_lexer::is_lyric_state () const
764 {
765         return YY_START == lyrics;
766 }
767
768 bool
769 My_lily_lexer::is_figure_state () const
770 {
771         return YY_START == figures;
772 }
773
774 /*
775  urg, belong to String (_convert)
776  and should be generalised 
777  */
778 void
779 strip_leading_white (String&s)
780 {
781         int i=0;
782         for (;  i < s.length (); i++) 
783                 if (!isspace (s[i]))
784                         break;
785
786         s = s.nomid_string (0, i);
787 }
788
789 void
790 strip_trailing_white (String&s)
791 {
792         int i=s.length ();      
793         while (i--) 
794                 if (!isspace (s[i]))
795                         break;
796
797         s = s.left_string (i+1);
798 }
799
800
801
802 /* 2.1.2x something -> \property -> \set. */ 
803 Lilypond_version oldest_version ("2.2.0");
804
805
806 bool
807 is_valid_version (String s)
808 {
809   Lilypond_version current ( MAJOR_VERSION "." MINOR_VERSION "." PATCH_LEVEL );
810   Lilypond_version ver (s);
811   if (! ((ver >= oldest_version) && (ver <= current)))
812         {       
813                 non_fatal_error (_f ("Incorrect lilypond version: %s (%s, %s)", ver.to_string (), oldest_version.to_string (), current.to_string ()));
814                 non_fatal_error (_ ("Consider updating the input with the convert-ly script")); 
815                 return false;
816     }
817   return true;
818 }
819         
820
821 /*
822   substitute _ and \,
823 */
824 String
825 lyric_fudge (String s)
826 {
827   char  * chars  =s.get_copy_str0 ();
828
829   for (char * p = chars; *p ; p++)
830     {
831       if (*p == '_' && (p == chars || *(p-1) != '\\'))
832         *p = ' ';
833     }
834   
835   s = String (chars);
836   delete[] chars;
837
838   int i =0;     
839   if ((i=s.index ("\\,")) != -1)   // change "\," to TeX's "\c "
840     {
841       * (s.get_str0 () + i + 1) = 'c';
842       s = s.left_string (i+2) + " " + s.right_string (s.length ()-i-2);
843     }
844
845   return s;
846 }
847
848 /*
849 Convert "NUM/DEN" into a '(NUM . DEN) cons.
850 */
851 SCM
852 scan_fraction (String frac)
853 {
854         int i = frac.index ('/');
855         int l = frac.length ();
856         String left = frac.left_string (i);
857         String right = frac.right_string (l - i - 1);
858
859         int n = String_convert::dec2int (left);
860         int d = String_convert::dec2int (right);
861         return scm_cons (scm_int2num (n), scm_int2num (d));
862 }
863
864 // Breaks for flex 2.5.31
865 #if 0
866 /* avoid silly flex induced gcc warnings */
867 static void yy_push_state (int) {;}
868 static void yy_pop_state () {;}
869 static int yy_top_state () { return 0; }
870
871 static void
872 avoid_silly_flex_induced_gcc_warnings ()
873 {
874         (void)yy_start_stack_ptr;
875         (void)yy_start_stack_depth;
876         (void)yy_start_stack;
877         yy_push_state (0);
878         yy_pop_state ();
879         yy_top_state ();
880         avoid_silly_flex_induced_gcc_warnings ();
881 }
882 #endif
883
884 SCM
885 lookup_markup_command (String s)
886 {
887         SCM proc = ly_scheme_function ("lookup-markup-command");
888         return scm_call_1 (proc, scm_makfrom0str (s.to_str0 ()));
889 }
890
891
892 int
893 music_function_type (SCM func)
894 {
895         SCM type= scm_object_property (func, ly_symbol2scm ("music-function-signature-keyword"));
896         if (type == ly_symbol2scm ("scm"))
897         {
898                 return MUSIC_FUNCTION_SCM;
899         }
900         else if (type == ly_symbol2scm ("music"))
901         {
902                 return MUSIC_FUNCTION_MUSIC;
903         }
904         else if (type == ly_symbol2scm ("scm-music"))
905         {
906                 return MUSIC_FUNCTION_SCM_MUSIC;
907         }
908         else if (type == ly_symbol2scm ("music-music"))
909         {
910                 return MUSIC_FUNCTION_MUSIC_MUSIC;
911         }
912         else if (type == ly_symbol2scm ("scm-music-music"))
913         {
914                 return MUSIC_FUNCTION_SCM_MUSIC_MUSIC;
915         }
916         else if (type == ly_symbol2scm ("scm-scm-music"))
917         {
918                 return MUSIC_FUNCTION_SCM_SCM_MUSIC;
919         }
920         else if (type == ly_symbol2scm ("noarg"))
921         {
922                 return MUSIC_FUNCTION;
923         }
924         else
925                 {
926                 /* TODO: print location */
927                 error ("Can not find sigature for music function.");
928                 }
929
930         return MUSIC_FUNCTION_SCM;
931 }