LUA_NUMBER */ ** this function is quite liberal in what it accepts, as 'luaO_str2num' ** will reject ill-formed numerals. */
| 212 | ** will reject ill-formed numerals. |
| 213 | */ |
| 214 | static int read_numeral (LexState *ls, SemInfo *seminfo) { |
| 215 | TValue obj; |
| 216 | const char *expo = "Ee"; |
| 217 | int first = ls->current; |
| 218 | lua_assert(lisdigit(ls->current)); |
| 219 | save_and_next(ls); |
| 220 | if (first == '0' && check_next2(ls, "xX")) /* hexadecimal? */ |
| 221 | expo = "Pp"; |
| 222 | for (;;) { |
| 223 | if (check_next2(ls, expo)) /* exponent part? */ |
| 224 | check_next2(ls, "-+"); /* optional exponent sign */ |
| 225 | if (lisxdigit(ls->current)) |
| 226 | save_and_next(ls); |
| 227 | else if (ls->current == '.') |
| 228 | save_and_next(ls); |
| 229 | else break; |
| 230 | } |
| 231 | save(ls, '\0'); |
| 232 | if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */ |
| 233 | lexerror(ls, "malformed number", TK_FLT); |
| 234 | if (ttisinteger(&obj)) { |
| 235 | seminfo->i = ivalue(&obj); |
| 236 | return TK_INT; |
| 237 | } |
| 238 | else { |
| 239 | lua_assert(ttisfloat(&obj)); |
| 240 | seminfo->r = fltvalue(&obj); |
| 241 | return TK_FLT; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | |
| 246 | /* |
no test coverage detected