mirror of
https://github.com/lua/lua
synced 2024-11-22 12:51:30 +03:00
more regularity in the use of quotes in error messages
This commit is contained in:
parent
593bfc9668
commit
92dc64e121
24
llex.c
24
llex.c
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -34,14 +34,13 @@
|
||||
|
||||
|
||||
/* ORDER RESERVED */
|
||||
const char *const luaX_tokens [] = {
|
||||
static const char *const luaX_tokens [] = {
|
||||
"and", "break", "do", "else", "elseif",
|
||||
"end", "false", "for", "function", "if",
|
||||
"in", "local", "nil", "not", "or", "repeat",
|
||||
"return", "then", "true", "until", "while",
|
||||
"..", "...", "==", ">=", "<=", "~=",
|
||||
"<number>", "<name>", "<string>", "<eof>",
|
||||
NULL
|
||||
"..", "...", "==", ">=", "<=", "~=", "<eof>",
|
||||
"<number>", "<name>", "<string>"
|
||||
};
|
||||
|
||||
|
||||
@ -79,10 +78,15 @@ const char *luaX_token2str (LexState *ls, int token) {
|
||||
if (token < FIRST_RESERVED) {
|
||||
lua_assert(token == cast(unsigned char, 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_NUMBER:
|
||||
save(ls, '\0');
|
||||
return luaZ_buffer(ls->buff);
|
||||
return luaO_pushfstring(ls->L, LUA_QS, luaZ_buffer(ls->buff));
|
||||
default:
|
||||
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);
|
||||
msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
|
||||
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);
|
||||
}
|
||||
|
||||
|
10
llex.h
10
llex.h
@ -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
|
||||
** 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_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
|
||||
/* other terminal symbols */
|
||||
TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
|
||||
TK_NAME, TK_STRING, TK_EOS
|
||||
TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_EOS,
|
||||
TK_NUMBER, TK_NAME, TK_STRING
|
||||
};
|
||||
|
||||
/* number of reserved words */
|
||||
#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
|
||||
|
||||
|
||||
/* array with token `names' */
|
||||
LUAI_DATA const char *const luaX_tokens [];
|
||||
|
||||
|
||||
typedef union {
|
||||
lua_Number r;
|
||||
TString *ts;
|
||||
|
@ -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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -64,7 +64,7 @@ static void anchor_token (LexState *ls) {
|
||||
|
||||
static void error_expected (LexState *ls, int token) {
|
||||
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);
|
||||
else {
|
||||
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));
|
||||
}
|
||||
}
|
||||
@ -734,7 +734,7 @@ static void primaryexp (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 */
|
||||
switch (ls->t.token) {
|
||||
case TK_NUMBER: {
|
||||
|
Loading…
Reference in New Issue
Block a user