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