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