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