]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lexer.ll
* lily/note-column.cc: reformat.
[lilypond.git] / lily / lexer.ll
index a31f25e43bc3d1c785092ea045147e541c6bfd0f..178ea88e97eb9d070e22359aa0458f2487158fab 100644 (file)
@@ -112,6 +112,7 @@ SCM (* scm_parse_error_handler) (void *);
 %x markup
 %x notes
 %x quote
+%x sourcefileline
 %x sourcefilename
 %x version
 
@@ -179,22 +180,33 @@ BOM_UTF8  \357\273\277
   }
 }
 
+<INITIAL,notes,figures,chords,markup>{
+       \"              {
+               start_quote ();
+       }
+}
+
 <INITIAL,chords,lyrics,notes,figures>\\version{WHITE}* {
        yy_push_state (version);
 }
 <INITIAL,chords,lyrics,notes,figures>\\sourcefilename{WHITE}*  {
        yy_push_state (sourcefilename);
 }
+<INITIAL,chords,lyrics,notes,figures>\\sourcefileline{WHITE}*  {
+       yy_push_state (sourcefileline);
+}
 <version>\"[^"]*\"     { /* got the version number */
        string s (YYText () + 1);
        s = s.substr (0, s.rfind ('\"'));
 
        yy_pop_state ();
+
+       SCM top_scope = scm_car (scm_last_pair (scopes_));
+       scm_module_define (top_scope, ly_symbol2scm ("version-seen"), SCM_BOOL_T);
+
        if (!is_valid_version (s))
                return INVALID;
 
-       SCM top_scope = scm_car (scm_last_pair (scopes_));
-       scm_module_define (top_scope, ly_symbol2scm ("version-seen?"), SCM_BOOL_T);
 
 }
 <sourcefilename>\"[^"]*\"     {
@@ -210,6 +222,16 @@ BOM_UTF8   \357\273\277
                     scm_makfrom0str (s.c_str ()));
 
 }
+
+<sourcefileline>{INT}  {
+       int i;
+       sscanf (YYText (), "%d", &i);
+
+//     this->set_debug (1); 
+       yy_pop_state ();
+       this->here_input ().get_source_file ()->set_line (here_input ().start (), i);
+}
+
 <version>.     {
        LexerError (_ ("quoted string expected after \\version").c_str ());
        yy_pop_state ();
@@ -218,6 +240,10 @@ BOM_UTF8   \357\273\277
        LexerError (_ ("quoted string expected after \\sourcefilename").c_str ());
        yy_pop_state ();
 }
+<sourcefileline>.      {
+       LexerError (_ ("integer expected after \\sourcefileline").c_str ());
+       yy_pop_state ();
+}
 <longcomment>{
        [^\%]*          {
        }
@@ -313,16 +339,26 @@ BOM_UTF8  \357\273\277
        }
                
        yylval.scm = sval;
-       return SCM_T;
+       return SCM_TOKEN;
 }
 <INITIAL,notes,lyrics>{ 
-       \<\<   {
+       \<\<    {
                return DOUBLE_ANGLE_OPEN;
        }
-       \>\>   {
+       \>\>    {
                return DOUBLE_ANGLE_CLOSE;
        }
 }
+
+<INITIAL,notes>{
+       \<      {
+               return ANGLE_OPEN;
+       }
+       \>      {
+               return ANGLE_CLOSE;
+       }
+}
+
 <figures>{
        _       {
                return FIGURE_SPACE;
@@ -360,36 +396,9 @@ BOM_UTF8   \357\273\277
                yylval.i = String_convert::dec2int (string (YYText () +1));
                return E_UNSIGNED;
        }
-       \" {
-               start_quote ();
-       }
-}
-
-\"             {
-       start_quote ();
 }
-<quote>{
-       \\{ESCAPED}     {
-               *yylval.string += to_string (escaped_char (YYText ()[1]));
-       }
-       [^\\"]+ {
-               *yylval.string += YYText ();
-       }
-       \"      {
-
-               yy_pop_state ();
 
-               /* yylval is union. Must remember STRING before setting SCM*/
-               string *sp = yylval.string;
-               yylval.scm = scm_makfrom0str (sp->c_str ());
-               delete sp;
-               return STRING;
-       }
-       .       {
-               *yylval.string += YYText ();
-       }
-}
-<lyric_quote>{
+<quote,lyric_quote>{
        \\{ESCAPED}     {
                *yylval.string += to_string (escaped_char (YYText ()[1]));
        }
@@ -404,7 +413,7 @@ BOM_UTF8    \357\273\277
                string *sp = yylval.string;
                yylval.scm = scm_makfrom0str (sp->c_str ());
                delete sp;
-               return LYRICS_STRING;
+               return is_lyric_state () ? LYRICS_STRING : STRING;
        }
        .       {
                *yylval.string += YYText ();
@@ -463,9 +472,6 @@ BOM_UTF8    \357\273\277
                yylval.i = String_convert::dec2int (string (YYText ()));
                return UNSIGNED;
        }
-       \" {
-               start_quote ();
-       }
        -  {
                return CHORD_MINUS;
        }
@@ -488,9 +494,6 @@ BOM_UTF8    \357\273\277
 
 
 <markup>{
-       \" {
-               start_quote ();
-       }
        \\score {
                return SCORE;
        }
@@ -548,7 +551,7 @@ BOM_UTF8    \357\273\277
        }
 }
 
-<<EOF>> {
+<*><<EOF>> {
        if (is_main_input_)
        {
                is_main_input_ = false;
@@ -811,8 +814,7 @@ strip_trailing_white (string&s)
 
 
 
-/* 2.1.2x something -> \property -> \set. */ 
-Lilypond_version oldest_version ("2.3.22");
+Lilypond_version oldest_version ("2.7.38");
 
 
 bool
@@ -879,74 +881,57 @@ lookup_markup_command (string s)
        return scm_call_1 (proc, scm_makfrom0str (s.c_str ()));
 }
 
+struct Parser_signature
+{
+       char *symbol;
+       int token_type;
+};
+static SCM signature_hash_table;
+
+static void init_signature_hash_table ()
+{
+       signature_hash_table = scm_gc_protect_object (scm_c_make_hash_table (31));
+       Parser_signature sigs[]  = {
+               {"scm", MUSIC_FUNCTION_SCM},
+               {"music", MUSIC_FUNCTION_MUSIC},
+               {"scm-music", MUSIC_FUNCTION_SCM_MUSIC},
+               {"scm-scm", MUSIC_FUNCTION_SCM_SCM},
+               {"music-music", MUSIC_FUNCTION_MUSIC_MUSIC},
+               {"scm-music-music", MUSIC_FUNCTION_SCM_MUSIC_MUSIC},
+               {"scm-scm-music-music", MUSIC_FUNCTION_SCM_SCM_MUSIC_MUSIC},
+               {"scm-scm-music", MUSIC_FUNCTION_SCM_SCM_MUSIC},
+               {"scm-scm-scm-music", MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC},
+               {"scm-scm-scm-scm-music", MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC},
+               {"scm-scm-scm", MUSIC_FUNCTION_SCM_SCM_SCM},
+               {"markup", MUSIC_FUNCTION_MARKUP},
+               {"markup-music", MUSIC_FUNCTION_MARKUP_MUSIC},
+               {"markup-markup", MUSIC_FUNCTION_MARKUP_MARKUP},
+               {"markup-music-music", MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC},
+               {"markup-markup-music", MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC},
+               {"noarg", MUSIC_FUNCTION},
+               {0,0}
+       };
+
+       for (int i = 0; sigs[i].symbol; i++)
+               scm_hashq_set_x (signature_hash_table, ly_symbol2scm (sigs[i].symbol),
+                                scm_from_int (sigs[i].token_type));
+}
 
 int
 music_function_type (SCM func)
 {
+       if (!signature_hash_table)
+               init_signature_hash_table ();
+
        SCM type = scm_object_property (func, ly_symbol2scm ("music-function-signature-keyword"));
-       if (type == ly_symbol2scm ("scm"))
-       {
-               return MUSIC_FUNCTION_SCM;
-       }
-       else if (type == ly_symbol2scm ("music"))
-       {
-               return MUSIC_FUNCTION_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("scm-music"))
-       {
-               return MUSIC_FUNCTION_SCM_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("scm-scm"))
-       {
-               return MUSIC_FUNCTION_SCM_SCM;
-       }
-       else if (type == ly_symbol2scm ("music-music"))
-       {
-               return MUSIC_FUNCTION_MUSIC_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("scm-music-music"))
-       {
-               return MUSIC_FUNCTION_SCM_MUSIC_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("scm-scm-music"))
-       {
-               return MUSIC_FUNCTION_SCM_SCM_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("scm-scm-scm"))
-       {
-               return MUSIC_FUNCTION_SCM_SCM_SCM;
-       }
-       else if (type == ly_symbol2scm ("markup"))
-       {
-               return MUSIC_FUNCTION_MARKUP;
-       }
-       else if (type == ly_symbol2scm ("markup-music"))
-       {
-               return MUSIC_FUNCTION_MARKUP_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("markup-markup"))
-       {
-               return MUSIC_FUNCTION_MARKUP_MARKUP;
-       }
-       else if (type == ly_symbol2scm ("markup-music-music"))
-       {
-               return MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("markup-markup-music"))
-       {
-               return MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("noarg"))
-       {
-               return MUSIC_FUNCTION;
-       }
-       else
+       SCM token_type = scm_hashq_ref (signature_hash_table, type, SCM_BOOL_F);
+       if (!scm_is_number (token_type))
                {
-               /* TODO: print location */
-               error (_ ("can't find signature for music function"));
+               programming_error (_ ("can't find signature for music function"));
+               return MUSIC_FUNCTION_SCM;
                }
-
-       return MUSIC_FUNCTION_SCM;
+       
+       return scm_to_int (token_type);
 }
 
 /* Shut up lexer warnings.  */