diff options
Diffstat (limited to 'llex.c')
-rw-r--r-- | llex.c | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 2.22 2006/08/30 13:19:58 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.23 2006/09/18 16:06:41 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 | */ |
@@ -34,14 +34,13 @@ | |||
34 | 34 | ||
35 | 35 | ||
36 | /* ORDER RESERVED */ | 36 | /* ORDER RESERVED */ |
37 | const char *const luaX_tokens [] = { | 37 | static const char *const luaX_tokens [] = { |
38 | "and", "break", "do", "else", "elseif", | 38 | "and", "break", "do", "else", "elseif", |
39 | "end", "false", "for", "function", "if", | 39 | "end", "false", "for", "function", "if", |
40 | "in", "local", "nil", "not", "or", "repeat", | 40 | "in", "local", "nil", "not", "or", "repeat", |
41 | "return", "then", "true", "until", "while", | 41 | "return", "then", "true", "until", "while", |
42 | "..", "...", "==", ">=", "<=", "~=", | 42 | "..", "...", "==", ">=", "<=", "~=", "<eof>", |
43 | "<number>", "<name>", "<string>", "<eof>", | 43 | "<number>", "<name>", "<string>" |
44 | NULL | ||
45 | }; | 44 | }; |
46 | 45 | ||
47 | 46 | ||
@@ -79,10 +78,15 @@ const char *luaX_token2str (LexState *ls, int token) { | |||
79 | if (token < FIRST_RESERVED) { | 78 | if (token < FIRST_RESERVED) { |
80 | lua_assert(token == cast(unsigned char, token)); | 79 | lua_assert(token == cast(unsigned char, token)); |
81 | return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : | 80 | return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : |
82 | luaO_pushfstring(ls->L, "%c", token); | 81 | luaO_pushfstring(ls->L, LUA_QL("%c"), token); |
82 | } | ||
83 | else { | ||
84 | const char *s = luaX_tokens[token - FIRST_RESERVED]; | ||
85 | if (token < TK_EOS) | ||
86 | return luaO_pushfstring(ls->L, LUA_QS, s); | ||
87 | else | ||
88 | return s; | ||
83 | } | 89 | } |
84 | else | ||
85 | return luaX_tokens[token-FIRST_RESERVED]; | ||
86 | } | 90 | } |
87 | 91 | ||
88 | 92 | ||
@@ -92,7 +96,7 @@ static const char *txtToken (LexState *ls, int token) { | |||
92 | case TK_STRING: | 96 | case TK_STRING: |
93 | case TK_NUMBER: | 97 | case TK_NUMBER: |
94 | save(ls, '\0'); | 98 | save(ls, '\0'); |
95 | return luaZ_buffer(ls->buff); | 99 | return luaO_pushfstring(ls->L, LUA_QS, luaZ_buffer(ls->buff)); |
96 | default: | 100 | default: |
97 | return luaX_token2str(ls, token); | 101 | return luaX_token2str(ls, token); |
98 | } | 102 | } |
@@ -104,7 +108,7 @@ void luaX_lexerror (LexState *ls, const char *msg, int token) { | |||
104 | luaO_chunkid(buff, getstr(ls->source), MAXSRC); | 108 | luaO_chunkid(buff, getstr(ls->source), MAXSRC); |
105 | msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); | 109 | msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); |
106 | if (token) | 110 | if (token) |
107 | luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token)); | 111 | luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token)); |
108 | luaD_throw(ls->L, LUA_ERRSYNTAX); | 112 | luaD_throw(ls->L, LUA_ERRSYNTAX); |
109 | } | 113 | } |
110 | 114 | ||