LUA_NUMBER */ ** This function is quite liberal in what it accepts, as 'luaO_str2num' ** will reject ill-formed numerals. Roughly, it accepts the following ** pattern: ** ** %d(%x|%.|([Ee][+-]?))* | 0[Xx](%x|%.|([Pp][+-]?))* ** ** The only tricky part is to accept [+-] only after a valid exponent ** mark, to avoid reading '3-4' or '0xe+1' as a single number. ** ** The caller might have already r
| 225 | ** The caller might have already read an initial dot. |
| 226 | */ |
| 227 | static int read_numeral (LexState *ls, SemInfo *seminfo) { |
| 228 | TValue obj; |
| 229 | const char *expo = "Ee"; |
| 230 | int first = ls->current; |
| 231 | lua_assert(lisdigit(ls->current)); |
| 232 | save_and_next(ls); |
| 233 | if (first == '0' && check_next2(ls, "xX")) /* hexadecimal? */ |
| 234 | expo = "Pp"; |
| 235 | for (;;) { |
| 236 | if (check_next2(ls, expo)) /* exponent mark? */ |
| 237 | check_next2(ls, "-+"); /* optional exponent sign */ |
| 238 | else if (lisxdigit(ls->current) || ls->current == '.') /* '%x|%.' */ |
| 239 | save_and_next(ls); |
| 240 | else break; |
| 241 | } |
| 242 | if (lislalpha(ls->current)) /* is numeral touching a letter? */ |
| 243 | save_and_next(ls); /* force an error */ |
| 244 | save(ls, '\0'); |
| 245 | if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */ |
| 246 | lexerror(ls, "malformed number", TK_FLT); |
| 247 | if (ttisinteger(&obj)) { |
| 248 | seminfo->i = ivalue(&obj); |
| 249 | return TK_INT; |
| 250 | } |
| 251 | else { |
| 252 | lua_assert(ttisfloat(&obj)); |
| 253 | seminfo->r = fltvalue(&obj); |
| 254 | return TK_FLT; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | |
| 259 | /* |
no test coverage detected