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