diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-08-27 18:01:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-08-27 18:01:44 -0300 |
commit | 8332d5c8a5059b85da1adaa3f0197d0f57afae81 (patch) | |
tree | 8a2f59ff0803da3afbc7e8a409911c920d624e94 /llex.c | |
parent | 885961be1d8e3f703b54d1d19e6c63617cd2ed24 (diff) | |
download | lua-8332d5c8a5059b85da1adaa3f0197d0f57afae81.tar.gz lua-8332d5c8a5059b85da1adaa3f0197d0f57afae81.tar.bz2 lua-8332d5c8a5059b85da1adaa3f0197d0f57afae81.zip |
parser fully reentrant(!)
Diffstat (limited to 'llex.c')
-rw-r--r-- | llex.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 1.120 2003/05/15 12:20:24 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.121 2003/08/21 14:16:43 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 | */ |
@@ -111,6 +111,16 @@ static void luaX_lexerror (LexState *ls, const char *s, int token) { | |||
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | TString *luaX_newstring (LexState *LS, const char *str, size_t l) { | ||
115 | lua_State *L = LS->L; | ||
116 | TString *ts = luaS_newlstr(L, str, l); | ||
117 | TObject *o = luaH_setstr(L, LS->fs->h, ts); /* entry for `str' */ | ||
118 | if (ttisnil(o)) | ||
119 | setbvalue(o, 1); /* make sure `str' will not be collected */ | ||
120 | return ts; | ||
121 | } | ||
122 | |||
123 | |||
114 | static void inclinenumber (LexState *LS) { | 124 | static void inclinenumber (LexState *LS) { |
115 | int old = LS->current; | 125 | int old = LS->current; |
116 | lua_assert(nextIsNewline(LS)); | 126 | lua_assert(nextIsNewline(LS)); |
@@ -253,7 +263,7 @@ static void read_long_string (LexState *LS, SemInfo *seminfo) { | |||
253 | save_and_next(LS, l); /* skip the second `]' */ | 263 | save_and_next(LS, l); /* skip the second `]' */ |
254 | save(LS, '\0', l); | 264 | save(LS, '\0', l); |
255 | if (seminfo) | 265 | if (seminfo) |
256 | seminfo->ts = luaS_newlstr(LS->L, luaZ_buffer(LS->buff) + 2, l - 5); | 266 | seminfo->ts = luaX_newstring(LS, luaZ_buffer(LS->buff) + 2, l - 5); |
257 | } | 267 | } |
258 | 268 | ||
259 | 269 | ||
@@ -311,7 +321,7 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) { | |||
311 | } | 321 | } |
312 | save_and_next(LS, l); /* skip delimiter */ | 322 | save_and_next(LS, l); /* skip delimiter */ |
313 | save(LS, '\0', l); | 323 | save(LS, '\0', l); |
314 | seminfo->ts = luaS_newlstr(LS->L, luaZ_buffer(LS->buff) + 1, l - 3); | 324 | seminfo->ts = luaX_newstring(LS, luaZ_buffer(LS->buff) + 1, l - 3); |
315 | } | 325 | } |
316 | 326 | ||
317 | 327 | ||
@@ -401,7 +411,7 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) { | |||
401 | else if (isalpha(LS->current) || LS->current == '_') { | 411 | else if (isalpha(LS->current) || LS->current == '_') { |
402 | /* identifier or reserved word */ | 412 | /* identifier or reserved word */ |
403 | size_t l = readname(LS); | 413 | size_t l = readname(LS); |
404 | TString *ts = luaS_newlstr(LS->L, luaZ_buffer(LS->buff), l); | 414 | TString *ts = luaX_newstring(LS, luaZ_buffer(LS->buff), l); |
405 | if (ts->tsv.reserved > 0) /* reserved word? */ | 415 | if (ts->tsv.reserved > 0) /* reserved word? */ |
406 | return ts->tsv.reserved - 1 + FIRST_RESERVED; | 416 | return ts->tsv.reserved - 1 + FIRST_RESERVED; |
407 | seminfo->ts = ts; | 417 | seminfo->ts = ts; |