diff --git a/llex.c b/llex.c index f636c368..48dbcd5b 100644 --- a/llex.c +++ b/llex.c @@ -1,11 +1,12 @@ /* -** $Id: llex.c,v 2.12 2005/05/17 19:49:15 roberto Exp roberto $ +** $Id: llex.c,v 2.13 2005/11/08 19:45:14 roberto Exp roberto $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ #include +#include #include #define llex_c @@ -134,6 +135,8 @@ static void inclinenumber (LexState *ls) { void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { + struct lconv *cv = localeconv(); + ls->decpoint = (cv ? cv->decimal_point[0] : '.'); ls->L = L; ls->lookahead.token = TK_EOS; /* no look-ahead token */ ls->z = z; @@ -163,6 +166,13 @@ static int check_next (LexState *ls, const char *set) { } +static void correctbuff (LexState *ls, char from, char to) { + int n = luaZ_bufflen(ls->buff); + char *p = luaZ_buffer(ls->buff); + while (n--) + if (p[n] == from) p[n] = to; +} + /* LUA_NUMBER */ static void read_numeral (LexState *ls, SemInfo *seminfo) { @@ -177,8 +187,11 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) { } } save(ls, '\0'); - if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) + correctbuff(ls, '.', ls->decpoint); /* follow locale for decimal point */ + if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { + correctbuff(ls, ls->decpoint, '.'); /* undo change */ luaX_lexerror(ls, "malformed number", TK_NUMBER); + } } diff --git a/llex.h b/llex.h index a62a20e0..2a7a3664 100644 --- a/llex.h +++ b/llex.h @@ -1,5 +1,5 @@ /* -** $Id: llex.h,v 1.54 2005/04/25 19:24:10 roberto Exp roberto $ +** $Id: llex.h,v 1.55 2005/06/06 13:30:25 roberto Exp roberto $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ @@ -63,6 +63,7 @@ typedef struct LexState { ZIO *z; /* input stream */ Mbuffer *buff; /* buffer for tokens */ TString *source; /* current source name */ + char decpoint; /* locale decimal point */ } LexState;