lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 03/16] parser.yy: make is_regular_identifier match the lexer defi


From: David Kastrup
Subject: [PATCH 03/16] parser.yy: make is_regular_identifier match the lexer definition
Date: Tue, 9 Oct 2012 20:59:48 +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 |   27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/lily/parser.yy b/lily/parser.yy
index d6dcf11..3fda842 100644
--- a/lily/parser.yy
+++ b/lily/parser.yy
@@ -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
-- 
1.7.9.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]