diff options
Diffstat (limited to '')
| -rw-r--r-- | llex.c | 35 | ||||
| -rw-r--r-- | llex.h | 3 |
2 files changed, 3 insertions, 35 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; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.h,v 1.77 2014/10/25 11:50:46 roberto Exp roberto $ | 2 | ** $Id: llex.h,v 1.78 2014/10/29 15:38:24 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 | */ |
| @@ -69,7 +69,6 @@ typedef struct LexState { | |||
| 69 | struct Dyndata *dyd; /* dynamic structures used by the parser */ | 69 | struct Dyndata *dyd; /* dynamic structures used by the parser */ |
| 70 | TString *source; /* current source name */ | 70 | TString *source; /* current source name */ |
| 71 | TString *envn; /* environment variable name */ | 71 | TString *envn; /* environment variable name */ |
| 72 | char decpoint; /* locale decimal point */ | ||
| 73 | } LexState; | 72 | } LexState; |
| 74 | 73 | ||
| 75 | 74 | ||
