MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / read_numeral

Function read_numeral

extlibs/lua/src/llex.c:225–254  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

223** The caller might have already read an initial dot.
224*/
225static int read_numeral (LexState *ls, SemInfo *seminfo) {
226 TValue obj;
227 const char *expo = "Ee";
228 int first = ls->current;
229 lua_assert(lisdigit(ls->current));
230 save_and_next(ls);
231 if (first == '0' && check_next2(ls, "xX")) /* hexadecimal? */
232 expo = "Pp";
233 for (;;) {
234 if (check_next2(ls, expo)) /* exponent mark? */
235 check_next2(ls, "-+"); /* optional exponent sign */
236 else if (lisxdigit(ls->current) || ls->current == '.') /* '%x|%.' */
237 save_and_next(ls);
238 else break;
239 }
240 if (lislalpha(ls->current)) /* is numeral touching a letter? */
241 save_and_next(ls); /* force an error */
242 save(ls, '\0');
243 if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */
244 lexerror(ls, "malformed number", TK_FLT);
245 if (ttisinteger(&obj)) {
246 seminfo->i = ivalue(&obj);
247 return TK_INT;
248 }
249 else {
250 lua_assert(ttisfloat(&obj));
251 seminfo->r = fltvalue(&obj);
252 return TK_FLT;
253 }
254}
255
256
257/*

Callers 1

llexFunction · 0.85

Calls 4

check_next2Function · 0.85
saveFunction · 0.85
luaO_str2numFunction · 0.85
lexerrorFunction · 0.85

Tested by

no test coverage detected