aboutsummaryrefslogtreecommitdiff
path: root/llex.c
diff options
context:
space:
mode:
Diffstat (limited to 'llex.c')
-rw-r--r--llex.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/llex.c b/llex.c
index bb83571e..1d26858c 100644
--- a/llex.c
+++ b/llex.c
@@ -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
64void 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
72const char *luaX_token2str (LexState *ls, int token) { 64const 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
96static void luaX_lexerror (LexState *ls, const char *msg, int token) { 88void 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