#include <stdio.h>
#include <ctype.h>
+#include <locale.h>
#include <setjmp.h>
#include <assert.h>
}
static void
+replace_decpoint(Eo_Lexer *ls, char prevdecp)
+{
+ if (ls->decpoint == prevdecp) return;
+ char *bufs = eina_strbuf_string_steal(ls->buff);
+ char *p = bufs;
+ while ((p = strchr(p, prevdecp))) *p = ls->decpoint;
+ eina_strbuf_append(ls->buff, bufs);
+ free(bufs);
+}
+
+static void
+write_val_with_decpoint(Eo_Lexer *ls, Eo_Token *tok, int type)
+{
+ struct lconv *lc = localeconv();
+ char prev = ls->decpoint;
+ ls->decpoint = lc ? lc->decimal_point[0] : '.';
+ if (ls->decpoint == prev)
+ {
+ eo_lexer_lex_error(ls, "malformed number", TOK_NUMBER);
+ return;
+ }
+ replace_decpoint(ls, prev);
+ char *end = NULL;
+ if (type == NUM_FLOAT)
+ tok->value.f = strtof(eina_strbuf_string_get(ls->buff), &end);
+ else if (type == NUM_DOUBLE)
+ tok->value.d = strtod(eina_strbuf_string_get(ls->buff), &end);
+ if (end && end[0])
+ eo_lexer_lex_error(ls, "malformed number", TOK_NUMBER);
+}
+
+static void
write_val(Eo_Lexer *ls, Eo_Token *tok, Eina_Bool is_float)
{
const char *str = eina_strbuf_string_get(ls->buff);
char *end = NULL;
if (is_float)
{
+ replace_decpoint(ls, '.');
if (type == NUM_FLOAT)
tok->value.f = strtof(str, &end);
else if (type == NUM_DOUBLE)
tok->value.ull = strtoull(str, &end, 0);
}
if (end && end[0])
- eo_lexer_lex_error(ls, "malformed number", TOK_NUMBER);
+ {
+ if (is_float)
+ {
+ write_val_with_decpoint(ls, tok, type);
+ return;
+ }
+ eo_lexer_lex_error(ls, "malformed number", TOK_NUMBER);
+ }
tok->kw = type;
}
ls->filename = get_filename(ls);
ls->line_number = 1;
ls->icolumn = ls->column = -1;
+ ls->decpoint = '.';
next_char(ls);
if (ls->current != 0xEF)
return;
/* this is jumped to when an error happens */
jmp_buf err_jmp;
- /* whether we allow lexing expression related tokens */
- Eina_Bool expr_mode;
-
/* saved context info */
Eina_List *saved_ctxs;
* case of error - and it's nulled when it's written into a more permanent
* position (e.g. as part of another struct, or into nodes */
Eo_Lexer_Temps tmp;
+
+ /* whether we allow lexing expression related tokens */
+ Eina_Bool expr_mode;
+
+ /* decimal point, by default '.' */
+ char decpoint;
} Eo_Lexer;
int eo_lexer_init (void);