]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lexer.ll
Doc-fr: NR spacing Nitpicks
[lilypond.git] / lily / lexer.ll
index 86375177cf125019f7eb086397f71eb3abd12f1c..2ef59f43f5243618951de8eb6d4c0ea90b23b03f 100644 (file)
@@ -47,7 +47,6 @@ using namespace std;
 
 #include "context-def.hh"
 #include "duration.hh"
-#include "identifier-smob.hh"
 #include "international.hh"
 #include "interval.hh"
 #include "lily-guile.hh"
@@ -312,7 +311,7 @@ BOM_UTF8    \357\273\277
 <INITIAL,chords,lyrics,figures,notes>\\include           {
        yy_push_state (incl);
 }
-<incl>\"[^"]*\"   { /* got the include file name */
+<incl>\"[^""]*\"   { /* got the include file name */
        string s (YYText ()+1);
        s = s.substr (0, s.rfind ('"'));
 
@@ -329,7 +328,7 @@ BOM_UTF8    \357\273\277
        if (scm_is_string (sid)) {
                new_input (ly_scm2string (sid), sources_);
                yy_pop_state ();
-       } else { 
+       } else {
            string msg (_f ("wrong or undefined identifier: `%s'", s ));
 
            LexerError (msg.c_str ());
@@ -338,7 +337,34 @@ BOM_UTF8   \357\273\277
            scm_display (sid, err);
          }
 }
-<incl,version,sourcefilename>\"[^"]*   { // backup rule
+<incl>(\$|#) { // scm for the filename
+       int n = 0;
+       Input hi = here_input();
+       hi.step_forward ();
+       SCM sval = ly_parse_scm (hi.start (), &n, hi,
+               be_safe_global && is_main_input_, parser_);
+       sval = eval_scm (sval);
+
+       for (int i = 0; i < n; i++)
+       {
+               yyinput ();
+       }
+       char_count_stack_.back () += n;
+
+       if (scm_is_string (sval)) {
+               new_input (ly_scm2string (sval), sources_);
+               yy_pop_state ();
+       } else {
+               LexerError (_ ("string expected after \\include").c_str ());
+               if (sval != SCM_UNDEFINED) {
+                       SCM err = scm_current_error_port ();
+                       scm_puts ("This value was found instead: ", err);
+                       scm_display (sval, err);
+               }
+       }
+}
+
+<incl,version,sourcefilename>\"[^""]*   { // backup rule
        error (_ ("end quote missing"));
        exit (1);
 }
@@ -358,10 +384,7 @@ BOM_UTF8   \357\273\277
                be_safe_global && is_main_input_, parser_);
 
        if (sval == SCM_UNDEFINED)
-       {
-               sval = SCM_UNSPECIFIED;
                error_level_ = 1;
-       }
 
        for (int i = 0; i < n; i++)
        {
@@ -369,20 +392,30 @@ BOM_UTF8  \357\273\277
        }
        char_count_stack_.back () += n;
 
-       if (unpack_identifier (sval) != SCM_UNDEFINED)
+       yylval.scm = sval;
+       return SCM_TOKEN;
+}
+
+<INITIAL,chords,figures,lyrics,markup,notes>\$ { //immediate scm
+       int n = 0;
+       Input hi = here_input();
+       hi.step_forward ();
+       SCM sval = ly_parse_scm (hi.start (), &n, hi,
+               be_safe_global && is_main_input_, parser_);
+
+       for (int i = 0; i < n; i++)
        {
-               yylval.scm = unpack_identifier(sval);
-               return identifier_type (yylval.scm);
+               yyinput ();
        }
+       char_count_stack_.back () += n;
 
-       for (size_t i = 0; i < pending_string_includes_.size (); i++)
-               new_input ("<included string>", pending_string_includes_[i],
-                          parser_->sources_);
-       pending_string_includes_.clear ();
+       sval = eval_scm (sval);
                
-       yylval.scm = sval;
-       return SCM_TOKEN;
+       int token = scan_scm_id (sval);
+       if (!scm_is_eq (yylval.scm, SCM_UNSPECIFIED))
+         return token;
 }
+
 <INITIAL,notes,lyrics>{ 
        \<\<    {
                return DOUBLE_ANGLE_OPEN;
@@ -427,7 +460,7 @@ BOM_UTF8    \357\273\277
        }
        {UNSIGNED}/\/   | // backup rule
        {UNSIGNED}              {
-               yylval.i = String_convert::dec2int (string (YYText ()));
+               yylval.scm = scm_c_read_string (YYText ());
                return UNSIGNED;
        }
        {E_UNSIGNED}    {
@@ -467,12 +500,12 @@ BOM_UTF8  \357\273\277
                return FRACTION;
        }
        {UNSIGNED}/\/[^0-9] { // backup rule
-               yylval.i = String_convert::dec2int (string (YYText ()));
+               yylval.scm = scm_c_read_string (YYText ());
                return UNSIGNED;
        }
        {UNSIGNED}/\/   | // backup rule
        {UNSIGNED}              {
-               yylval.i = String_convert::dec2int (string (YYText ()));
+               yylval.scm = scm_c_read_string (YYText ());
                return UNSIGNED;
        }
        {NOTECOMMAND}   {
@@ -512,12 +545,12 @@ BOM_UTF8  \357\273\277
                return FRACTION;
        }
        {UNSIGNED}/\/[^0-9] { // backup rule
-               yylval.i = String_convert::dec2int (string (YYText ()));
+               yylval.scm = scm_c_read_string (YYText ());
                return UNSIGNED;
        }
        {UNSIGNED}/\/   | // backup rule
        {UNSIGNED}              {
-               yylval.i = String_convert::dec2int (string (YYText ()));
+               yylval.scm = scm_c_read_string (YYText ());
                return UNSIGNED;
        }
        -  {
@@ -598,7 +631,7 @@ BOM_UTF8    \357\273\277
        [{}]    {
                return YYText ()[0];
        }
-       [^#{}\"\\ \t\n\r\f]+ {
+       [^$#{}\"\\ \t\n\r\f]+ {
                string s (YYText ()); 
 
                char c = s[s.length () - 1];
@@ -659,7 +692,7 @@ BOM_UTF8    \357\273\277
 }
 
 {UNSIGNED}     {
-       yylval.i = String_convert::dec2int (string (YYText ()));
+       yylval.scm = scm_c_read_string (YYText ());
        return UNSIGNED;
 }
 
@@ -799,6 +832,20 @@ Lily_lexer::scan_escaped_word (string str)
                return i;
 
        SCM sid = lookup_identifier (str);
+       if (sid != SCM_UNDEFINED)
+               return scan_scm_id (sid);
+
+       string msg (_f ("unknown escaped string: `\\%s'", str));        
+       LexerError (msg.c_str ());
+
+       yylval.scm = ly_string2scm (str);
+
+       return STRING;
+}
+
+int
+Lily_lexer::scan_scm_id (SCM sid)
+{
        if (is_music_function (sid))
        {
                int funtype = SCM_FUNCTION;
@@ -833,9 +880,7 @@ Lily_lexer::scan_escaped_word (string str)
                                cs = SCM_CAR (cs);
                        }
                        
-                       if (cs == ly_music_p_proc)
-                               push_extra_token (EXPECT_MUSIC);
-                       else if (cs == Pitch_type_p_proc)
+                       if (cs == Pitch_type_p_proc)
                                push_extra_token (EXPECT_PITCH);
                        else if (cs == Duration_type_p_proc)
                                push_extra_token (EXPECT_DURATION);
@@ -851,19 +896,8 @@ Lily_lexer::scan_escaped_word (string str)
                }
                return funtype;
        }
-
-       if (sid != SCM_UNDEFINED)
-       {
-               yylval.scm = sid;
-               return identifier_type (sid);
-       }
-
-       string msg (_f ("unknown escaped string: `\\%s'", str));        
-       LexerError (msg.c_str ());
-
-       yylval.scm = ly_string2scm (str);
-
-       return STRING;
+       yylval.scm = sid;
+       return identifier_type (sid);
 }
 
 int
@@ -930,6 +964,29 @@ Lily_lexer::is_figure_state () const
        return get_state () == figures;
 }
 
+SCM
+Lily_lexer::eval_scm (SCM readerdata)
+{
+       SCM sval = SCM_UNDEFINED;
+
+       if (!SCM_UNBNDP (readerdata))
+       {
+               sval = ly_eval_scm (scm_car (readerdata),
+                                   *unsmob_input (scm_cdr (readerdata)),
+                                   be_safe_global && is_main_input_,
+                                   parser_);
+       }
+
+       if (SCM_UNBNDP (sval))
+       {
+               error_level_ = 1;
+               return SCM_UNSPECIFIED;
+       }
+       return sval;
+}
+
+
+
 /*
  urg, belong to string (_convert)
  and should be generalised