diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lua/llex.c (renamed from src/lua-5.3/llex.c) | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/src/lua-5.3/llex.c b/src/lua/llex.c index b6d9a46..90a7951 100644 --- a/src/lua-5.3/llex.c +++ b/src/lua/llex.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 2.96.1.1 2017/04/19 17:20:42 roberto Exp $ | 2 | ** $Id: llex.c $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -29,7 +29,7 @@ | |||
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | #define next(ls) (ls->current = zgetc(ls->z)) | 32 | #define next(ls) (ls->current = zgetc(ls->z)) |
| 33 | 33 | ||
| 34 | 34 | ||
| 35 | 35 | ||
| @@ -63,7 +63,7 @@ static void save (LexState *ls, int c) { | |||
| 63 | newsize = luaZ_sizebuffer(b) * 2; | 63 | newsize = luaZ_sizebuffer(b) * 2; |
| 64 | luaZ_resizebuffer(ls->L, b, newsize); | 64 | luaZ_resizebuffer(ls->L, b, newsize); |
| 65 | } | 65 | } |
| 66 | b->buffer[luaZ_bufflen(b)++] = cast(char, c); | 66 | b->buffer[luaZ_bufflen(b)++] = cast_char(c); |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | 69 | ||
| @@ -82,7 +82,10 @@ void luaX_init (lua_State *L) { | |||
| 82 | const char *luaX_token2str (LexState *ls, int token) { | 82 | const char *luaX_token2str (LexState *ls, int token) { |
| 83 | if (token < FIRST_RESERVED) { /* single-byte symbols? */ | 83 | if (token < FIRST_RESERVED) { /* single-byte symbols? */ |
| 84 | lua_assert(token == cast_uchar(token)); | 84 | lua_assert(token == cast_uchar(token)); |
| 85 | return luaO_pushfstring(ls->L, "'%c'", token); | 85 | if (lisprint(token)) |
| 86 | return luaO_pushfstring(ls->L, "'%c'", token); | ||
| 87 | else /* control character */ | ||
| 88 | return luaO_pushfstring(ls->L, "'<\\%d>'", token); | ||
| 86 | } | 89 | } |
| 87 | else { | 90 | else { |
| 88 | const char *s = luaX_tokens[token - FIRST_RESERVED]; | 91 | const char *s = luaX_tokens[token - FIRST_RESERVED]; |
| @@ -129,15 +132,15 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) { | |||
| 129 | TValue *o; /* entry for 'str' */ | 132 | TValue *o; /* entry for 'str' */ |
| 130 | TString *ts = luaS_newlstr(L, str, l); /* create new string */ | 133 | TString *ts = luaS_newlstr(L, str, l); /* create new string */ |
| 131 | setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */ | 134 | setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */ |
| 132 | o = luaH_set(L, ls->h, L->top - 1); | 135 | o = luaH_set(L, ls->h, s2v(L->top - 1)); |
| 133 | if (ttisnil(o)) { /* not in use yet? */ | 136 | if (isempty(o)) { /* not in use yet? */ |
| 134 | /* boolean value does not need GC barrier; | 137 | /* boolean value does not need GC barrier; |
| 135 | table has no metatable, so it does not need to invalidate cache */ | 138 | table is not a metatable, so it does not need to invalidate cache */ |
| 136 | setbvalue(o, 1); /* t[string] = true */ | 139 | setbtvalue(o); /* t[string] = true */ |
| 137 | luaC_checkGC(L); | 140 | luaC_checkGC(L); |
| 138 | } | 141 | } |
| 139 | else { /* string already present */ | 142 | else { /* string already present */ |
| 140 | ts = tsvalue(keyfromval(o)); /* re-use value previously stored */ | 143 | ts = keystrval(nodefromval(o)); /* re-use value previously stored */ |
| 141 | } | 144 | } |
| 142 | L->top--; /* remove string from stack */ | 145 | L->top--; /* remove string from stack */ |
| 143 | return ts; | 146 | return ts; |
| @@ -208,8 +211,16 @@ static int check_next2 (LexState *ls, const char *set) { | |||
| 208 | 211 | ||
| 209 | /* LUA_NUMBER */ | 212 | /* LUA_NUMBER */ |
| 210 | /* | 213 | /* |
| 211 | ** this function is quite liberal in what it accepts, as 'luaO_str2num' | 214 | ** This function is quite liberal in what it accepts, as 'luaO_str2num' |
| 212 | ** will reject ill-formed numerals. | 215 | ** will reject ill-formed numerals. Roughly, it accepts the following |
| 216 | ** pattern: | ||
| 217 | ** | ||
| 218 | ** %d(%x|%.|([Ee][+-]?))* | 0[Xx](%x|%.|([Pp][+-]?))* | ||
| 219 | ** | ||
| 220 | ** The only tricky part is to accept [+-] only after a valid exponent | ||
| 221 | ** mark, to avoid reading '3-4' or '0xe+1' as a single number. | ||
| 222 | ** | ||
| 223 | ** The caller might have already read an initial dot. | ||
| 213 | */ | 224 | */ |
| 214 | static int read_numeral (LexState *ls, SemInfo *seminfo) { | 225 | static int read_numeral (LexState *ls, SemInfo *seminfo) { |
| 215 | TValue obj; | 226 | TValue obj; |
| @@ -220,14 +231,14 @@ static int read_numeral (LexState *ls, SemInfo *seminfo) { | |||
| 220 | if (first == '0' && check_next2(ls, "xX")) /* hexadecimal? */ | 231 | if (first == '0' && check_next2(ls, "xX")) /* hexadecimal? */ |
| 221 | expo = "Pp"; | 232 | expo = "Pp"; |
| 222 | for (;;) { | 233 | for (;;) { |
| 223 | if (check_next2(ls, expo)) /* exponent part? */ | 234 | if (check_next2(ls, expo)) /* exponent mark? */ |
| 224 | check_next2(ls, "-+"); /* optional exponent sign */ | 235 | check_next2(ls, "-+"); /* optional exponent sign */ |
| 225 | if (lisxdigit(ls->current)) | 236 | else if (lisxdigit(ls->current) || ls->current == '.') /* '%x|%.' */ |
| 226 | save_and_next(ls); | ||
| 227 | else if (ls->current == '.') | ||
| 228 | save_and_next(ls); | 237 | save_and_next(ls); |
| 229 | else break; | 238 | else break; |
| 230 | } | 239 | } |
| 240 | if (lislalpha(ls->current)) /* is numeral touching a letter? */ | ||
| 241 | save_and_next(ls); /* force an error */ | ||
| 231 | save(ls, '\0'); | 242 | save(ls, '\0'); |
| 232 | if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */ | 243 | if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */ |
| 233 | lexerror(ls, "malformed number", TK_FLT); | 244 | lexerror(ls, "malformed number", TK_FLT); |
| @@ -260,7 +271,6 @@ static size_t skip_sep (LexState *ls) { | |||
| 260 | return (ls->current == s) ? count + 2 | 271 | return (ls->current == s) ? count + 2 |
| 261 | : (count == 0) ? 1 | 272 | : (count == 0) ? 1 |
| 262 | : 0; | 273 | : 0; |
| 263 | |||
| 264 | } | 274 | } |
| 265 | 275 | ||
| 266 | 276 | ||
| @@ -333,10 +343,10 @@ static unsigned long readutf8esc (LexState *ls) { | |||
| 333 | save_and_next(ls); /* skip 'u' */ | 343 | save_and_next(ls); /* skip 'u' */ |
| 334 | esccheck(ls, ls->current == '{', "missing '{'"); | 344 | esccheck(ls, ls->current == '{', "missing '{'"); |
| 335 | r = gethexa(ls); /* must have at least one digit */ | 345 | r = gethexa(ls); /* must have at least one digit */ |
| 336 | while ((save_and_next(ls), lisxdigit(ls->current))) { | 346 | while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) { |
| 337 | i++; | 347 | i++; |
| 348 | esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large"); | ||
| 338 | r = (r << 4) + luaO_hexavalue(ls->current); | 349 | r = (r << 4) + luaO_hexavalue(ls->current); |
| 339 | esccheck(ls, r <= 0x10FFFF, "UTF-8 value too large"); | ||
| 340 | } | 350 | } |
| 341 | esccheck(ls, ls->current == '}', "missing '}'"); | 351 | esccheck(ls, ls->current == '}', "missing '}'"); |
| 342 | next(ls); /* skip '}' */ | 352 | next(ls); /* skip '}' */ |
| @@ -466,7 +476,7 @@ static int llex (LexState *ls, SemInfo *seminfo) { | |||
| 466 | read_long_string(ls, seminfo, sep); | 476 | read_long_string(ls, seminfo, sep); |
| 467 | return TK_STRING; | 477 | return TK_STRING; |
| 468 | } | 478 | } |
| 469 | else if (sep == 0) /* '[=...' missing second bracket */ | 479 | else if (sep == 0) /* '[=...' missing second bracket? */ |
| 470 | lexerror(ls, "invalid long string delimiter", TK_STRING); | 480 | lexerror(ls, "invalid long string delimiter", TK_STRING); |
| 471 | return '['; | 481 | return '['; |
| 472 | } | 482 | } |
