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-a003e891252a2f6b4b7d1d006b20d2b306626caa.tar.gz lua-a003e891252a2f6b4b7d1d006b20d2b306626caa.tar.bz2 lua-a003e891252a2f6b4b7d1d006b20d2b306626caa.zip | |
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 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 1.128 2003/10/20 12:24:34 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -61,14 +61,6 @@ void luaX_init (lua_State *L) { | |||
| 61 | #define MAXSRC 80 | 61 | #define MAXSRC 80 |
| 62 | 62 | ||
| 63 | 63 | ||
| 64 | void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) { | ||
| 65 | if (val > limit) { | ||
| 66 | msg = luaO_pushfstring(ls->L, "too many %s (limit=%d)", msg, limit); | ||
| 67 | luaX_syntaxerror(ls, msg); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | const char *luaX_token2str (LexState *ls, int token) { | 64 | const char *luaX_token2str (LexState *ls, int token) { |
| 73 | if (token < FIRST_RESERVED) { | 65 | if (token < FIRST_RESERVED) { |
| 74 | lua_assert(token == (unsigned char)token); | 66 | lua_assert(token == (unsigned char)token); |
| @@ -93,11 +85,12 @@ static const char *txtToken (LexState *ls, int token) { | |||
| 93 | } | 85 | } |
| 94 | 86 | ||
| 95 | 87 | ||
| 96 | static void luaX_lexerror (LexState *ls, const char *msg, int token) { | 88 | void luaX_lexerror (LexState *ls, const char *msg, int token) { |
| 97 | char buff[MAXSRC]; | 89 | char buff[MAXSRC]; |
| 98 | luaO_chunkid(buff, getstr(ls->source), MAXSRC); | 90 | luaO_chunkid(buff, getstr(ls->source), MAXSRC); |
| 99 | luaO_pushfstring(ls->L, "%s:%d: %s near `%s'", | 91 | msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); |
| 100 | buff, ls->linenumber, msg, txtToken(ls, token)); | 92 | if (token) |
| 93 | luaO_pushfstring(ls->L, "%s near `%s'", msg, txtToken(ls, token)); | ||
| 101 | luaD_throw(ls->L, LUA_ERRSYNTAX); | 94 | luaD_throw(ls->L, LUA_ERRSYNTAX); |
| 102 | } | 95 | } |
| 103 | 96 | ||
| @@ -123,8 +116,8 @@ static void inclinenumber (LexState *ls) { | |||
| 123 | next(ls); /* skip `\n' or `\r' */ | 116 | next(ls); /* skip `\n' or `\r' */ |
| 124 | if (currIsNewline(ls) && ls->current != old) | 117 | if (currIsNewline(ls) && ls->current != old) |
| 125 | next(ls); /* skip `\n\r' or `\r\n' */ | 118 | next(ls); /* skip `\n\r' or `\r\n' */ |
| 126 | ++ls->linenumber; | 119 | if (++ls->linenumber >= MAX_INT) |
| 127 | luaX_checklimit(ls, ls->linenumber, MAX_INT, "lines in a chunk"); | 120 | luaX_syntaxerror(ls, "chunk has too many lines"); |
| 128 | } | 121 | } |
| 129 | 122 | ||
| 130 | 123 | ||
