aboutsummaryrefslogtreecommitdiff
path: root/llex.c
diff options
context:
space:
mode:
Diffstat (limited to 'llex.c')
-rw-r--r--llex.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/llex.c b/llex.c
index f636c368..48dbcd5b 100644
--- a/llex.c
+++ b/llex.c
@@ -1,11 +1,12 @@
1/* 1/*
2** $Id: llex.c,v 2.12 2005/05/17 19:49:15 roberto Exp roberto $ 2** $Id: llex.c,v 2.13 2005/11/08 19:45:14 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*/
6 6
7 7
8#include <ctype.h> 8#include <ctype.h>
9#include <locale.h>
9#include <string.h> 10#include <string.h>
10 11
11#define llex_c 12#define llex_c
@@ -134,6 +135,8 @@ static void inclinenumber (LexState *ls) {
134 135
135 136
136void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { 137void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
138 struct lconv *cv = localeconv();
139 ls->decpoint = (cv ? cv->decimal_point[0] : '.');
137 ls->L = L; 140 ls->L = L;
138 ls->lookahead.token = TK_EOS; /* no look-ahead token */ 141 ls->lookahead.token = TK_EOS; /* no look-ahead token */
139 ls->z = z; 142 ls->z = z;
@@ -163,6 +166,13 @@ static int check_next (LexState *ls, const char *set) {
163} 166}
164 167
165 168
169static void correctbuff (LexState *ls, char from, char to) {
170 int n = luaZ_bufflen(ls->buff);
171 char *p = luaZ_buffer(ls->buff);
172 while (n--)
173 if (p[n] == from) p[n] = to;
174}
175
166 176
167/* LUA_NUMBER */ 177/* LUA_NUMBER */
168static void read_numeral (LexState *ls, SemInfo *seminfo) { 178static void read_numeral (LexState *ls, SemInfo *seminfo) {
@@ -177,8 +187,11 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) {
177 } 187 }
178 } 188 }
179 save(ls, '\0'); 189 save(ls, '\0');
180 if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) 190 correctbuff(ls, '.', ls->decpoint); /* follow locale for decimal point */
191 if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {
192 correctbuff(ls, ls->decpoint, '.'); /* undo change */
181 luaX_lexerror(ls, "malformed number", TK_NUMBER); 193 luaX_lexerror(ls, "malformed number", TK_NUMBER);
194 }
182} 195}
183 196
184 197