2
0
Эх сурвалжийг харах

some changes in error reporting

Roberto Ierusalimschy 22 жил өмнө
parent
commit
30e51f09b9
1 өөрчлөгдсөн 24 нэмэгдсэн , 30 устгасан
  1. 24 30
      llex.c

+ 24 - 30
llex.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: llex.c,v 1.123 2003/08/28 14:38:46 roberto Exp roberto $
+** $Id: llex.c,v 1.124 2003/08/29 16:48:14 roberto Exp roberto $
 ** Lexical Analyzer
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -77,42 +77,37 @@ static void luaX_error (LexState *ls, const char *s, const char *token) {
 }
 }
 
 
 
 
-void luaX_syntaxerror (LexState *ls, const char *msg) {
-  const char *lasttoken;
-  switch (ls->t.token) {
+const char *luaX_token2str (LexState *ls, int token) {
+  if (token < FIRST_RESERVED) {
+    lua_assert(token == (unsigned char)token);
+    return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) :
+                              luaO_pushfstring(ls->L, "%c", token);
+  }
+  else
+    return token2string[token-FIRST_RESERVED];
+}
+
+
+static const char *txtToken (LexState *ls, int token) {
+  switch (token) {
     case TK_NAME:
     case TK_NAME:
-      lasttoken = getstr(ls->t.seminfo.ts);
-      break;
     case TK_STRING:
     case TK_STRING:
     case TK_NUMBER:
     case TK_NUMBER:
       save(ls, '\0');
       save(ls, '\0');
-      lasttoken = luaZ_buffer(ls->buff);
-      break;
+      return luaZ_buffer(ls->buff);
     default:
     default:
-      lasttoken = luaX_token2str(ls, ls->t.token);
-      break;
+      return luaX_token2str(ls, token);
   }
   }
-  luaX_error(ls, msg, lasttoken);
 }
 }
 
 
 
 
-const char *luaX_token2str (LexState *ls, int token) {
-  if (token < FIRST_RESERVED) {
-    lua_assert(token == (unsigned char)token);
-    return luaO_pushfstring(ls->L, "%c", token);
-  }
-  else
-    return token2string[token-FIRST_RESERVED];
+static void luaX_lexerror (LexState *ls, const char *msg, int token) {
+    luaX_error(ls, msg, txtToken(ls, token));
 }
 }
 
 
 
 
-static void luaX_lexerror (LexState *ls, const char *s, int token) {
-  if (token == TK_EOS)
-    luaX_error(ls, s, luaX_token2str(ls, token));
-  else {
-    save(ls, '\0');
-    luaX_error(ls, s, luaZ_buffer(ls->buff));
-  }
+void luaX_syntaxerror (LexState *ls, const char *msg) {
+  luaX_lexerror(ls, msg, ls->t.token);
 }
 }
 
 
 
 
@@ -406,14 +401,13 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) {
                                   luaZ_bufflen(ls->buff));
                                   luaZ_bufflen(ls->buff));
           if (ts->tsv.reserved > 0)  /* reserved word? */
           if (ts->tsv.reserved > 0)  /* reserved word? */
             return ts->tsv.reserved - 1 + FIRST_RESERVED;
             return ts->tsv.reserved - 1 + FIRST_RESERVED;
-          seminfo->ts = ts;
-          return TK_NAME;
+          else {
+            seminfo->ts = ts;
+            return TK_NAME;
+          }
         }
         }
         else {
         else {
           int c = ls->current;
           int c = ls->current;
-          if (iscntrl(c))
-            luaX_error(ls, "invalid control char",
-                           luaO_pushfstring(ls->L, "char(%d)", c));
           next(ls);
           next(ls);
           return c;  /* single-char tokens (+ - / ...) */
           return c;  /* single-char tokens (+ - / ...) */
         }
         }