diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2016-05-02 11:02:12 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2016-05-02 11:02:12 -0300 |
commit | 0232fbffbe43d84bef1bdb379b2b9f10eb11f750 (patch) | |
tree | 277cf67d5eea525c4d66f24de8e5bbbe463aaf0d /llex.c | |
parent | ed110f66c5af4fd804567a3cd5a7250eb5eb239b (diff) | |
download | lua-0232fbffbe43d84bef1bdb379b2b9f10eb11f750.tar.gz lua-0232fbffbe43d84bef1bdb379b2b9f10eb11f750.tar.bz2 lua-0232fbffbe43d84bef1bdb379b2b9f10eb11f750.zip |
now that 'luaO_str2num' always accepts a dot as a radix character,
the lexer does not need to bother with this issue.
Diffstat (limited to 'llex.c')
-rw-r--r-- | llex.c | 35 |
1 files changed, 2 insertions, 33 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 2.94 2015/10/28 18:51:47 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.95 2015/11/19 19:16:22 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 | */ |
@@ -162,7 +162,6 @@ static void inclinenumber (LexState *ls) { | |||
162 | void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, | 162 | void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, |
163 | int firstchar) { | 163 | int firstchar) { |
164 | ls->t.token = 0; | 164 | ls->t.token = 0; |
165 | ls->decpoint = '.'; | ||
166 | ls->L = L; | 165 | ls->L = L; |
167 | ls->current = firstchar; | 166 | ls->current = firstchar; |
168 | ls->lookahead.token = TK_EOS; /* no look-ahead token */ | 167 | ls->lookahead.token = TK_EOS; /* no look-ahead token */ |
@@ -207,35 +206,6 @@ static int check_next2 (LexState *ls, const char *set) { | |||
207 | } | 206 | } |
208 | 207 | ||
209 | 208 | ||
210 | /* | ||
211 | ** change all characters 'from' in buffer to 'to' | ||
212 | */ | ||
213 | static void buffreplace (LexState *ls, char from, char to) { | ||
214 | if (from != to) { | ||
215 | size_t n = luaZ_bufflen(ls->buff); | ||
216 | char *p = luaZ_buffer(ls->buff); | ||
217 | while (n--) | ||
218 | if (p[n] == from) p[n] = to; | ||
219 | } | ||
220 | } | ||
221 | |||
222 | |||
223 | /* | ||
224 | ** in case of format error, try to change decimal point separator to | ||
225 | ** the one defined in the current locale and check again | ||
226 | */ | ||
227 | static void trydecpoint (LexState *ls, TValue *o) { | ||
228 | char old = ls->decpoint; | ||
229 | ls->decpoint = lua_getlocaledecpoint(); | ||
230 | buffreplace(ls, old, ls->decpoint); /* try new decimal separator */ | ||
231 | if (luaO_str2num(luaZ_buffer(ls->buff), o) == 0) { | ||
232 | /* format error with correct decimal point: no more options */ | ||
233 | buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ | ||
234 | lexerror(ls, "malformed number", TK_FLT); | ||
235 | } | ||
236 | } | ||
237 | |||
238 | |||
239 | /* LUA_NUMBER */ | 209 | /* LUA_NUMBER */ |
240 | /* | 210 | /* |
241 | ** this function is quite liberal in what it accepts, as 'luaO_str2num' | 211 | ** this function is quite liberal in what it accepts, as 'luaO_str2num' |
@@ -259,9 +229,8 @@ static int read_numeral (LexState *ls, SemInfo *seminfo) { | |||
259 | else break; | 229 | else break; |
260 | } | 230 | } |
261 | save(ls, '\0'); | 231 | save(ls, '\0'); |
262 | buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ | ||
263 | if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */ | 232 | if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */ |
264 | trydecpoint(ls, &obj); /* try to update decimal point separator */ | 233 | lexerror(ls, "malformed number", TK_FLT); |
265 | if (ttisinteger(&obj)) { | 234 | if (ttisinteger(&obj)) { |
266 | seminfo->i = ivalue(&obj); | 235 | seminfo->i = ivalue(&obj); |
267 | return TK_INT; | 236 | return TK_INT; |