lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> I stumbled upon a weird behaviour in hexadecimal constants in Lua
> 5.2.0 (and LuaJIT 2.0.0-beta8).
> 
> [...]
> > print(0xE+9)
> stdin:1: malformed number near '0xE+9'
> [...]

I guess this patch solves the problem:

---------------------------------------------
--- llex.c	2011/11/30 12:43:51	2.59
+++ llex.c	2012/01/20 18:22:50
@@ -223,12 +223,19 @@
 
 /* LUA_NUMBER */
 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? */
---------------------------------------------

-- Roberto