瀏覽代碼

ctype 'lalpha' includes '_' (as '_' behaves as a letter from the
point of view of Lua)

Roberto Ierusalimschy 16 年之前
父節點
當前提交
6ffcf21367
共有 3 個文件被更改,包括 11 次插入9 次删除
  1. 2 2
      lctype.c
  2. 5 3
      lctype.h
  3. 4 4
      llex.c

+ 2 - 2
lctype.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lctype.c,v 1.2 2009/02/20 13:11:15 roberto Exp roberto $
+** $Id: lctype.c,v 1.3 2009/03/10 17:42:33 roberto Exp roberto $
 ** 'ctype' functions for Lua
 ** See Copyright Notice in lua.h
 */
@@ -20,7 +20,7 @@ const char luai_ctype_[UCHAR_MAX + 1] = {
   0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,
   0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
   0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
-  0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x04,
+  0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x05,
   0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,
   0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
   0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,

+ 5 - 3
lctype.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lctype.h,v 1.2 2009/02/20 13:11:15 roberto Exp roberto $
+** $Id: lctype.h,v 1.3 2009/03/10 17:42:33 roberto Exp roberto $
 ** 'ctype' functions for Lua
 ** See Copyright Notice in lua.h
 */
@@ -23,8 +23,10 @@
 #define MASK(B)		(1 << (B))
 
 
-#define lisalpha(x)	(luai_ctype_[x] & MASK(ALPHABIT))
-#define lisalnum(x)	(luai_ctype_[x] & (MASK(ALPHABIT) | MASK(DIGITBIT)))
+/* 'lalpha' (Lua alphabetic) includes '_' */
+#define lislalpha(x)	(luai_ctype_[x] & MASK(ALPHABIT))
+/* ditto */
+#define lislalnum(x)	(luai_ctype_[x] & (MASK(ALPHABIT) | MASK(DIGITBIT)))
 #define lisdigit(x)	(luai_ctype_[x] & MASK(DIGITBIT))
 #define lisspace(x)	(luai_ctype_[x] & MASK(SPACEBIT))
 #define lisprint(x)	(luai_ctype_[x] & MASK(PRINTBIT))

+ 4 - 4
llex.c

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.c,v 2.30 2009/02/11 18:25:20 roberto Exp roberto $
+** $Id: llex.c,v 2.31 2009/02/19 17:18:25 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -206,7 +206,7 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) {
   } while (lisdigit(ls->current) || ls->current == '.');
   if (check_next(ls, "Ee"))  /* `E'? */
     check_next(ls, "+-");  /* optional exponent sign */
-  while (lisalnum(ls->current) || ls->current == '_')
+  while (lislalnum(ls->current))
     save_and_next(ls);
   save(ls, '\0');
   buffreplace(ls, '.', ls->decpoint);  /* follow locale for decimal point */
@@ -408,12 +408,12 @@ static int llex (LexState *ls, SemInfo *seminfo) {
           read_numeral(ls, seminfo);
           return TK_NUMBER;
         }
-        else if (lisalpha(ls->current) || ls->current == '_') {
+        else if (lislalpha(ls->current)) {
           /* identifier or reserved word */
           TString *ts;
           do {
             save_and_next(ls);
-          } while (lisalnum(ls->current) || ls->current == '_');
+          } while (lislalnum(ls->current));
           ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
                                   luaZ_bufflen(ls->buff));
           if (ts->tsv.reserved > 0)  /* reserved word? */