more regularity in the use of quotes in error messages

This commit is contained in:
Roberto Ierusalimschy 2007-02-07 15:49:18 -02:00
parent 593bfc9668
commit 92dc64e121
3 changed files with 21 additions and 21 deletions

24
llex.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: llex.c,v 2.22 2006/08/30 13:19:58 roberto Exp roberto $ ** $Id: llex.c,v 2.23 2006/09/18 16:06:41 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -34,14 +34,13 @@
/* ORDER RESERVED */ /* ORDER RESERVED */
const char *const luaX_tokens [] = { static const char *const luaX_tokens [] = {
"and", "break", "do", "else", "elseif", "and", "break", "do", "else", "elseif",
"end", "false", "for", "function", "if", "end", "false", "for", "function", "if",
"in", "local", "nil", "not", "or", "repeat", "in", "local", "nil", "not", "or", "repeat",
"return", "then", "true", "until", "while", "return", "then", "true", "until", "while",
"..", "...", "==", ">=", "<=", "~=", "..", "...", "==", ">=", "<=", "~=", "<eof>",
"<number>", "<name>", "<string>", "<eof>", "<number>", "<name>", "<string>"
NULL
}; };
@ -79,10 +78,15 @@ const char *luaX_token2str (LexState *ls, int token) {
if (token < FIRST_RESERVED) { if (token < FIRST_RESERVED) {
lua_assert(token == cast(unsigned char, token)); lua_assert(token == cast(unsigned char, token));
return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) :
luaO_pushfstring(ls->L, "%c", token); luaO_pushfstring(ls->L, LUA_QL("%c"), token);
}
else {
const char *s = luaX_tokens[token - FIRST_RESERVED];
if (token < TK_EOS)
return luaO_pushfstring(ls->L, LUA_QS, s);
else
return s;
} }
else
return luaX_tokens[token-FIRST_RESERVED];
} }
@ -92,7 +96,7 @@ static const char *txtToken (LexState *ls, int token) {
case TK_STRING: case TK_STRING:
case TK_NUMBER: case TK_NUMBER:
save(ls, '\0'); save(ls, '\0');
return luaZ_buffer(ls->buff); return luaO_pushfstring(ls->L, LUA_QS, luaZ_buffer(ls->buff));
default: default:
return luaX_token2str(ls, token); return luaX_token2str(ls, token);
} }
@ -104,7 +108,7 @@ void luaX_lexerror (LexState *ls, const char *msg, int token) {
luaO_chunkid(buff, getstr(ls->source), MAXSRC); luaO_chunkid(buff, getstr(ls->source), MAXSRC);
msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
if (token) if (token)
luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token)); luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
luaD_throw(ls->L, LUA_ERRSYNTAX); luaD_throw(ls->L, LUA_ERRSYNTAX);
} }

10
llex.h
View File

@ -1,5 +1,5 @@
/* /*
** $Id: llex.h,v 1.57 2005/12/07 15:43:05 roberto Exp roberto $ ** $Id: llex.h,v 1.58 2006/03/23 18:23:32 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -28,18 +28,14 @@ enum RESERVED {
TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
/* other terminal symbols */ /* other terminal symbols */
TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_EOS,
TK_NAME, TK_STRING, TK_EOS TK_NUMBER, TK_NAME, TK_STRING
}; };
/* number of reserved words */ /* number of reserved words */
#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
/* array with token `names' */
LUAI_DATA const char *const luaX_tokens [];
typedef union { typedef union {
lua_Number r; lua_Number r;
TString *ts; TString *ts;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lparser.c,v 2.49 2006/10/24 13:31:48 roberto Exp roberto $ ** $Id: lparser.c,v 2.50 2006/11/22 11:02:03 roberto Exp roberto $
** Lua Parser ** Lua Parser
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -64,7 +64,7 @@ static void anchor_token (LexState *ls) {
static void error_expected (LexState *ls, int token) { static void error_expected (LexState *ls, int token) {
luaX_syntaxerror(ls, luaX_syntaxerror(ls,
luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token))); luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token)));
} }
@ -109,7 +109,7 @@ static void check_match (LexState *ls, int what, int who, int where) {
error_expected(ls, what); error_expected(ls, what);
else { else {
luaX_syntaxerror(ls, luaO_pushfstring(ls->L, luaX_syntaxerror(ls, luaO_pushfstring(ls->L,
LUA_QS " expected (to close " LUA_QS " at line %d)", "%s expected (to close %s at line %d)",
luaX_token2str(ls, what), luaX_token2str(ls, who), where)); luaX_token2str(ls, what), luaX_token2str(ls, who), where));
} }
} }
@ -734,7 +734,7 @@ static void primaryexp (LexState *ls, expdesc *v) {
static void simpleexp (LexState *ls, expdesc *v) { static void simpleexp (LexState *ls, expdesc *v) {
/* simpleexp -> NUMBER | STRING | NIL | true | false | ... | /* simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... |
constructor | FUNCTION body | primaryexp */ constructor | FUNCTION body | primaryexp */
switch (ls->t.token) { switch (ls->t.token) {
case TK_NUMBER: { case TK_NUMBER: {