diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-03-12 16:53:56 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-03-12 16:53:56 -0300 |
commit | a003e891252a2f6b4b7d1d006b20d2b306626caa (patch) | |
tree | b4ca1f1a192713897aa40d0248178f7d2cb8b367 /llex.c | |
parent | b876ec61c03e05ea0c4c02d8ad8abb84cf55e87c (diff) | |
download | lua-github-a003e891252a2f6b4b7d1d006b20d2b306626caa.tar.gz |
better error messages for some limits
Diffstat (limited to 'llex.c')
-rw-r--r-- | llex.c | 21 |
1 files changed, 7 insertions, 14 deletions
@@ -1,5 +1,5 @@ /* -** $Id: llex.c,v 1.128 2003/10/20 12:24:34 roberto Exp roberto $ +** $Id: llex.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ @@ -61,14 +61,6 @@ void luaX_init (lua_State *L) { #define MAXSRC 80 -void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) { - if (val > limit) { - msg = luaO_pushfstring(ls->L, "too many %s (limit=%d)", msg, limit); - luaX_syntaxerror(ls, msg); - } -} - - const char *luaX_token2str (LexState *ls, int token) { if (token < FIRST_RESERVED) { lua_assert(token == (unsigned char)token); @@ -93,11 +85,12 @@ static const char *txtToken (LexState *ls, int token) { } -static void luaX_lexerror (LexState *ls, const char *msg, int token) { +void luaX_lexerror (LexState *ls, const char *msg, int token) { char buff[MAXSRC]; luaO_chunkid(buff, getstr(ls->source), MAXSRC); - luaO_pushfstring(ls->L, "%s:%d: %s near `%s'", - buff, ls->linenumber, msg, txtToken(ls, token)); + msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); + if (token) + luaO_pushfstring(ls->L, "%s near `%s'", msg, txtToken(ls, token)); luaD_throw(ls->L, LUA_ERRSYNTAX); } @@ -123,8 +116,8 @@ static void inclinenumber (LexState *ls) { next(ls); /* skip `\n' or `\r' */ if (currIsNewline(ls) && ls->current != old) next(ls); /* skip `\n\r' or `\r\n' */ - ++ls->linenumber; - luaX_checklimit(ls, ls->linenumber, MAX_INT, "lines in a chunk"); + if (++ls->linenumber >= MAX_INT) + luaX_syntaxerror(ls, "chunk has too many lines"); } |