]> git.donarmstrong.com Git - lilypond.git/commitdiff
parser.yy: make is_regular_identifier match the lexer definition
authorDavid Kastrup <dak@gnu.org>
Thu, 4 Oct 2012 15:11:25 +0000 (17:11 +0200)
committerDavid Kastrup <dak@gnu.org>
Thu, 25 Oct 2012 18:29:26 +0000 (20:29 +0200)
is_regular_identifier checks now for valid identifiers employing the
definition of words that is also used in the lexer: letters, and
characters outside of the ASCII range, interspersed with single - and
_ characters.

lily/parser.yy

index d6dcf11cc4a053ec646df883e7f190fc3f827402..3fda84232f7c9b928f56cf44bc3063462f5ab33f 100644 (file)
@@ -3199,19 +3199,22 @@ bool
 is_regular_identifier (SCM id)
 {
   string str = ly_scm2string (id);
-  char const *s = str.c_str ();
 
-  bool v = true;
-#if 0
-  isalpha (*s);
-  s++;
-#endif
-  while (*s && v)
-   {
-        v = v && isalnum (*s);
-        s++;
-   }
-  return v;
+  bool middle = false;
+
+  for (string::iterator it=str.begin(); it != str.end (); it++)
+  {
+         int c = *it & 0xff;
+         if ((c >= 'a' && c <= 'z')
+             || (c >= 'A' && c <= 'Z')
+             || c > 0x7f)
+                 middle = true;
+         else if (middle && (c == '-' || c == '_'))
+                 middle = false;
+         else
+                 return false;
+  }
+  return middle;
 }
 
 SCM