mirror of https://github.com/rusefi/lua.git
now that 'luaO_str2num' always accepts a dot as a radix character,
the lexer does not need to bother with this issue.
This commit is contained in:
parent
ed110f66c5
commit
0232fbffbe
35
llex.c
35
llex.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: llex.c,v 2.94 2015/10/28 18:51:47 roberto Exp roberto $
|
** $Id: llex.c,v 2.95 2015/11/19 19:16:22 roberto Exp roberto $
|
||||||
** Lexical Analyzer
|
** Lexical Analyzer
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -162,7 +162,6 @@ static void inclinenumber (LexState *ls) {
|
||||||
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
|
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
|
||||||
int firstchar) {
|
int firstchar) {
|
||||||
ls->t.token = 0;
|
ls->t.token = 0;
|
||||||
ls->decpoint = '.';
|
|
||||||
ls->L = L;
|
ls->L = L;
|
||||||
ls->current = firstchar;
|
ls->current = firstchar;
|
||||||
ls->lookahead.token = TK_EOS; /* no look-ahead token */
|
ls->lookahead.token = TK_EOS; /* no look-ahead token */
|
||||||
|
@ -207,35 +206,6 @@ static int check_next2 (LexState *ls, const char *set) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** change all characters 'from' in buffer to 'to'
|
|
||||||
*/
|
|
||||||
static void buffreplace (LexState *ls, char from, char to) {
|
|
||||||
if (from != to) {
|
|
||||||
size_t n = luaZ_bufflen(ls->buff);
|
|
||||||
char *p = luaZ_buffer(ls->buff);
|
|
||||||
while (n--)
|
|
||||||
if (p[n] == from) p[n] = to;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** in case of format error, try to change decimal point separator to
|
|
||||||
** the one defined in the current locale and check again
|
|
||||||
*/
|
|
||||||
static void trydecpoint (LexState *ls, TValue *o) {
|
|
||||||
char old = ls->decpoint;
|
|
||||||
ls->decpoint = lua_getlocaledecpoint();
|
|
||||||
buffreplace(ls, old, ls->decpoint); /* try new decimal separator */
|
|
||||||
if (luaO_str2num(luaZ_buffer(ls->buff), o) == 0) {
|
|
||||||
/* format error with correct decimal point: no more options */
|
|
||||||
buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */
|
|
||||||
lexerror(ls, "malformed number", TK_FLT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* LUA_NUMBER */
|
/* LUA_NUMBER */
|
||||||
/*
|
/*
|
||||||
** this function is quite liberal in what it accepts, as 'luaO_str2num'
|
** this function is quite liberal in what it accepts, as 'luaO_str2num'
|
||||||
|
@ -259,9 +229,8 @@ static int read_numeral (LexState *ls, SemInfo *seminfo) {
|
||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
save(ls, '\0');
|
save(ls, '\0');
|
||||||
buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
|
|
||||||
if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */
|
if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */
|
||||||
trydecpoint(ls, &obj); /* try to update decimal point separator */
|
lexerror(ls, "malformed number", TK_FLT);
|
||||||
if (ttisinteger(&obj)) {
|
if (ttisinteger(&obj)) {
|
||||||
seminfo->i = ivalue(&obj);
|
seminfo->i = ivalue(&obj);
|
||||||
return TK_INT;
|
return TK_INT;
|
||||||
|
|
3
llex.h
3
llex.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: llex.h,v 1.77 2014/10/25 11:50:46 roberto Exp roberto $
|
** $Id: llex.h,v 1.78 2014/10/29 15:38:24 roberto Exp roberto $
|
||||||
** Lexical Analyzer
|
** Lexical Analyzer
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -69,7 +69,6 @@ typedef struct LexState {
|
||||||
struct Dyndata *dyd; /* dynamic structures used by the parser */
|
struct Dyndata *dyd; /* dynamic structures used by the parser */
|
||||||
TString *source; /* current source name */
|
TString *source; /* current source name */
|
||||||
TString *envn; /* environment variable name */
|
TString *envn; /* environment variable name */
|
||||||
char decpoint; /* locale decimal point */
|
|
||||||
} LexState;
|
} LexState;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue