]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lexer.ll
release: 1.3.142
[lilypond.git] / lily / lexer.ll
index e271bb1ada28c3628b4334c6155d00869cd2eaa4..7deca514b0a9e5aebb3944ebba3e64f7ffcc3173 100644 (file)
@@ -18,7 +18,7 @@
       lex.backup
   contains no backup states, but only the reminder
       Compressed tables always back up.
 (don-t forget to rm lex.yy.cc :-)
+ (don-t forget to rm lex.yy.cc :-)
  */
 
 
@@ -49,6 +49,7 @@ RH 7 fix (?)
 
 void strip_trailing_white (String&);
 void strip_leading_white (String&);
+String lyric_fudge (String s);
 
 
 bool
@@ -60,7 +61,8 @@ valid_version_b (String s);
        yy_push_state (quote);\
        yylval.string = new String
 
-#define yylval (*(YYSTYPE*)lexval_l)
+#define yylval \
+       (*(YYSTYPE*)lexval_l)
 
 #define YY_USER_ACTION add_lexed_char (YYLeng ());
 /*
@@ -95,7 +97,7 @@ N             [0-9]
 AN             {AA}|{N}
 PUNCT          [?!:']
 ACCENT         \\[`'"^]
-NATIONAL  [\001-\006\021-\027\031\036\200-\377]
+NATIONAL       [\001-\006\021-\027\031\036\200-\377]
 TEX            {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL}
 WORD           {A}{AN}*
 ALPHAWORD      {A}+
@@ -282,7 +284,7 @@ HYPHEN              --
 }
 <quote>{
        \\{ESCAPED}     {
-               *yylval.string += to_str (escaped_char(YYText()[1]));
+               *yylval.string += to_str (escaped_char (YYText ()[1]));
        }
        [^\\"]+ {
                *yylval.string += YYText ();
@@ -293,7 +295,7 @@ HYPHEN              --
 
                /* yylval is union. Must remember STRING before setting SCM*/
                String *sp = yylval.string;
-               yylval.scm = ly_str02scm  (sp->ch_C ());
+               yylval.scm = ly_str02scm (sp->ch_C ());
                delete sp;
                return STRING;
        }
@@ -320,19 +322,12 @@ HYPHEN            --
                        return yylval.i = EXTENDER;
                if (s == "--")
                        return yylval.i = HYPHEN;
-               int i = 0;
-                       while ((i=s.index_i ("_")) != -1) // change word binding "_" to " "
-                       *(s.ch_l () + i) = ' ';
-               if ((i=s.index_i ("\\,")) != -1)   // change "\," to TeX's "\c "
-                       {
-                       *(s.ch_l () + i + 1) = 'c';
-                       s = s.left_str (i+2) + " " + s.right_str (s.length_i ()-i-2);
-                       }
+               s = lyric_fudge (s);
 
                char c = s[s.length_i () - 1];
                if (c == '{' ||  c == '}') // brace open is for not confusing dumb tools.
                        here_input ().warning (
-                               _("Brace found at end of lyric. Did you forget a space?"));
+                               _ ("Brace found at end of lyric. Did you forget a space?"));
                yylval.scm = ly_str02scm (s.ch_C ());
 
                DEBUG_OUT << "lyric : `" << s << "'\n";
@@ -472,7 +467,7 @@ My_lily_lexer::scan_escaped_word (String str)
 {
        // use more SCM for this.
 
-       SCM sym = ly_symbol2scm (str.ch_C());
+       SCM sym = ly_symbol2scm (str.ch_C ());
 
        int l = lookup_keyword (str);
        if (l != -1) {
@@ -520,7 +515,7 @@ My_lily_lexer::scan_escaped_word (String str)
        String msg (_f ("unknown escaped string: `\\%s'", str));        
        LexerError (msg.ch_C ());
 
-       yylval.scm = ly_str02scm(str.ch_C());
+       yylval.scm = ly_str02scm (str.ch_C ());
 
        return STRING;
 }
@@ -541,7 +536,7 @@ My_lily_lexer::scan_bare_word (String str)
                }
        }
 
-       yylval.scm = ly_str02scm (str.ch_C());
+       yylval.scm = ly_str02scm (str.ch_C ());
        return STRING;
 }
 
@@ -564,7 +559,7 @@ My_lily_lexer::lyric_state_b () const
 }
 
 /*
- urg, belong to String(_convert)
+ urg, belong to String (_convert)
  and should be generalised 
  */
 void
@@ -597,12 +592,36 @@ valid_version_b (String s)
 {
   Lilypond_version current ( MAJOR_VERSION "." MINOR_VERSION "." PATCH_LEVEL );
   Lilypond_version ver (s);
-  if (!((ver >= oldest_version) && (ver <= current)))
+  if (! ((ver >= oldest_version) && (ver <= current)))
        {       
                non_fatal_error (_f ("incorrect lilypond version: %s (%s, %s)", ver.str (), oldest_version.str (), current.str ()));
-               non_fatal_error (_("Consider converting the input with the convert-ly script")); 
+               non_fatal_error (_ ("Consider converting the input with the convert-ly script")); 
                return false;
     }
   return true;
 }
        
+
+String
+lyric_fudge (String s)
+{
+  char  * chars  =s.copy_ch_p ();
+
+  for (char * p = chars; *p ; p++)
+    {
+      if (*p == '_' && (p == chars || *(p-1) != '\\'))
+       *p = ' ';
+    }
+  
+  s = String (chars);
+  delete[] chars;
+
+  int i =0;    
+  if ((i=s.index_i ("\\,")) != -1)   // change "\," to TeX's "\c "
+    {
+      * (s.ch_l () + i + 1) = 'c';
+      s = s.left_str (i+2) + " " + s.right_str (s.length_i ()-i-2);
+    }
+
+  return s;
+}