commit 76eab106df01013de80033ac07586a79879fca55
parent 81ed85ecfbec8607c12e8f7f9731a376eaeb2d0a
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 20 Jan 2012 16:35:12 -0200
bug: Lexical gets confused with some combination of arithmetic
operators and hexadecimal numbers
Diffstat:
M | llex.c | | | 21 | ++++++++++++++++----- |
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/llex.c b/llex.c
@@ -1,5 +1,5 @@
/*
-** $Id: llex.c,v 2.58 2011/08/15 19:41:58 roberto Exp roberto $
+** $Id: llex.c,v 2.59 2011/11/30 12:43:51 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@@ -222,13 +222,24 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) {
/* LUA_NUMBER */
+/*
+** this function is quite liberal in what it accepts, as 'luaO_str2d'
+** will reject ill-formed numerals.
+*/
static void read_numeral (LexState *ls, SemInfo *seminfo) {
+ const char *expo = "Ee";
+ int first = ls->current;
lua_assert(lisdigit(ls->current));
- do {
- save_and_next(ls);
- if (check_next(ls, "EePp")) /* exponent part? */
+ save_and_next(ls);
+ if (first == '0' && check_next(ls, "Xx")) /* hexadecimal? */
+ expo = "Pp";
+ for (;;) {
+ if (check_next(ls, expo)) /* exponent part? */
check_next(ls, "+-"); /* optional exponent sign */
- } while (lislalnum(ls->current) || ls->current == '.');
+ if (lisxdigit(ls->current) || ls->current == '.')
+ save_and_next(ls);
+ else break;
+ }
save(ls, '\0');
buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
if (!buff2d(ls->buff, &seminfo->r)) /* format error? */