]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lexer.ll
lexer.ll: remove old and buggy TeX cruft
[lilypond.git] / lily / lexer.ll
index 1a79dbdec85fe943fa7137c0f5ec3931ad18ce4c..ce3bf9c5166d721db1e0b5d6d4fb937d8938020d 100644 (file)
@@ -1,4 +1,4 @@
-%{ // -*-Fundamental-*-
+%{ // -*- mode: c++; c-file-style: "linux" -*-
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+/* Mode and indentation are at best a rough approximation based on TAB
+ * formatting (reasonable for compatibility with unspecific editor
+ * modes as Flex modes are hard to find) and need manual correction
+ * frequently.  Without a reasonably dependable way of formatting a
+ * Flex file sensibly, there is little point in trying to fix the
+ * inconsistent state of indentation.
+ */
+
 /*
   backup rules
 
@@ -86,11 +94,9 @@ bool is_valid_version (string s);
        yy_push_state (lyric_quote);\
        yylval.string = new string
 
-#define yylval \
-       (*(YYSTYPE*)lexval_)
+#define yylval (*lexval_)
 
-#define yylloc \
-       (*(YYLTYPE*)lexloc_)
+#define yylloc (*lexloc_)
 
 #define YY_USER_ACTION add_lexed_char (YYLeng ());
 
@@ -311,7 +317,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 ('"'));
 
@@ -328,7 +334,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 ());
@@ -337,7 +343,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);
 }
@@ -365,11 +398,6 @@ BOM_UTF8   \357\273\277
        }
        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 ();
-               
        yylval.scm = sval;
        return SCM_TOKEN;
 }
@@ -380,7 +408,6 @@ BOM_UTF8    \357\273\277
        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++)
        {
@@ -388,7 +415,11 @@ BOM_UTF8   \357\273\277
        }
        char_count_stack_.back () += n;
 
-       return scan_scm_id (sval);
+       sval = eval_scm (sval);
+               
+       int token = scan_scm_id (sval);
+       if (!scm_is_eq (yylval.scm, SCM_UNSPECIFIED))
+         return token;
 }
 
 <INITIAL,notes,lyrics>{ 
@@ -1015,30 +1046,18 @@ is_valid_version (string s)
        
 
 /*
-  substitute _ and \,
+  substitute _
 */
 string
 lyric_fudge (string s)
 {
-  char *chars = string_copy (s);
+       size_t i=0;
 
-  for (char *p = chars; *p ; p++)
-    {
-      if (*p == '_' && (p == chars || *(p-1) != '\\'))
-       *p = ' ';
-    }
-  
-  s = string (chars);
-  delete[] chars;
-
-  ssize i = 0; 
-  if ((i = s.find ("\\,")) != NPOS)   // change "\," to TeX's "\c "
-    {
-      * (((char*)s.c_str ()) + i + 1) = 'c';
-      s = s.substr (0, i + 2) + " " + s.substr (i - 2);
-    }
-
-  return s;
+       while ((i = s.find ('_', i)) != string::npos)
+       {
+               s[i++] = ' ';
+       }
+       return s;
 }
 
 /*