]> git.donarmstrong.com Git - lilypond.git/blob - lily/lexer.ll
f595f73dc315c92474cb8c3dbc5a027390a50fea
[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         }
237         else
238                 error (_ ("\\maininput not allowed outside init files"));
239 }
240
241 <INITIAL,chords,lyrics,figures,notes>\\include           {
242         yy_push_state (incl);
243 }
244 <incl>\"[^"]*\";?   { /* got the include file name */
245 /* FIXME: semicolon? */
246         String s (YYText ()+1);
247         s = s.left_string (s.index_last ('"'));
248
249         new_input (s, sources_);
250         yy_pop_state ();
251 }
252 <incl>\\{BLACK}*;?{WHITE} { /* got the include identifier */
253 /* FIXME: semicolon? */
254         String s = YYText () + 1;
255         strip_trailing_white (s);
256         if (s.length () && (s[s.length () - 1] == ';'))
257           s = s.left_string (s.length () - 1);
258
259         SCM sid = lookup_identifier (s);
260         if (ly_c_string_p (sid)) {
261                 new_input (ly_scm2string (sid), sources_);
262                 yy_pop_state ();
263         } else { 
264             String msg (_f ("wrong or undefined identifier: `%s'", s ));
265
266             LexerError (msg.to_str0 ());
267             SCM err = scm_current_error_port ();
268             scm_puts ("This value was found in the table: ", err);
269             scm_display (sid, err);
270           }
271 }
272 <incl>\"[^"]*   { // backup rule
273         error (_ ("Missing end quote"));
274         exit (1);
275 }
276 <chords,notes,figures>{RESTNAME}        {
277         const char *s = YYText ();
278         yylval.scm = scm_makfrom0str (s);
279         return RESTNAME;
280 }
281 <chords,notes,figures>R         {
282         return MULTI_MEASURE_REST;
283 }
284 <INITIAL,markup,chords,lyrics,notes,figures>#   { //embedded scm
285         //char const* s = YYText () + 1;
286         char const* s = here_str0 ();
287         int n = 0;
288         SCM sval = ly_parse_scm (s, &n, here_input (),
289                 safe_global_b && main_input_b_);
290
291         if (sval == SCM_UNDEFINED)
292         {
293                 sval = SCM_UNSPECIFIED;
294                 error_level_ = 1;
295         }
296
297         for (int i=0; i < n; i++)
298         {
299                 yyinput ();
300         }
301         char_count_stack_.top () += n;
302
303         if (unpack_identifier (sval) != SCM_UNDEFINED)
304         {
305                 yylval.scm = unpack_identifier(sval);
306                 return identifier_type (yylval.scm);
307         }
308                 
309         yylval.scm = sval;
310         return SCM_T;
311 }
312 <INITIAL,notes,lyrics>{ 
313         \<\<   {
314                 return DOUBLE_ANGLE_OPEN;
315         }
316         \>\>   {
317                 return DOUBLE_ANGLE_CLOSE;
318         }
319 }
320 <figures>{
321         _       {
322                 return FIGURE_SPACE;
323         }
324         \>              {
325                 return FIGURE_CLOSE;
326         }
327         \<      {
328                 return FIGURE_OPEN;
329         }
330 }
331
332 <notes,figures>{
333         {ALPHAWORD}     {
334                 return scan_bare_word (YYText ());
335         }
336
337         {NOTECOMMAND}   {
338                 return scan_escaped_word (YYText () + 1); 
339         }
340         {FRACTION}      {
341                 yylval.scm =  scan_fraction (YYText ());
342                 return FRACTION;
343         }
344
345         {DIGIT}         {
346                 yylval.i = String_convert::dec2int (String (YYText ()));
347                 return DIGIT;
348         }
349         {UNSIGNED}              {
350                 yylval.i = String_convert::dec2int (String (YYText ()));
351                 return UNSIGNED;
352         }
353         {E_UNSIGNED}    {
354                 yylval.i = String_convert::dec2int (String (YYText () +1));
355                 return E_UNSIGNED;
356         }
357
358         \" {
359                 start_quote ();
360         }
361 }
362
363 \"              {
364         start_quote ();
365 }
366 <quote>{
367         \\{ESCAPED}     {
368                 *yylval.string += to_string (escaped_char (YYText ()[1]));
369         }
370         [^\\"]+ {
371                 *yylval.string += YYText ();
372         }
373         \"      {
374
375                 yy_pop_state ();
376
377                 /* yylval is union. Must remember STRING before setting SCM*/
378                 String *sp = yylval.string;
379                 yylval.scm = scm_makfrom0str (sp->to_str0 ());
380                 delete sp;
381                 return STRING;
382         }
383         .       {
384                 *yylval.string += YYText ();
385         }
386 }
387 <lyric_quote>{
388         \\{ESCAPED}     {
389                 *yylval.string += to_string (escaped_char (YYText ()[1]));
390         }
391         [^\\"]+ {
392                 *yylval.string += YYText ();
393         }
394         \"      {
395
396                 yy_pop_state ();
397
398                 /* yylval is union. Must remember STRING before setting SCM*/
399                 String *sp = yylval.string;
400                 yylval.scm = scm_makfrom0str (sp->to_str0 ());
401                 delete sp;
402                 return LYRICS_STRING;
403         }
404         .       {
405                 *yylval.string += YYText ();
406         }
407 }
408
409 <lyrics>{
410         \" {
411                 start_lyric_quote ();
412         }
413         {FRACTION}      {
414                 yylval.scm =  scan_fraction (YYText ());
415                 return FRACTION;
416         }
417         {UNSIGNED}              {
418                 yylval.i = String_convert::dec2int (String (YYText ()));
419                 return UNSIGNED;
420         }
421         {NOTECOMMAND}   {
422                 return scan_escaped_word (YYText () + 1);
423         }
424         {LYRICS} {
425                 /* ugr. This sux. */
426                 String s (YYText ()); 
427                 if (s == "__")
428                         return yylval.i = EXTENDER;
429                 if (s == "--")
430                         return yylval.i = HYPHEN;
431                 s = lyric_fudge (s);
432
433                 char c = s[s.length () - 1];
434                 if (c == '{' ||  c == '}') // brace open is for not confusing dumb tools.
435                         here_input ().warning (
436                                 _ ("Brace found at end of lyric.  Did you forget a space?"));
437                 yylval.scm = scm_makfrom0str (s.to_str0 ());
438
439
440                 return LYRICS_STRING;
441         }
442         . {
443                 return YYText ()[0];
444         }
445 }
446 <chords>{
447         {ALPHAWORD}     {
448                 return scan_bare_word (YYText ());
449         }
450         {NOTECOMMAND}   {
451                 return scan_escaped_word (YYText () + 1);
452         }
453         {FRACTION}      {
454                 yylval.scm =  scan_fraction (YYText ());
455                 return FRACTION;
456         }
457         {UNSIGNED}              {
458                 yylval.i = String_convert::dec2int (String (YYText ()));
459                 return UNSIGNED;
460         }
461         \" {
462                 start_quote ();
463         }
464         -  {
465                 return CHORD_MINUS;
466         }
467         :  {
468                 return CHORD_COLON;
469         }
470         \/\+ {
471                 return CHORD_BASS;
472         }
473         \/  {
474                 return CHORD_SLASH;
475         }
476         \^  {
477                 return CHORD_CARET;
478         }
479         . {
480                 return YYText ()[0];
481         }
482 }
483
484
485 <markup>{
486         \" {
487                 start_quote ();
488         }
489         \< {
490                 return '<';
491         }
492         \> {
493                 return '>';
494         }
495         \\score {
496                 return SCORE;
497         }
498         {MARKUPCOMMAND} {
499                 String str (YYText () + 1);
500                 SCM s = lookup_markup_command (str);
501
502                 if (ly_c_pair_p (s) && ly_c_symbol_p (ly_cdr (s)) ) {
503                         yylval.scm = ly_car(s);
504                         SCM tag = ly_cdr(s);
505                         if (tag == ly_symbol2scm("markup0"))
506                                 return MARKUP_HEAD_MARKUP0;
507                         if (tag == ly_symbol2scm("empty"))
508                                 return MARKUP_HEAD_EMPTY;
509                         else if (tag == ly_symbol2scm ("markup0-markup1"))
510                                 return MARKUP_HEAD_MARKUP0_MARKUP1;
511                         else if (tag == ly_symbol2scm ("markup-list0"))
512                                 return MARKUP_HEAD_LIST0;
513                         else if (tag == ly_symbol2scm ("scheme0"))
514                                 return MARKUP_HEAD_SCM0;
515                         else if (tag == ly_symbol2scm ("scheme0-scheme1"))
516                                 return MARKUP_HEAD_SCM0_SCM1;
517                         else if (tag == ly_symbol2scm ("scheme0-markup1"))
518                                 return MARKUP_HEAD_SCM0_MARKUP1;
519                         else if (tag == ly_symbol2scm ("scheme0-scheme1-markup2"))
520                                 return MARKUP_HEAD_SCM0_SCM1_MARKUP2;
521                         else if (tag == ly_symbol2scm ("scheme0-scheme1-scheme2"))
522                                 return MARKUP_HEAD_SCM0_SCM1_SCM2;
523                         else {
524                                 programming_error ("No parser tag defined for this signature. Abort"); 
525                                 ly_display_scm (s);
526                                 assert(false);
527                         }
528                 } else
529                         return scan_escaped_word (str);
530         }
531         [{}]    {
532                 return YYText ()[0];
533         }
534         [^#{}"\\ \t\n\r\f]+ {
535                 String s (YYText ()); 
536
537                 char c = s[s.length () - 1];
538                 /* brace open is for not confusing dumb tools.  */
539                 if (c == '{' ||  c == '}')
540                         here_input ().warning (
541                                 _ ("Brace found at end of markup.  Did you forget a space?"));
542                 yylval.scm = scm_makfrom0str (s.to_str0 ());
543
544
545                 return STRING;
546         }
547         .  {
548                 return YYText()[0];
549         }
550 }
551
552 <<EOF>> {
553         if (main_input_b_)
554         {
555                 main_input_b_ = false;
556                 if (!close_input ())
557                 /* Returns YY_NULL */
558                         yyterminate ();
559         }
560         else if (!close_input ())
561                 /* Returns YY_NULL */
562                 yyterminate ();
563 }
564
565
566 {WORD}  {
567         return scan_bare_word (YYText ());
568 }
569 {KEYWORD}       {
570         return scan_escaped_word (YYText () + 1);
571 }
572 {REAL}          {
573         Real r;
574         int cnv=sscanf (YYText (), "%lf", &r);
575         assert (cnv == 1);
576
577         yylval.scm = scm_make_real (r);
578         return REAL;
579 }
580
581 {UNSIGNED}      {
582         yylval.i = String_convert::dec2int (String (YYText ()));
583         return UNSIGNED;
584 }
585
586
587 [{}]    {
588
589         return YYText ()[0];
590 }
591 [*:=]           {
592         char c = YYText ()[0];
593
594         return c;
595 }
596
597 <INITIAL,notes,figures>.        {
598         return YYText ()[0];
599 }
600
601 <INITIAL,lyrics,notes,figures>\\. {
602     char c= YYText ()[1];
603
604     switch (c) {
605     case '>':
606         return E_BIGGER;
607     case '<':
608         return E_SMALLER;
609     case '!':
610         return E_EXCLAMATION;
611     case '(':
612         return E_OPEN;
613     case ')':
614         return E_CLOSE;
615     case '[':
616         return E_LEFTSQUARE;
617     case ']':
618         return E_RIGHTSQUARE;
619     case '~':
620         return E_TILDE;
621     case '\\':
622         return E_BACKSLASH;
623
624     default:
625         return E_CHAR;
626     }
627 }
628
629 <*>.            {
630         String msg = _f ("invalid character: `%c'", YYText ()[0]);
631         LexerError (msg.to_str0 ());
632         return YYText ()[0];
633 }
634
635 %%
636
637 void
638 My_lily_lexer::push_chord_state (SCM tab)
639 {
640         pitchname_tab_stack_ = scm_cons (tab, pitchname_tab_stack_);
641         yy_push_state (chords);
642 }
643
644 void
645 My_lily_lexer::push_figuredbass_state ()
646 {
647         yy_push_state (figures);
648 }
649
650 void
651 My_lily_lexer::push_initial_state ()
652 {
653         yy_push_state (INITIAL);
654 }
655
656 void
657 My_lily_lexer::push_lyric_state ()
658 {
659         yy_push_state (lyrics);
660 }
661
662 void
663 My_lily_lexer::push_markup_state ()
664 {
665         yy_push_state (markup);
666 }
667
668 void
669 My_lily_lexer::push_note_state (SCM tab)
670 {
671         pitchname_tab_stack_ = scm_cons (tab, pitchname_tab_stack_);
672         yy_push_state (notes);
673 }
674
675 void
676 My_lily_lexer::pop_state ()
677 {
678         if (YYSTATE == notes || YYSTATE == chords)
679                 pitchname_tab_stack_ = ly_cdr (pitchname_tab_stack_);
680         yy_pop_state ();
681 }
682
683 int
684 My_lily_lexer::identifier_type (SCM sid)
685 {
686         int k = try_special_identifiers (&yylval.scm , sid);
687         return k >= 0  ? k : SCM_IDENTIFIER;
688 }
689
690
691 int
692 My_lily_lexer::scan_escaped_word (String str)
693 {
694         // use more SCM for this.
695
696 //      SCM sym = ly_symbol2scm (str.to_str0 ());
697
698         int l = lookup_keyword (str);
699         if (l != -1) {
700                 return l;
701         }
702         SCM sid = lookup_identifier (str);
703         if (is_music_function (sid))
704         {
705                 yylval.scm = get_music_function_transform (sid);
706                 
707                 return music_function_type (yylval.scm);
708         }
709
710         if (sid != SCM_UNDEFINED)
711         {
712                 yylval.scm = sid;
713                 return identifier_type (sid);
714         }
715
716         String msg (_f ("unknown escaped string: `\\%s'", str));        
717         LexerError (msg.to_str0 ());
718
719         yylval.scm = scm_makfrom0str (str.to_str0 ());
720
721         return STRING;
722 }
723
724 int
725 My_lily_lexer::scan_bare_word (String str)
726 {
727         SCM sym = ly_symbol2scm (str.to_str0 ());
728         if ((YYSTATE == notes) || (YYSTATE == chords)) {
729                 SCM handle = SCM_BOOL_F;
730                 if (ly_c_pair_p (pitchname_tab_stack_))
731                         handle = scm_hashq_get_handle (ly_car (pitchname_tab_stack_), sym);
732                 
733                 if (ly_c_pair_p (handle)) {
734                         yylval.scm = ly_cdr (handle);
735                         if (unsmob_pitch (yylval.scm)) 
736                             return (YYSTATE == notes) ? NOTENAME_PITCH : TONICNAME_PITCH;
737                         else if (ly_c_symbol_p (yylval.scm))
738                             return DRUM_PITCH;
739                 }
740                 else if ((handle = scm_hashq_get_handle (chordmodifier_tab_, sym))!= SCM_BOOL_F)
741                 {
742                     yylval.scm = ly_cdr (handle);
743                     return CHORD_MODIFIER;
744                 }
745         }
746
747         yylval.scm = scm_makfrom0str (str.to_str0 ());
748         return STRING;
749 }
750
751 bool
752 My_lily_lexer::is_note_state () const
753 {
754         return YY_START == notes;
755 }
756
757 bool
758 My_lily_lexer::is_chord_state () const
759 {
760         return YY_START == chords;
761 }
762
763 bool
764 My_lily_lexer::is_lyric_state () const
765 {
766         return YY_START == lyrics;
767 }
768
769 bool
770 My_lily_lexer::is_figure_state () const
771 {
772         return YY_START == figures;
773 }
774
775 /*
776  urg, belong to String (_convert)
777  and should be generalised 
778  */
779 void
780 strip_leading_white (String&s)
781 {
782         int i=0;
783         for (;  i < s.length (); i++) 
784                 if (!isspace (s[i]))
785                         break;
786
787         s = s.nomid_string (0, i);
788 }
789
790 void
791 strip_trailing_white (String&s)
792 {
793         int i=s.length ();      
794         while (i--) 
795                 if (!isspace (s[i]))
796                         break;
797
798         s = s.left_string (i+1);
799 }
800
801
802
803 /* 2.1.2x something -> \property -> \set. */ 
804 Lilypond_version oldest_version ("2.2.0");
805
806
807 bool
808 is_valid_version (String s)
809 {
810   Lilypond_version current ( MAJOR_VERSION "." MINOR_VERSION "." PATCH_LEVEL );
811   Lilypond_version ver (s);
812   if (! ((ver >= oldest_version) && (ver <= current)))
813         {       
814                 non_fatal_error (_f ("Incorrect lilypond version: %s (%s, %s)", ver.to_string (), oldest_version.to_string (), current.to_string ()));
815                 non_fatal_error (_ ("Consider updating the input with the convert-ly script")); 
816                 return false;
817     }
818   return true;
819 }
820         
821
822 /*
823   substitute _ and \,
824 */
825 String
826 lyric_fudge (String s)
827 {
828   char  * chars  =s.get_copy_str0 ();
829
830   for (char * p = chars; *p ; p++)
831     {
832       if (*p == '_' && (p == chars || *(p-1) != '\\'))
833         *p = ' ';
834     }
835   
836   s = String (chars);
837   delete[] chars;
838
839   int i =0;     
840   if ((i=s.index ("\\,")) != -1)   // change "\," to TeX's "\c "
841     {
842       * (s.get_str0 () + i + 1) = 'c';
843       s = s.left_string (i+2) + " " + s.right_string (s.length ()-i-2);
844     }
845
846   return s;
847 }
848
849 /*
850 Convert "NUM/DEN" into a '(NUM . DEN) cons.
851 */
852 SCM
853 scan_fraction (String frac)
854 {
855         int i = frac.index ('/');
856         int l = frac.length ();
857         String left = frac.left_string (i);
858         String right = frac.right_string (l - i - 1);
859
860         int n = String_convert::dec2int (left);
861         int d = String_convert::dec2int (right);
862         return scm_cons (scm_int2num (n), scm_int2num (d));
863 }
864
865 // Breaks for flex 2.5.31
866 #if 0
867 /* avoid silly flex induced gcc warnings */
868 static void yy_push_state (int) {;}
869 static void yy_pop_state () {;}
870 static int yy_top_state () { return 0; }
871
872 static void
873 avoid_silly_flex_induced_gcc_warnings ()
874 {
875         (void)yy_start_stack_ptr;
876         (void)yy_start_stack_depth;
877         (void)yy_start_stack;
878         yy_push_state (0);
879         yy_pop_state ();
880         yy_top_state ();
881         avoid_silly_flex_induced_gcc_warnings ();
882 }
883 #endif
884
885 SCM
886 lookup_markup_command (String s)
887 {
888         SCM proc = ly_scheme_function ("lookup-markup-command");
889         return scm_call_1 (proc, scm_makfrom0str (s.to_str0 ()));
890 }
891
892
893 int
894 music_function_type (SCM func)
895 {
896         SCM type= scm_object_property (func, ly_symbol2scm ("music-function-signature-keyword"));
897         if (type == ly_symbol2scm ("scm"))
898         {
899                 return MUSIC_FUNCTION_SCM;
900         }
901         else if (type == ly_symbol2scm ("music"))
902         {
903                 return MUSIC_FUNCTION_MUSIC;
904         }
905         else if (type == ly_symbol2scm ("scm-music"))
906         {
907                 return MUSIC_FUNCTION_SCM_MUSIC;
908         }
909         else if (type == ly_symbol2scm ("scm-scm"))
910         {
911                 return MUSIC_FUNCTION_SCM_SCM;
912         }
913         else if (type == ly_symbol2scm ("music-music"))
914         {
915                 return MUSIC_FUNCTION_MUSIC_MUSIC;
916         }
917         else if (type == ly_symbol2scm ("scm-music-music"))
918         {
919                 return MUSIC_FUNCTION_SCM_MUSIC_MUSIC;
920         }
921         else if (type == ly_symbol2scm ("scm-scm-music"))
922         {
923                 return MUSIC_FUNCTION_SCM_SCM_MUSIC;
924         }
925         else if (type == ly_symbol2scm ("noarg"))
926         {
927                 return MUSIC_FUNCTION;
928         }
929         else
930                 {
931                 /* TODO: print location */
932                 error ("Can not find signature for music function.");
933                 }
934
935         return MUSIC_FUNCTION_SCM;
936 }